合并主分支的视频播放

This commit is contained in:
@fawn-nine
2024-08-19 14:39:29 +08:00
17 changed files with 8670 additions and 2729 deletions

View File

@@ -1,13 +1,12 @@
<template>
<view class="richDetail">
<!-- 公共组件-每个页面必须引入 -->
<view
scroll-x="true"
class="detail_title video_box"
style="background-color: #fff"
>
>
<view
v-for="(v, i) in dataList"
:class="`video_item ${currentVideo&&currentVideo.id == v.id ? 'hot' : ''}`"
@@ -28,13 +27,16 @@
import $http from "@/config/requestConfig.js";
import { mapState } from "vuex";
export default {
props: ["detailInfo", "dataList", "currentVideo"],
props: ["detailInfo", "dataList", "currentVideo", "changeVideoLock"],
components: {},
data() {
return {};
},
onLoad(options) {},
onHide() {},
mounted() {
console.log('currentVideo播放列表收到的--',this.currentVideo)
},
computed: {
...mapState(["userInfo"]),
},
@@ -47,8 +49,10 @@ export default {
}
},
handleClick(data) {
if(this.changeVideoLock){
return
}
console.log("data at line 35:", data);
this.$emit("open", data);
},

View File

@@ -1,13 +1,27 @@
<template>
<view class="container" style="background-color: #000; position: relative">
<view class="container" style="background-color: #000; position: relative">
<view style="width: 100%; height: 200px">
<view v-if="show" style="height: 100%;display: flex;align-items:center;justify-content:center;color: #fff;font-size: 38rpx;text-align: center;">{{errorTxt}}</view>
<view v-if="showCountDown" class="showCountDownd" style="">
<view class="">
<text class="nextText">{{secondCountDown}} 秒后播放下一个视频</text><br/>
<view >
<text class="cancelNext" @click="hideNextVideo">取消下一个</text>
<!-- <text class="cancelNext" @click="replayVideo">重新播放</text> -->
</view>
<!-- <view class="cancelNext" @click="hideNextVideo">重新播放</view> -->
</view>
</view>
<view v-if="show"
style="height: 100%;display: flex;align-items:center;justify-content:center;color: #fff;font-size: 38rpx;text-align: center;">
{{errorTxt}}</view>
<div class="" v-else style="background-color: #000" ref="videoContent" @tap="renderScript.handleClick"
id="url-player-test" :videoData="videoData" :winWidth="winWidth" :winHeight="winHeight"
:currentVideoList="currentVideoList" :firstTime="firstTime" :isfresh="isfresh" :platform="platform"
:isSetFirstTime="isSetFirstTime" :isChange="isChange" :change:videoData="renderScript.receiveMsg"
:replayVideoFlag="replayVideoFlag"
:change:winWidth="renderScript.receiveWinWidth" :change:winHeight="renderScript.receiveWinHeight"
:change:firstTime="renderScript.receiveFirstTime"
:change:replayVideoFlag="renderScript.receiveReplayVideoFlag"
:change:isSetFirstTime="renderScript.receiveisSetFirstTime"
:change:isfresh="renderScript.receiveIsfresh" :change:platform="renderScript.receiveplatform"
:change:isChange="renderScript.receiveIsChange"
@@ -29,11 +43,23 @@
<div @tap="renderScript.emitopenShow" ref="videoContent5" v-show="false" class="videoContent5">
打开视频提示
</div>
<div @tap="renderScript.emitLoadNextVideo" ref="videoContent6" v-show="false" class="videoContent6">
播放下一条
</div>
<div @tap="renderScript.emitHideNextVideo" ref="videoContent7" v-show="false" class="videoContent7">
隐藏播放下一条界面
</div>
<div @tap="renderScript.emitReplayVideoFlagFalse" ref="videoContent8" v-show="false" class="videoContent8">
隐藏播放下一条界面
</div>
<div @tap="renderScript.emitUnlockChangeVideo" ref="videoContent9" v-show="false" class="videoContent9">
释放切换键锁
</div>
<div class="fullScreenButton-container">
<div :class="`prism-fullscreen-btn ${isFullScreen ? 'fullscreen' : ''}`"
@tap="renderScript.changeVideoScreen"></div>
</div>
</view>
</view>
</view>
</template>
<script>
@@ -43,12 +69,13 @@
mapState,
mapMutations
} from "vuex";
export default {
props: ["currentVideo", "currentVideoList","videoTitle"],
props: ["currentVideo", "currentVideoList", "videoTitle",'secondCountDown'],
data() {
return {
show: false,
reaquestFlag: false,
show: false,
platform: null,
//当前是否是全屏模式
isFullScreen: false,
@@ -56,8 +83,13 @@
isChange: false,
isControl: true,
timer: null,
replayVideoFlag:false,
// secondCountDown: 5,
showCountDown: false,
playEndBlank:false,
// videoTitle: "",
videoList: [],
replayVideoLock:false,// 重播操作锁
firstTime: 0,
options: {},
playAuth: "",
@@ -67,7 +99,7 @@
isSetFirstTime: false,
screenType: null,
videoUrl: null,
errorTxt:'此设备暂不支持观看当前视频请移步到安卓手机进行学习!'
errorTxt: '此设备暂不支持观看当前视频请移步到安卓手机进行学习!'
};
},
computed: {
@@ -101,20 +133,56 @@
plus.screen.lockOrientation("portrait-primary"); //锁死屏幕方向为竖屏
// #endif
await this.setVideoTime();
await this.setVideoTime();
},
//第一次加载
onLoad(options) {
},
methods: {
replayVideo(){
if(!this.replayVideoFlag){
this.getLive(true, this.currentVideo)
console.log('this.currentVideo',this.currentVideo.id);
this.hideNextVideo()
this.replayVideoFlag = true
}
},
replayVideoFlagFalse(){
console.log('复原replayVideoFlag',this.replayVideoFlag);
this.replayVideoFlag = false
},
UnlockChangeVideo(){
this.$emit('unlockChangeVideo')
},
hideNextVideo(){
this.showCountDown = false
this.playEndBlank = false
this.$emit('hideNextVideo')
},
loadNextVideo() {
this.playEndBlank = true
var _list = [...this.currentVideoList]
_list = _list.map(item => { return item.id})
var thisIndex = _list.findIndex(item=>{
return item == this.currentVideo.id
})
console.log('播放列表',_list,this.currentVideo.id, thisIndex);
if(thisIndex < this.currentVideoList.length-1){
this.showCountDown = true
this.$emit('startNextVideoCountDown')
}
},
openShow(data) {
data.msg ? this.errorTxt = data.msg : '此设备暂不支持观看当前视频请移步到安卓手机进行学习'
this.show = true;
},
start() {
start() {
this.$refs.playerView.start();
},
pause() {
@@ -126,11 +194,13 @@
this.isChange = false;
},
async changeVideo(data) {
console.log('changeVideo+++++++++', data);
this.currentTime = "";
this.firstTime = 0;
this.isSetFirstTime = false;
this.isChange = false;
await this.init(data, true);
this.getLive(true, data)
// await this.init(data, true);
},
screenChange(data) {
console.log(
@@ -139,7 +209,7 @@
data.primary
);
this.isFullScreen = !data.status;
this.$emit("changeScreen", this.isFullScreen);
this.$emit("changeScreen", this.isFullScreen);
},
// 控制器的显示隐藏
controlChange(e) {
@@ -149,7 +219,7 @@
// 退出全屏
const ctx = this.$refs.myVideo;
ctx.exitFullScreen();
},
},
// 播放器初始化
async init(data, isChange) {
this.show = false;
@@ -163,8 +233,8 @@
this.videoId = this.options.video;
console.log("这是苹果视屏id", this.videoId);
await this.getLive(isChange);
},
await this.getLive(isChange,this.options);
},
// 配置播放项
async getData(data, isChange) {
var that = this;
@@ -175,9 +245,9 @@
var list = [];
if (uni.getStorageSync("videoOssList")) {
list = JSON.parse(uni.getStorageSync("videoOssList"));
var index = list.findIndex((e) => e.id == data.id);
console.log('data.id',data.id);
console.log('data.id', data.id);
if (netWork) {
if (index >= 0) {
this.firstTime =
@@ -198,26 +268,26 @@
this.videoData = {
...data,
firstTime : this.firstTime
firstTime: this.firstTime
};
this.isChange = isChange ? isChange : false;
console.log(this.firstTime, "这是第一次播放时长222");
this.isChange = isChange ? isChange : false;
console.log(this.firstTime, "这是第一次播放时长222");
uni.setStorageSync("videoOssList", JSON.stringify(list));
console.log(this.firstTime, "这是第一次播放时长");
console.log(this.firstTime, "这是第一次播放时长");
}
this.isSetFirstTime = true;
},
// 存储本地播放时间
recordTime(data) {
console.log('recordTime',data.time);
console.log('recordTime', data.time);
this.currentTime = data.time;
var list = [];
if (uni.getStorageSync("videoOssList")) {
list = JSON.parse(uni.getStorageSync("videoOssList"));
}
var index = list.findIndex((e) => e.id == this.videoData.id);
var index = list.findIndex((e) => e.id == this.videoData.id);
if (list.length > 0 && index >= 0) {
list[index] = {
...this.videoData,
@@ -232,13 +302,25 @@
uni.setStorageSync("videoOssList", JSON.stringify(list));
},
// 获取播放凭证
async getLive(isChange) {
async getLive(isChange, newVideoData) {
console.log('获取播放凭证',newVideoData.id);
if (this.reaquestFlag) {
uni.showToast({
title: '操作太快了,歇一下吧',
icon: 'none'
})
}
this.reaquestFlag = true
var that = this;
this.isfresh = false;
var data = {
...this.options,
};
if (isChange && newVideoData) {
data = {
...newVideoData,
};
}
await $http
.request({
url: `sociology/course/checkVideo`,
@@ -250,26 +332,29 @@
},
})
.then(async (res) => {
if (this.$platform == 'ios') {
if (this.currentVideo.type == 1 && res.video.m3u8Url == null || this.currentVideo.type == 1 && res.video.m3u8Url == '') {
this.reaquestFlag = false
if (this.$platform == 'ios') {
if (this.currentVideo.type == 1 && res.video.m3u8Url == null || this.currentVideo
.type == 1 && res.video.m3u8Url == '') {
// 只存在私有加密
this.show = true
uni.showModal({
content: '抱歉,苹果手机不支持此加密视频格式,您可以在安卓端观看本视频',
confirmText: '知道了',
showCancel: false,
success: function (res) {
if (res.confirm) {
// uni.navigateBack({delta: 2})
}
success: function(res) {
if (res.confirm) {
// uni.navigateBack({delta: 2})
}
}
})
return
}
}
var data = {
...res.video,
};
};
if (this.currentVideo.type == 1) {
var playAuth = res.video.playAuth.replace(/=/g, "");
// console.log("这是接口获取的视屏凭证111", playAuth);
@@ -292,13 +377,19 @@
console.log("是否获取到初始播放值", data);
that.$forceUpdate();
}).catch(e => {
this.reaquestFlag = false
uni.showToast({
'title': '获取播放地址失败',
icon: 'none'
})
});
},
async handleEnd() {
var list = JSON.parse(uni.getStorageSync("videoOssList"));
var data = list.find((e) => e.id == this.videoData.id);
this.currentTime = data.time;
async handleEnd() {
var list = JSON.parse(uni.getStorageSync("videoOssList"));
var data = list.find((e) => e.id == this.videoData.id);
this.currentTime = data.time;
console.log(
"this.currentTime at line 这是结束的时候掉的存储视频:",
this.currentTime
@@ -309,10 +400,10 @@
},
// 存储时长到线上
setVideoTime(time) {
var data = {};
console.log("是否走了存储视屏," + this.videoData.id, time,this.currentTime);
var data = {};
console.log("是否走了存储视屏," + this.videoData.id, time, this.currentTime);
let _time = null
time ? _time = time : _time = this.currentTime
time ? _time = time : _time = this.currentTime
var data = {
videoId: this.videoData.id,
position: _time, //秒数
@@ -335,17 +426,17 @@
}).catch(e => {
console.log("存储进度报错", e);
});
},
},
goBack() {
uni.navigateBack({
delta: 1,
});
},
// 设置初始播放时间 并开启定时器
async setVideoFirtsetTime(data) {
async setVideoFirtsetTime(data) {
this.currentTime = this.firstTime;
console.log("setVideoFirtsetTime播放时间:", data.time);
await this.setVideoTime(data.time);
await this.setVideoTime(data.time);
},
},
@@ -356,11 +447,13 @@
<script module="renderScript" lang="renderjs">
var videoData = null
var _seconds = 0
var ReplayVideoFlag = false
var curStatus = null
var diff = 0
import $ from 'jquery'
export default {
var pauseTime = 0
var myplayer = undefined
import $ from 'jquery'
export default {
components: {
// MyComponent
},
@@ -398,28 +491,56 @@
})
},
async receiveFirstTime(newValue, oldValue, ownerVm, vm) {
receiveReplayVideoFlag(newValue, oldValue, ownerVm, vm) {
console.log('newValue重新播放',newValue,myplayer);
ReplayVideoFlag = newValue
if(newValue){
$('.videoContent8').click()
// ReplayVideoFlag = newValue
// // myplayer.replay()
// $('.videoContent7').click()
// myplayer.seek(0)
// myplayer.play()
}
},
emitReplayVideoFlagFalse(event, ownerInstance) {
ownerInstance.callMethod('replayVideoFlagFalse')
},
emitUnlockChangeVideo(event, ownerInstance) {
ownerInstance.callMethod('UnlockChangeVideo')
},
async receiveFirstTime(newValue, oldValue, ownerVm, vm) {
},
async receiveisSetFirstTime(newValue, oldValue, ownerVm, vm) {
console.log('是否刚开始设置播放时间', newValue, this.firstTime, this.player);
console.log('是否刚开始设置播放时间', newValue, this.firstTime, myplayer);
},
emitSetData(event, ownerInstance) {
// var that = this;
ownerInstance.callMethod('setVideoFirtsetTime',{
time: _seconds,
ownerInstance.callMethod('setVideoFirtsetTime', {
time: _seconds,
})
},
emitHideNextVideo(event, ownerInstance) {
ownerInstance.callMethod('hideNextVideo')
},
emitLoadNextVideo(event, ownerInstance) {
ownerInstance.callMethod('loadNextVideo')
},
emitopenShow(event, ownerInstance) {
ownerInstance.callMethod('openShow',{msg:'播放出错啦!'})
ownerInstance.callMethod('openShow', {
msg: '播放出错啦!'
})
},
// 全屏切换事件
changeVideoScreen(event, ownerInstance) {
var that = this;
// this.$emit('changeScreenLoading',true)
var status = this.player.fullscreenService.getIsFullScreen();
console.log('this.$platform--------',this.platform);
if (this.platform != 'ios') { // 改变按钮形态
var status = myplayer.fullscreenService.getIsFullScreen();
console.log('this.$platform--------', this.platform);
if (this.platform != 'ios') { // 改变按钮形态
ownerInstance.callMethod('screenChange', {
status: status,
primary: status ? 'portrait' : 'landscape'
@@ -427,22 +548,22 @@
}
if (status) {
if (this.platform != 'ios') {
console.log('恢复竖版');
setTimeout(() => {
plus.screen.lockOrientation("portrait-primary"); //锁死屏幕方向为竖屏
this.player.fullscreenService.cancelFullScreen();
}, 100);
console.log('恢复竖版');
setTimeout(() => {
plus.screen.lockOrientation("portrait-primary"); //锁死屏幕方向为竖屏
myplayer.fullscreenService.cancelFullScreen();
}, 100);
}
} else {
this.player.fullscreenService.requestFullScreen();
myplayer.fullscreenService.requestFullScreen();
if (this.platform != 'ios') {
setTimeout(() => {
plus.screen.lockOrientation("landscape-primary");
plus.screen.lockOrientation("landscape-primary");
}, 100);
}else{
} else {
console.log('不要旋转, 使用原生全屏');
}
}
},
changeVideoData(event, ownerInstance) {
@@ -455,13 +576,12 @@
},
// renderjs阿里云播放器引入与配置
getLive() {
console.log('这是这只只是666666:', this.firstTime, this.videoData)
if (this.player) {
this.player.dispose();
console.log('这是这只只是666666:', this.firstTime, this.videoData)
$('#url-player-test').empty();
this.player = null;
}
var fullScreenButtonComponent = Aliplayer.Component({
pauseTime = 0
var fullScreenButtonComponent = Aliplayer.Component({
/**
* 初始函数在new对象时调用
*
@@ -483,58 +603,33 @@
var $adWrapper = this.$html.find('.ad-wrapper');
$adWrapper.attr('href', this.toAddress);
$adWrapper.click(function() {
});
});
$(el).find('.prism-time-display').after(this.$html);
},
ready: function(player, e) {
// this.$html.hide()
},
/**
* 隐藏广告
*/
play: function(player, e) {
// this.$html.show();
},
/**
* 显示广告
*/
pause: function(player, e) {
// this.$html.show();
},
/**
* 隐藏广告
*/
playing: function(player, e) {
this.$html.show();
this.$html.show();
// this.$html.hide();
},
waiting: function(player, e) {
// this.$html.hide()
},
timeupdate: function(player, e) {},
error: function(player, e) {},
/**
* 显示广告
*/
ended: function(player, e) {
}
});
console.log('这是查看是否获取到hlstoken', this.videoData)
// console.log('这是查看是否获取到hlstoken', this.videoData)
var playerOptions = {
id: "url-player-test",
                width: '100%', //容器的大小
                height: '100%', //容器的大小
                "qualitySort": "asc",
                "cover": "",
                "autoplay": true,
            "isLive": false,
            "rePlay": false,
            "playsinline": true,
            "controlBarVisibility": "hover",
            "useH5Prism": true,
components: [
{
width: '100%', //容器的大小
height: '100%', //容器的大小
"qualitySort": "asc",
"cover": "",
"autoplay": true,
"isLive": false,
"rePlay": false,
"playsinline": true,
"controlBarVisibility": "hover",
"useH5Prism": true,
components: [{
name: 'adComponent',
type: fullScreenButtonComponent,
args: [
@@ -598,7 +693,7 @@
align: "tl",
x: 10,
y: 7
},
},
{
name: "prism-speed-selector",
align: "tr",
@@ -616,7 +711,7 @@
]
}
if (this.videoData.type == 1) {
if (this.videoData.m3u8Url == null || this.videoData.m3u8Url == '') {
console.log('这是私有加密的视频');
@@ -627,7 +722,7 @@
...playerOptions,
"vid": this.videoData
.videoId, // 必选参数,可以通过点播控制台(路径:媒资库>音/视频查询。示例1e067a2831b641db90d570b6480f****。
"playauth": this.videoData.playAuth, // 必选参数参数值可通过调用GetVideoPlayAuth接口获取。
"encryptType": 1, // 必选参数当播放私有加密流时需要设置本参数值为1。其它情况无需设置。
"playConfig": {
@@ -635,14 +730,14 @@
}
}
console.log('这是私有加密的视频');
}
}
} else if (this.videoData.m3u8Url != null || this.videoData.m3u8Url != '') {
playerOptions = {
...playerOptions,
source: this.videoData.m3u8Url,
source: this.videoData.m3u8Url,
// "playConfig": {"EncryptType": "HLSEncryption"}
}
console.log('这是标准加密的视频');
console.log('这是标准加密的视频', this.videoData.id, this.videoData.m3u8Url);
}
} else {
@@ -651,44 +746,75 @@
source: this.videoData.videoUrl
}
console.log('这是没有加密的视频');
}
}
var player = new Aliplayer(playerOptions, function(player) {});
this.player = player;
console.log('是否拿到第一次初始值呢', this.platform, typeof this.firstTime, this.firstTime)
myplayer = player;
// console.log('myplayer------------',myplayer.loadByUrl('https://www.w3schools.com/html/movie.mp4'));
// console.log('是否拿到第一次初始值呢', this.platform, typeof this.firstTime, this.firstTime)
player.on('ready', function() {
console.log('播放器准备就绪,开始播放');
player.play()
$('.videoContent9').click()
})
player.on('play', function() {
console.log('开始播放------');
$('.videoContent7').click()
if(pauseTime > 0){
player.seek(pauseTime);
}
})
player.one('canplay', function() {
console.log('这是ios数据缓冲初次设置播放位置判断',videoData)
// console.log('这是ios数据缓冲初次设置播放位置判断', videoData)
// player.seek(20);
player.seek(videoData.firstTime);
})
this.player.on('playing', function() {
console.log('正在播放')
// if(ReplayVideoFlag){
// player.seek(0);
// }else{
var videoDurationTimes = parseInt(player.getDuration())
// var firstTime = parseInt(player.getCurrentTime())
console.log('视频总长度',parseInt(player.getDuration()),parseInt(player.getCurrentTime()));
if(videoData.firstTime < videoDurationTimes){
player.seek(videoData.firstTime);
}else{
player.seek(0);
}
//}
})
this.player.on('timeupdate', function() {
myplayer.on('playing', function() {
console.log('正在播放...')
})
myplayer.on('timeupdate', function() {
let that = this
var _time = parseInt(player.getCurrentTime())
curStatus = player.getStatus()
// console.log('timeupdatetimeupdate...',curStatus);
if(_seconds != _time){
if (_seconds != _time) {
_seconds = _time
diff ++
if(diff % 60 === 0){
console.log('符合---------');
$('.videoContent4').click()
diff = 0
}
$('.videoContent1').click()
diff++
if (diff % 60 === 0) {
console.log('符合---------');
$('.videoContent4').click()
diff = 0
}
$('.videoContent1').click()
}
})
this.player.on('ended', function() {
console.log('播放完毕');
})
myplayer.on('ended', function() {
console.log('播放完毕');
$('.videoContent2').click()
$('.videoContent6').click()
})
player.on('pause', function() {
pauseTime = parseInt(player.getCurrentTime())
player.pause(true)
console.log('触发暂停', pauseTime)
})
this.player.on('error', function() {
myplayer.on('error', function() {
console.log('播放出错')
$('.videoContent5').click()
})
@@ -719,19 +845,18 @@
});
},
receiveScreenType(newValue) {
},
receiveScreenType(newValue) {},
async receiveIsfresh(newValue) {
console.log('是否走了刷新销毁方法:', this.player)
if (this.player) {
console.log('是否走了刷新销毁方法:', myplayer)
if (myplayer) {
// clearInterval(this.$store.state.videoTimer)
// await this.setVideoTime();
this.player.dispose();
myplayer.dispose();
}
},
async receiveplatform(newValue) {
},
async receiveIsChange(newValue) {
if (this.isChange) {
@@ -747,14 +872,32 @@
receiveMsg(newValue, oldValue, ownerVm, vm) {
//数据变化
videoData = newValue
if (videoData) {
return
console.log('切换后的播放数据videoData',videoData.type);
if (videoData.type == 1) {
if (videoData.m3u8Url != '' && videoData.m3u8Url != null) {
// myplayer.source(videoData.m3u8Url)
myplayer.loadByUrl(videoData.m3u8Url)
console.log('切换走了吗m3u8');
} else {
myplayer.replayByVidAndPlayAuth(videoData.videoId, videoData.playAuth)
console.log('切换走了吗?私有加密');
}
} else {
myplayer.loadByUrl(videoData.videoUrl)
console.log('切换常规视频');
}
}
// console.log('可能是切换视频', videoData, );
},
receiveWinWidth(newValue, oldValue, ownerVm, vm) {
//数据变化
console.log('newValue', newValue)
console.log('newValue', newValue)
},
receiveWinHeight(newValue, oldValue, ownerVm, vm) {
//数据变化
console.log('newValue', newValue)
console.log('newValue', newValue)
},
// 检测是否传入播放参数
checkValue() {
@@ -764,7 +907,7 @@
this.checkValue();
}, 1000);
} else {
console.log('这是这只只是594:', this.firstTime, this.videoData)
// console.log('这是这只只是594:', this.firstTime, this.videoData)
this.getLive();
}
},
@@ -794,11 +937,36 @@
document.body.appendChild(l_tag);
});
},
}
}
</script>
<style>
.cancelNext{display: inline-block; margin-right: 20rpx;
border-radius: 10rpx; margin-top: 10rpx;
padding: 10rpx 20rpx !important; background-color: #fff !important;
color: #000; text-align: center; line-height: 50rpx;}
/* .cancelNext:last-child{margin-left: 10rpx;} */
.nextText{}
.showCountDownd {
box-sizing: border-box;
height: 100%; width: 100%; background-color: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content:flex-end;
color: #fff;
font-size: 38rpx;
text-align: center;
position: absolute;
top: 0; right: 10rpx;
z-index: 4;
text{
}
}
.container {
width: 100vw;
height: auto;