直播平臺源碼搭建教程:微信小程序中的直播如何去掉水印
本文與大家分享一下直播平臺源碼搭建教程,如何去掉直播視頻的水印
var services = require('../../lib/service')
var ReceiverOptions = null;
Page({
data: {
loading: false,
videoInfo: {}, //{videoId:0,videourl:'',title:''}
//0:加載完成(還有數據) 1:加載中 2:加載完成(沒有更多數據了)
searchLoadingStatus: 2,
//1:已授權 0:未授權
typeCode: 0,
//搜索位置名稱
searchKeyWord: '',
systemInfo: {},
//視頻下載狀態 0:未下載 1:正在下載
videoDownLoadStatus: 0,
videoDownProgress: 0,
videoPlayCoverList: [],
//是否顯示下載視頻按鈕
showDownLoadBtn: false,
//顯示分享按鈕
showShareVideoBtn: false,
//是否顯示在線客服
showOnlineKf: false,
//積分總數
creditsAmountSum: 0,
//視頻下載Url
downLoadVideoUrl: '',
//視頻下載提示語
downloadVideoWaitRemindText: '正在生成視頻地址,請稍後...'
},
onLoad(options) {
var that = this;
wx.getSystemInfo({
success: function(res) {
that.setData({
systemInfo: res //windowWidth,windowHeight
});
console.log(res);
}
});
getApp().getWxLoginInfo(function() {
that.loadSupportPlat(true);
that.videoSystemSetting();
});
},
onShow() {
var that = this;
var userLoginStatus = getApp().globalData.UserInfo.UserLoginStatus;
if (userLoginStatus) {
that.loadSupportPlat(false);
}
wx.getClipboardData({
success(res) {
console.log(res.data);
var linkStr = res.data;
if (linkStr.indexOf('http:') >= 0 || linkStr.indexOf('https:') >= 0) {
//清空剪切板內容
wx.setClipboardData({
data: ' ',
success(clearRes) {
wx.hideToast();
}
})
wx.showModal({
title: '是否粘貼剪切板中的鏈接地址',
content: linkStr,
success(res) {
if (res.confirm) {
that.setData({
searchKeyWord: linkStr
});
}
}
})
}
}
})
that.setData({
searchLoadingStatus: 2
});
},
loadSupportPlat: function(loading) {
var that = this;
services.service('minivideo/getplatlist', {
"WxUserId": 0
},
function(res) {
console.log(res);
that.setData({
videoPlayCoverList: res.data.Data
});
}, null, null, loading);
},
loadShareVideo: function() {
let that = this;
var videoId = that.data.videoInfo.videoId;
//videoId = 10004;
if (videoId > 0) {
services.service('minivideo/getvideoinfo', {
"WxUserId": 0,
"VideoId": videoId
},
function(res) {
console.log(res);
if (res.data.Status) {
var analysisStatus = res.data.Data.AnalysisStatus;
var showDownLoadBtn = false;
//下載成功,顯示下載,分享按鈕
if (analysisStatus == 3) {
showDownLoadBtn = true;
}
that.setData({
downloadVideoWaitRemindText: '',
showDownLoadBtn: showDownLoadBtn,
showShareVideoBtn: true,
videoInfo: {
videoId: videoId,
videourl: res.data.Data.VideoUrl
},
downLoadVideoUrl: res.data.Data.VideoUrl
});
}
}, null, null, true);
} else {
}
},
//系統設置
videoSystemSetting: function() {
let that = this;
services.service('minivideo/getconfig', {},
function(res) {
console.log(res);
if (res.data.Status) {
that.setData({
showShareVideoBtn: res.data.Data.ShowShareVideo,
showOnlineKf: res.data.Data.ShowOnlineKf
});
}
}, null, null, false);
},
//保存視頻到相冊
btnSaveVideo: function() {
var that = this;
wx.authorize({
scope: "scope.writePhotosAlbum",
success: function() {
var downLoadStatus = that.data.videoDownLoadStatus;
if (downLoadStatus == 0) {
var videourl = that.data.downLoadVideoUrl;
if (videourl == null || videourl == '') {
that.showToast('請先提取視頻');
return;
}
that.setData({
videoDownLoadStatus: 1,
videoDownProgress: 0
})
const downloadTask = wx.downloadFile({
url: videourl,
success(res) {
if (res.statusCode === 200) {
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
//保存成功
that.showSuccessToast('已保存到相冊');
},
fail(res) {
console.log(res);
that.showToast('保存失敗');
}
})
}
},
fail(res) {
that.showToast('下載視頻失敗');
},
complete(res) {
that.setData({
videoDownLoadStatus: 0
})
}
})
//監聽下載進度
downloadTask.onProgressUpdate(function(res) {
that.setData({
videoDownProgress: res.progress
})
})
}
},
fail: function() {
that.showToast('授權保存視頻到相冊失敗,請刪除該小程序重新授權');
}
});
},
//複製鏈接
copyVideoLink: function() {
var that = this;
var videoUrl = that.data.videoInfo.videourl;
wx.setClipboardData({
data: videoUrl,
success(res) {
that.showToast('複製成功')
}
});
},
//搜索
bindSearchTap: function(e) {
console.log('開始提取視頻')
console.log(e);
var that = this;
var searchLoadingStatus = that.data.searchLoadingStatus;
if (searchLoadingStatus != 1) {
that.setData({
//加載中
searchLoadingStatus: 1
});
var _userInfo = e.detail.userInfo;
if (_userInfo != null && _userInfo != undefined) {
//先授權
getApp().authorUserInfo(_userInfo, function(data) {
that.getVideoPlayUrl();
}, false);
} else {
that.showToast("請先允許微信授權");
that.setData({
//加載中
searchLoadingStatus: 2
});
}
}
},
//使用教程
bindUseCourse: function(e) {
wx.navigateTo({
url: '../useCourse/useCourse'
});
},
//跳轉到位置收藏大師
navigateToLocationMiniProgram: function(e) {
var wxUserId = getApp().globalData.UserInfo.WxUserId;
wx.navigateToMiniProgram({
appId: 'wxb91f7b85c23f0624',
path: 'pages/home/home?skip=' + wxUserId,
//extraData: {
// flag: 'Skip_1'
//},
envVersion: 'release',
success(res) {
// 打開成功
},
fail(res) {
that.showToast('調起小程序失敗,請稍後重試');
}
})
},
//清空輸入框
clearInput: function() {
var that = this;
that.setData({
searchKeyWord: ''
});
},
//輸入框輸入監聽
searchInputMonitor: function(e) {
var that = this;
that.setData({
searchKeyWord: e.detail.value
});
},
//提取視頻
getVideoPlayUrl: function() {
var that = this;
that.startGetVideoPlayUrl();
},
startGetVideoPlayUrl: function() {
var that = this;
var wxUserId = getApp().globalData.UserInfo.WxUserId;
var keyword = that.data.searchKeyWord;
services.service('minivideo/addvideourl', {
WxUserId: wxUserId,
OriginalUrl: keyword,
XcxTypeCode: 1
},
function(res) {
if (res.data.Status) {
var videoUrl = res.data.Data.VideoUrl;
var videoRecordId = res.data.Data.VideoRecordId;
var videoImgs = res.data.Data.Imgs;
that.setData({
videoInfo: {
videoId: videoRecordId,
videourl: videoUrl,
title: '',
imgs: videoImgs
}
});
var needDownLoadToServer = res.data.Data.NeedDownLoadToServer;
if (needDownLoadToServer) {
if (videoUrl != null && videoUrl != '') {
that.downLoadVideoToServer(wxUserId, videoUrl, videoRecordId);
}
} else {
that.setData({
downLoadVideoUrl: videoUrl,
showDownLoadBtn: true
});
}
} else {
wx.showModal({
content: res.data.Msg,
showCancel: false
})
}
}, null,
function() {
that.setData({
//加載完成
searchLoadingStatus: 2
});
})
},
//下載視頻到服務器
downLoadVideoToServer: function(wxUserId, videoUrl, videoRecordId) {
var that = this;
that.setData({
showDownLoadBtn: false,
downloadVideoWaitRemindText: '正在生成視頻地址,請稍後...'
});
services.service('minivideo/downloadvideo', {
"WxUserId": wxUserId,
"VideoUrl": videoUrl,
"VideoRecordId": videoRecordId
},
function(res) {
if (res.data.Status) {
var url = res.data.Data.Url;
that.setData({
downLoadVideoUrl: url,
showDownLoadBtn: true
});
} else {
that.showToast(res.data.Msg);
that.setData({
showDownLoadBtn: false,
downloadVideoWaitRemindText: res.data.Msg
});
}
}, null, null, false);
},
//如何獲取更多次數
getTimesMore: function() {
wx.navigateTo({
url: '../getTimesMore/getTimesMore'
});
},
showToast(title) {
wx.showToast({
title: title,
icon: 'none',
duration: 2000
})
},
onShareAppMessage: function(res) {
let that = this;
return {
path: '/pages/home/home'
}
}
});
以上就是直播平臺源碼搭建教程,歡迎感興趣的朋友一起討論。