//获取应用实例
|
|
const app = getApp();
|
const com = require("../../utils/common.js");
|
const dowx = require("../../utils/DOWX.js");
|
var th = null;
|
|
// 上传域名
|
const uphttp = "https://bn.izbsq.com/";
|
|
Page({
|
|
// 页面数据
|
data: {
|
// 需要获取的数据
|
openid: null, //我的openid
|
videoid: null, //该视频编号
|
typenum: null, //该视频归属种
|
// 领取概要
|
had_lingqu: 0, //已经被领取的个数
|
max_lingqu: 0, //红包共有的个数
|
max_dashang: 0, //总的打赏人数
|
// 视频文件信息
|
process: null, //视频生成进度
|
src_videoimg: null, //视频封面图片
|
url_video: null, // 后台的视频地址
|
// 录音格式
|
time_luyinmin: 2, // 录音最短长度限制
|
time_luyinmax: 10, // 录音最长长度限制
|
// 弹幕的组
|
zu_danmu: [], //弹幕的列表组
|
// 领取的红包
|
tf_hadlingqu: false, //是否已经领取过钱,控制是否弹出红包领取框
|
bao_toux: null, //红包发起者的头像
|
bao_nickname: '发起者昵称', //发起者昵称
|
bao_jine: 0, //领取到的金额数值
|
|
|
// 使用中获取的变量
|
show_video: true, //video组件是否可以显示
|
show_ly: false, // 录音提示是否显示
|
// 当前进行的步骤数
|
bushu: 1,
|
// video使用
|
src_video: null, //video播放时的src
|
tf_animt_cover: false, //是否允许弹幕滚动,用于重置弹幕
|
// 录音
|
zu_wificlass: ['luyinbo_wifi', 'luyinbo_wifi', 'luyinbo_wifi'], //录音播放的wifi样式
|
file_luyin: null, // 录音文件
|
time_luyin: 0, // 录音时长
|
time_show: '00' // 录音时提示的时间
|
},
|
|
// 数据请求
|
getdata: {
|
working1: false, //获取视频进度中?
|
working2: false, //获取语音录制的格式要求中?
|
working3: false, //获取视频红包的详情信息中?
|
working4: false, //获取弹幕组中?
|
working5: false, //获取视频链接中?
|
// 获取视频生成进度
|
timeout_process: null,
|
process: function (callback)
|
{
|
if (callback == null) { callback = function () { }; }
|
if (th.getdata.working1 == true) { return false; } //已经在工作中了,那么直接退出
|
th.getdata.working1 = true; //进入工作标识
|
|
// 数据准备
|
var mydata = {
|
openid: th.data.openid,
|
id: th.data.videoid
|
};
|
var myurl = com.getWholeUrl('bainian/api/client/video/getdrawprocess', mydata);
|
// 数据请求
|
dowx.AjaxPost(myurl, {}, function (res)
|
{
|
th.getdata.working1 = false;
|
dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
|
|
if (res.code == 0)
|
{
|
// 保存生成进度
|
th.setData({ process: res.data.process });
|
// 如果进度不为100,那么5s再次请求
|
if (th.data.process == 100) { callback(); }
|
else {
|
th.getdata.timeout_process = setTimeout(function(){
|
console.log("timeout:请求生成进度");
|
th.getdata.process(callback);
|
},5000);
|
}
|
}
|
else {
|
wx.showToast({
|
title: '进度' + res.msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
}
|
});
|
},
|
// 请求语音录制的格式要求
|
luyingeshi: function ()
|
{
|
if (th.getdata.working2 == true) { return false; } // 如果已经在工作,那么直接退出函数
|
th.getdata.working2 = true; //进入工作标识
|
|
// 数据准备
|
var mydata = { openid: th.data.openid };
|
var myurl = com.getWholeUrl("bainian/api/client/config/getvideoconfig", mydata);
|
// 请求数据
|
dowx.AjaxPost(myurl, {}, function (res)
|
{
|
th.getdata.working2 = false;
|
dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
|
|
if (res.code == 0)
|
{
|
th.setData({
|
time_luyinmin: res.data.minVoiceTime,
|
time_luyinmax: res.data.maxVoiceTime
|
});
|
}
|
else {
|
wx.showToast({
|
title: '录音格式' + res.msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
}
|
});
|
},
|
// 请求视频红包的详情信息
|
videoxiangqin: function (callback)
|
{
|
if (callback == null) { callback = function () { }; }
|
if (th.getdata.working3 == true) { return false; } //已经在工作中了,那么直接退出
|
th.getdata.working3 = true; //进入工作标识
|
|
// 数据准备
|
var mydata = {
|
id: th.data.videoid,
|
openid: th.data.openid
|
};
|
var myurl = null;
|
if (th.data.typenum == 1) { myurl = com.getWholeUrl('bainian/api/client/video/hb/getdetail', mydata); }
|
else if (th.data.typenum == 2) { myurl = com.getWholeUrl('bainian/api/client/video/ysq/getdetail', mydata); }
|
// 数据请求
|
dowx.AjaxPost(myurl, {}, function(res)
|
{
|
th.getdata.working3 = false;
|
dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
|
|
if (res.code == 0)
|
{
|
// 共同信息赋值
|
th.setData({
|
src_videoimg: res.data.videoGameInfo.postPicture, //视频封面图片
|
url_video: res.data.videoGameInfo.video.finalVideoUrl, //后台的视频地址
|
bao_toux: res.data.videoGameInfo.user.portrait, //红包发起者的头像
|
bao_nickname: res.data.videoGameInfo.user.nickName, //发起者昵称
|
shareimg: res.data.videoGameInfo.shareImg //朋友圈分享图
|
});
|
// 私有信息赋值
|
if (th.data.typenum == 1)
|
{
|
th.setData({
|
had_lingqu: res.data.recieveCount,//已经被领取的个数
|
max_lingqu: res.data.moneyCount,//红包共有的个数
|
tf_hadlingqu: res.data.received, //是否已经领取过红包
|
});
|
}
|
else if (th.data.typenum == 2)
|
{
|
th.setData({
|
max_dashang: res.data.totalCount,//总打赏人数
|
});
|
}
|
callback();
|
}
|
else {
|
wx.showToast({
|
title: res.msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
}
|
});
|
},
|
// 请求视频地址
|
videourl: function ()
|
{
|
if (th.getdata.working5 == true) { return false; } //已经在工作中了,那么直接退出
|
th.getdata.working5 = true; //进入工作标识
|
|
// 数据准备
|
var mydata = { openid: th.data.openid, id: th.data.videoid };
|
var myurl = com.getWholeUrl("bainian/api/client/video/getplayurl", mydata);
|
// 请求数据
|
dowx.AjaxPost(myurl, {}, function (res)
|
{
|
th.getdata.working5 = false;
|
dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
|
|
if (res.code == 0) {
|
th.setData({ src_video: res.data.playUrl });
|
}
|
else {
|
wx.showToast({
|
title: res.msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
}
|
});
|
},
|
// 请求弹幕组
|
danmu: function (callback)
|
{
|
if (callback == null) { callback = function () {}; }
|
if (th.getdata.working4 == true) { return false; } //已经在工作中了,那么直接退出
|
th.getdata.working4 = true; //进入工作标识
|
|
// 数据准备,一次请求200条数据,即全部请求
|
var mydata = {
|
id: th.data.videoid,
|
openid: th.data.openid,
|
page: 1,
|
pagesize: 200
|
};
|
var myurl = null;
|
if (th.data.typenum == 1) { myurl = com.getWholeUrl('bainian/api/client/video/hb/getmoneyjoinlist', mydata); }
|
else if (th.data.typenum == 2) { myurl = com.getWholeUrl('bainian/api/client/video/ysq/getjoinlist', mydata); }
|
// 发起请求
|
dowx.AjaxPost(myurl, {}, function(res)
|
{
|
th.getdata.working4 = false;
|
dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
|
|
if (res.code != 0) {
|
wx.showToast({
|
title: res.msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
}
|
else
|
{
|
if (th.data.typenum == 1)
|
{
|
// 查看是否已经上传过录音
|
if (res.data.voice.length != 0) { th.setData({ file_luyin: res.data.voice }); }
|
else { th.setData({ file_luyin: null }); }
|
}
|
|
var zu_mo = [];//保存临时数据的组
|
// 通过循环将临时组的元素补全
|
for (var i = 0; i < res.data.data.length; i++)
|
{
|
var yuan = {
|
userid: res.data.data[i].user.id, //用户id
|
userimg: res.data.data[i].user.portrait, //用户头像
|
time_luyin: res.data.data[i].voiceTime, //录音时长
|
show_danmu: false, // 是否显示该条弹幕
|
hadtime: 0 // 已经显示的时间
|
};
|
if (th.data.typenum == 1) {
|
yuan.money = res.data.data[i].money; //领取金额
|
}
|
else if (th.data.typenum == 2) {
|
yuan.money = res.data.data[i].money; //打赏金额
|
}
|
zu_mo.push(yuan);
|
}
|
// 弹幕组赋值
|
th.setData({ zu_danmu: zu_mo });
|
|
// 清除弹幕定时器
|
th.getdata.clear_danmu();
|
// 弹幕滚动
|
th.getdata.setinval_danmu();
|
|
callback();
|
}
|
});
|
},
|
// 弹幕循环计时器方法, inval_danmu为null才可执行
|
inval_danmu: null,
|
timeout_danmu: null,
|
setinval_danmu: function ()
|
{
|
// 如果弹幕条数为0,那么直接退出
|
if (th.data.zu_danmu.length <= 0) { return false; }
|
// 如果已经存在计时器,那么不操作,直接退出
|
if (th.getdata.inval_danmu != null) { return false; }
|
|
// 对弹幕组出场进行配置:
|
var length_zu = th.data.zu_danmu.length; // 弹幕组的长度
|
var index_danmu = -1; //当前操作的弹幕组元素下标
|
// 进行弹幕计时循环
|
th.getdata.inval_danmu = setInterval(function ()
|
{
|
// 将处理的元素下标+1
|
index_danmu = index_danmu + 1;
|
// 下标超标则退出定时器
|
if (index_danmu >= length_zu)
|
{
|
// 清除定时器
|
clearInterval(th.getdata.inval_danmu); th.getdata.inval_danmu = null;
|
|
// 重头滚动弹幕
|
th.getdata.timeout_danmu = setTimeout(function()
|
{
|
console.log("timeout:弹幕将马上重头再来");
|
// 初始化清除弹幕
|
th.getdata.clear_danmu();
|
// 递归本函数
|
th.getdata.setinval_danmu();
|
},6500);
|
}
|
// 未超出则依次显示
|
else
|
{
|
console.log("interval:新弹幕马上进入");
|
// 让当前下标元素变为show
|
var mo_zu = th.data.zu_danmu;
|
mo_zu[index_danmu].show_danmu = true;
|
th.setData({ zu_danmu: mo_zu });
|
// show为true的元素显示时间全部+1
|
for (var i=0; i<=index_danmu; i++)
|
{
|
if(mo_zu[i].show_danmu == true)
|
{
|
mo_zu[i].hadtime = mo_zu[i].hadtime + 2.5;
|
th.setData({ zu_danmu: mo_zu });
|
mo_zu = th.data.zu_danmu;
|
// 弹幕滚动出局检测
|
if (mo_zu[i].hadtime > 11)
|
{
|
// 将这个元素show设为false
|
mo_zu[i].show_danmu = false;
|
th.setData({ zu_danmu: mo_zu });
|
}
|
}
|
}
|
}
|
|
}, 2500);
|
},
|
// 停止弹幕且归零
|
clear_danmu: function ()
|
{
|
// 清除定时器
|
if (th.getdata.inval_danmu != null) { clearInterval(th.getdata.inval_danmu); th.getdata.inval_danmu = null; }
|
if (th.getdata.timeout_danmu != null) { clearTimeout(th.getdata.timeout_danmu); th.getdata.timeout_danmu = null; }
|
// 将弹幕元素的show设为false, time设为0
|
var mo_zu = th.data.zu_danmu;
|
for (var i = 0; i < mo_zu.length; i++)
|
{
|
if (mo_zu[i].hadtime != 0)
|
{
|
mo_zu[i].hadtime = 0;
|
mo_zu[i].show_danmu = false;
|
}
|
}
|
th.setData({ zu_danmu: mo_zu });
|
}
|
},
|
|
// 获取超链接传递的视频编号等信息,获取一次视频生成进度
|
onLoad: function (options)
|
{
|
// 对th赋值
|
th = this;
|
// 是否传递有视频编号
|
if ( options.videoid )
|
{
|
// 得到且保存 当前视频id,视频type
|
th.setData({
|
videoid: options.videoid,
|
typenum: options.type
|
});
|
// 获取视频文件信息
|
app.Get_info(function (info2)
|
{
|
th.setData({ openid: info2.info2.openid });
|
// 预先获取:该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取生成进度
|
th.getdata.process(function()
|
{
|
// 请求录音录制格式
|
th.getdata.luyingeshi();
|
// 请求视频地址
|
th.getdata.videourl();
|
// 获取弹幕组
|
th.getdata.danmu();
|
});
|
});
|
}
|
// 通过二维码获取
|
else if ( decodeURIComponent(options.scene) != "undefined" )
|
{
|
var scene = decodeURIComponent(options.scene);
|
scene = JSON.parse(scene);
|
console.log(scene);
|
// 得到且保存 当前视频id,视频type
|
th.setData({
|
videoid: options.videoid,
|
typenum: options.type
|
});
|
// 获取视频文件信息
|
app.Get_info(function (info2)
|
{
|
th.setData({ openid: info2.info2.openid });
|
// 预先获取:该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取生成进度
|
th.getdata.process(function ()
|
{
|
// 请求录音录制格式
|
th.getdata.luyingeshi();
|
// 请求视频地址
|
th.getdata.videourl();
|
// 获取弹幕组
|
th.getdata.danmu();
|
});
|
});
|
}
|
// 未能获取
|
else { dowx.Showred(th,'未能获取视频id'); }
|
},
|
|
// 获取录音权限,获取视频信息
|
onShow: function()
|
{
|
// 获取录音权限
|
dowx.Authorize_record();
|
// 当视频处理好后通过
|
if (th.data.process == 100)
|
{
|
// 请求录音录制格式
|
th.getdata.luyingeshi();
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu();
|
}
|
},
|
|
onPullDownRefresh: function ()
|
{
|
setTimeout(function () { wx.stopPullDownRefresh(); },300);
|
if (th.data.process == 100)
|
{
|
// 请求录音录制格式
|
th.getdata.luyingeshi();
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu();
|
}
|
},
|
|
onShareAppMessage: function ()
|
{
|
// 分享的标题设置
|
var title = "";
|
if (th.data.typenum == 1) { title = th.data.bao_nickname + "-发福利啦"; }
|
else if (th.data.typenum == 2) { title = th.data.bao_nickname + "-来拜年了"; }
|
return {
|
title: title,
|
path: '/pages/lingqu/lingqu?videoid=' + th.data.videoid + '&type=' + th.data.typenum,
|
imageUrl: th.data.src_videoimg
|
}
|
},
|
|
onUnload: function ()
|
{
|
// 清除弹幕定时器
|
th.getdata.clear_danmu();
|
// 清除5s请求的定时器
|
if (th.getdata.timeout_process != null) { clearTimeout(th.getdata.timeout_process); th.getdata.timeout_process = null; }
|
},
|
|
|
// 红包隐藏框 事件 ----------------------------------------------------------------------------------------
|
//
|
// 边缘图层 点击
|
Click_bian: function()
|
{
|
|
th.setData({ yc_bao: false }); // 红包框隐藏
|
th.setData({ yc_baobushu: 1 }); //回到红包最初界面
|
th.myvideo.show(); // video显示
|
},
|
// 立即开抢 点击
|
Click_kaiqiang: function()
|
{
|
// 有录音文件时:录音后领取
|
if (th.data.file_luyin!=null)
|
{
|
// 数据准备
|
var mydata = {
|
appid: 'wx4dbc1f6c7cf71b68',
|
id: th.data.videoid,
|
openid: th.data.openid,
|
time: th.data.time_luyin
|
};
|
var myurl = uphttp + 'bainian/api/client/video/hb/recievehb';
|
// 发送数据
|
wx.showLoading({ title: '' });//loading框展示
|
wx.uploadFile({
|
url: myurl,
|
filePath: th.data.file_luyin,
|
name: 'voice',
|
formData: mydata,
|
fail: function (res) {
|
wx.hideLoading();
|
wx.showToast({
|
title: '上传录音→fail',
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
},
|
success: function (res)
|
{
|
wx.hideLoading();
|
res = JSON.parse(res.data);
|
if (res.code == 0) {
|
// 保存金额
|
th.setData({ bao_jine: res.data.money });
|
// 进入到红包第2步
|
th.setData({ yc_baobushu: 2 });
|
// 清除刚才的录音
|
th.setData({ time_luyin: 0, file_luyin: null });
|
// 页面进入第1步
|
th.setData({ bushu: 1 });
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu();
|
}
|
else {
|
wx.showToast({
|
title: res.msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
// 清除刚才的录音
|
th.setData({ time_luyin: 0, file_luyin: null });
|
// 页面进入第1步
|
th.setData({ bushu: 1 });
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu(function(){
|
// 弹框取消
|
th.Click_bian();
|
});
|
}
|
}
|
});
|
}
|
// 无录音文件时:看完视频就领
|
else
|
{
|
// 数据准备
|
var mydata = {
|
appid: 'wx4dbc1f6c7cf71b68',
|
id: th.data.videoid,
|
openid: th.data.openid
|
};
|
var myurl = com.getWholeUrl('bainian/api/client/video/hb/recievehb',mydata);
|
// 发送数据
|
wx.showLoading({ title: '' });//loading框展示
|
dowx.AjaxPost( myurl,{},function (res)
|
{
|
wx.hideLoading();
|
dowx.AjaxStop();
|
|
if (res.code == 0) {
|
// 保存金额
|
th.setData({ bao_jine: res.data.money });
|
// 进入到红包第2步
|
th.setData({ yc_baobushu: 2 });
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu();
|
}
|
else {
|
wx.showToast({
|
title: res.msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu(function(){
|
// 弹框取消
|
th.Click_bian();
|
});
|
}
|
});
|
}
|
},
|
// 查看详情 点击
|
Click_xiangq: function()
|
{
|
th.myvideo.pause(); // 视频暂停
|
wx.navigateTo({ url: '/pages/lingqulist/lingqulist?videoid='+th.data.videoid+'&type='+th.data.typenum });
|
},
|
|
// 分享隐藏框 事件 ----------------------------------------------------------------------------------------
|
//
|
// 蒙层 点击
|
Click_yc: function () {
|
th.setData({ yc_if2: false }); // 分享选择框隐藏
|
th.myvideo.show(); // video显示
|
},
|
// 取消冒泡传递
|
Click_yc2: function () {},
|
// 朋友圈分享图 点击
|
Click_sharepyq: function () {
|
// 打开图片预览
|
wx.previewImage({
|
urls: [th.data.shareimg],
|
fail: function (res) { dowx.Showred(th, '打开分享图→fail'); }
|
});
|
},
|
|
|
// 按键 事件 ----------------------------------------------------------------------------------------
|
//
|
// 主页按钮
|
Click_paishe: function () { wx.reLaunch({ url: '/pages/index/index' }); },
|
|
// 分享按钮
|
Click_share: function ()
|
{
|
// 视频是否已经生成
|
if (th.data.process != 100) {
|
// 弹框表示正在生成中
|
dowx.Showgreen(th, '正在生成中');
|
return false;
|
}
|
// 暂停video播放
|
th.myvideo.pause();
|
// 隐藏video
|
th.myvideo.hide();
|
// 停止播放录音文件
|
th.myaudio.stopben(); //本地播
|
th.myaudio.stopwang(); //网络播
|
// 显示分享选项弹框
|
th.setData({ yc_if2: true });
|
},
|
|
// 录制录音按钮 按下
|
working_record: false,
|
An_luzhi: function ()
|
{
|
// 视频是否已经生成
|
if (th.data.process != 100) {
|
// 弹框表示正在生成中
|
dowx.Showgreen(th, '正在生成中');
|
return false;
|
}
|
if (th.working_record == true) { return false; }
|
th.working_record = true;
|
// 暂停video播放
|
th.myvideo.pause();
|
// 录音提示显示
|
th.setData({ show_ly: true, time_show: '00' });
|
// 启动录音
|
dowx.Record_start(th, th.data.time_luyinmax, function (res)
|
{
|
// 这里是录音文件回调
|
if (res.time < th.data.time_luyinmin)
|
{
|
wx.showToast({
|
title: '最少需要' + th.data.time_luyinmin + 's',
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
th.setData({ file_luyin: null, time_luyin: 0 }); //消除录音文件
|
}
|
else if (res.time >= th.data.time_luyinmin) {
|
// 录音提示隐藏
|
th.setData({ show_ly: false });
|
// 录音信息赋值
|
th.setData({ file_luyin: res.tempFilePath, time_luyin: res.time });
|
// 进入第2步
|
th.setData({ bushu: 2 });
|
}
|
th.working_record = false;
|
},
|
function(timeD)
|
{
|
var mo_timed = '00';
|
if (timeD < 10) { mo_timed = '0' + timeD; }
|
else if (timeD >= 10) { mo_timed = timeD; }
|
th.setData({ time_show: mo_timed });
|
});
|
},
|
// 录制录音按钮 松开
|
Out_luzhi: function ()
|
{
|
// 视频是否已经生成
|
if (th.data.process != 100) { return false; }
|
// 录音提示隐藏
|
th.setData({ show_ly: false });
|
// 停止录音
|
dowx.Record_stop(th);
|
},
|
|
// 重录按钮
|
Click_chonglu: function ()
|
{
|
th.myaudio.stopben(); //录音播放停止
|
th.tf_baibo = false; //录音播放停止
|
th.setData({ file_luyin: null, time_luyin: 0 }); //消除录音文件
|
th.setData({ bushu: 1 }); //步数回到第1步
|
},
|
|
// 播放本地录音按钮
|
Click_luyinbo: function ()
|
{
|
// 语音未在播放则进行播放
|
if (th.tf_baibo != true)
|
{
|
// 暂停video播放
|
th.myvideo.pause();
|
// 播放录音文件
|
th.myaudio.playben();
|
th.tf_baibo = true;
|
}
|
// 语音在播放则暂停
|
else{
|
//停止播放录音文件
|
th.myaudio.stopben();
|
th.tf_baibo = false;
|
}
|
},
|
// 播放后台录音按钮
|
Click_luyinbo1: function ()
|
{
|
// 语音未在播放则进行播放
|
if (th.tf_baibo != true)
|
{
|
// 暂停video播放
|
th.myvideo.pause();
|
//播放录音文件
|
th.myaudio.playwang();
|
th.tf_baibo = true;
|
}
|
// 语音在播放则暂停
|
else{
|
//停止播放录音文件
|
th.myaudio.stopwang();
|
th.tf_baibo = false;
|
}
|
},
|
|
// 上传录音按钮
|
Click_queren: function ()
|
{
|
// 据情况弹出红包框,未领取过钱且红包还有剩余便可弹出
|
if (th.data.tf_hadlingqu == false && th.data.had_lingqu < th.data.max_lingqu)
|
{
|
th.myvideo.pause(); // 暂停video
|
th.myvideo.hide(); // 隐藏video
|
th.setData({ yc_bao: true }); // 红包显示
|
}
|
// 不然只上传录音
|
else {
|
// 数据准备
|
var mydata = {
|
appid: 'wx4dbc1f6c7cf71b68',
|
id: th.data.videoid,
|
openid: th.data.openid,
|
time: th.data.time_luyin
|
};
|
var myurl = uphttp + 'bainian/api/client/video/hb/recievehb';
|
// 发送数据
|
wx.showLoading({ title: '' });//loading框展示
|
wx.uploadFile({
|
url: myurl,
|
filePath: th.data.file_luyin,
|
name: 'voice',
|
formData: mydata,
|
fail: function () {
|
wx.hideLoading();
|
wx.showToast({
|
title: '录音上传→fail',
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
},
|
success: function (res)
|
{
|
wx.hideLoading();
|
res = JSON.parse(res.data);
|
if (res.code == 0) {
|
// 弹框提示
|
dowx.Showgreen(th, '上传成功');
|
// 清除刚才的录音
|
th.setData({ time_luyin: 0, file_luyin: null });
|
// 回到步数1
|
th.setData({ bushu: 1 });
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu();
|
}
|
else {
|
wx.showToast({
|
title: res,msg,
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
// 清除刚才的录音
|
th.setData({ time_luyin: 0, file_luyin: null });
|
// 回到步数1
|
th.setData({ bushu: 1 });
|
// 获取该视频红包的相关信息
|
th.getdata.videoxiangqin();
|
// 获取弹幕组
|
th.getdata.danmu();
|
}
|
}
|
});
|
}
|
},
|
|
// 打赏按钮
|
Click_dashang: function ()
|
{
|
// 视频是否已经生成
|
if (th.data.process != 100) {
|
// 弹框表示正在生成中
|
dowx.Showgreen(th, '正在生成中');
|
return false;
|
}
|
th.myvideo.pause(); // 视频暂停
|
wx.navigateTo({ url: '/pages/dashang/dashang?videoid=' + th.data.videoid });
|
},
|
|
// 弹幕点击
|
Click_danmudan: function (ev)
|
{
|
// 获取点钱点击的弹幕的下标index
|
var index = ev.currentTarget.id;
|
th.myvideo.pause(); // 视频暂停
|
wx.navigateTo({
|
url: '/pages/lingqulist/lingqulist?videoid=' + th.data.videoid + '&type=' + th.data.typenum + '&index=' + index
|
});
|
},
|
|
|
|
// 组件对象 -----------------------------------------------------------------------------------------------
|
//
|
// 视频组件
|
myvideo: {
|
obj: null, // 组件对象
|
id: 'myvideo', // 组件id
|
uploadpath: null, // 下载的视频本地地址
|
// video组件显示
|
show: function () {
|
// 设置显示
|
th.setData({ show_video: true });
|
// 弹幕滚动
|
th.getdata.setinval_danmu();
|
},
|
// video组件隐藏
|
hide: function () {
|
// 清除弹幕定时器
|
th.getdata.clear_danmu();
|
// 设置隐藏
|
th.setData({ show_video: false });
|
},
|
// 暂停视频
|
pause: function ()
|
{
|
if (th.myvideo.obj == null) { th.myvideo.obj = wx.createVideoContext(th.myvideo.id); }
|
th.myvideo.obj.pause();
|
// 清除弹幕定时器
|
th.getdata.clear_danmu();
|
},
|
// 下载视频
|
uploadvideo: function ()
|
{
|
//未下载完成时通过
|
if (th.myvideo.uploadpath == null)
|
{
|
// 未在工作中状态才可以下载
|
if (th.tf_working_upload != true)
|
{
|
th.tf_working_upload = true; //正在下载工作中
|
// 视频下载
|
wx.downloadFile({
|
url: th.data.url_video,
|
fail: function () { console.log('视频下载失败'); },
|
success: function (res)
|
{
|
console.log("视频下载完成");
|
//路径赋值
|
th.myvideo.uploadpath = res.tempFilePath;
|
th.tf_working_upload = false; //未在下载工作中
|
}
|
});
|
// 标题图下载
|
wx.downloadFile({
|
url: th.data.src_videoimg,
|
fail: function () { console.log('标题图下载失败'); },
|
success: function (res) { th.setData({ src_videoimg: res.tempFilePath }); }
|
});
|
}
|
}
|
},
|
// 播放完毕后,重置src,让封面图显示
|
endplay: function ()
|
{
|
// 初始化src
|
th.setData({ src_video: null });
|
// 下载完成时
|
if (th.myvideo.uploadpath != null) { th.setData({ src_video: th.myvideo.uploadpath }); }
|
// 没有下载完成时
|
else { th.setData({ src_video: th.data.url_video }); }
|
// 据情况弹出抢红包框
|
if (th.data.tf_hadlingqu == false && th.data.had_lingqu < th.data.max_lingqu)
|
{
|
th.myvideo.pause(); // 暂停
|
th.myvideo.hide(); // 隐藏
|
th.setData({ yc_bao: true }); // 红包框出现
|
}
|
}
|
},
|
|
// 当video开始播放时触发
|
Bindplay: function () {
|
// 视频下载
|
th.myvideo.uploadvideo();
|
// 弹幕滚动
|
th.getdata.setinval_danmu();
|
},
|
// 视频播放完毕触发
|
Over_video: function () { th.myvideo.endplay(); },
|
|
// 音频组件
|
myaudio: {
|
obj: null, // 组件对象
|
id: 'myaudio', // 组件id
|
// 开始本地录音播放
|
playben: function ()
|
{
|
// wifi图标变化
|
dowx.Play_wifi(th, 'luyinbo_wifi');
|
wx.playVoice({
|
filePath: th.data.file_luyin,
|
fail: function () {
|
wx.showToast({
|
title: '录音播放→fail',
|
image: '/img/zdo_error.png',
|
duration: 2500,
|
});
|
},
|
success: function () {
|
th.myaudio.stopben();
|
},
|
});
|
},
|
// 停止本地录音播放
|
stopben: function()
|
{
|
//wifi动画停止
|
dowx.Stop_wifi(th, 'luyinbo_wifi');
|
wx.stopVoice();
|
},
|
// 开始网络音频播放
|
playwang: function ()
|
{
|
if (th.myaudio.obj == null) { th.myaudio.obj = wx.createAudioContext(th.myaudio.id); }
|
th.myaudio.obj.setSrc(th.data.file_luyin);
|
th.myaudio.obj.play();
|
// wifi图标变化
|
dowx.Play_wifi(th, 'luyinbo_wifi');
|
},
|
// 停止网络音频播放
|
stopwang: function()
|
{
|
if (th.myaudio.obj == null) { th.myaudio.obj = wx.createAudioContext(th.myaudio.id); }
|
th.myaudio.obj.seek(0);
|
th.myaudio.obj.pause();
|
//wifi动画停止
|
dowx.Stop_wifi(th, 'luyinbo_wifi');
|
},
|
},
|
|
// 网络音频播放完毕
|
audioend: function () { dowx.Stop_wifi(th, 'luyinbo_wifi'); th.tf_baibo = false; },
|
|
})
|