mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-08 10:26:45 +08:00
视频组件
This commit is contained in:
@@ -3,20 +3,19 @@
|
|||||||
<video id="myVideo" style="width: 100%;"
|
<video id="myVideo" style="width: 100%;"
|
||||||
:src="url"
|
:src="url"
|
||||||
:controls="false"
|
:controls="false"
|
||||||
:initial-time="videoPlayingTime"
|
:enable-play-gesture="true"
|
||||||
@error="videoErrorCallback"
|
:initial-time="initPlayingTime"
|
||||||
@touchend="onPlayerTouchend"
|
@error="onError"
|
||||||
@play="onPlayerPlay"
|
@touchend="onTouchend"
|
||||||
@pause="onPlayerPause"
|
@play="onPlay"
|
||||||
@ended="onPlayerEnded"
|
@pause="onPause"
|
||||||
@timeupdate="onPlayerPlaying"
|
@ended="onEnded"
|
||||||
|
@timeupdate="onPlaying"
|
||||||
@fullscreenchange="onFullScreen"
|
@fullscreenchange="onFullScreen"
|
||||||
@loadeddata="onPalyerLoad"
|
@loadeddata="onLoad"
|
||||||
@loadedmetadata="onPlayerMetaLoad"
|
@loadedmetadata="onMetaLoad"
|
||||||
@controlstoggle="onPlayerControlsToggle"
|
@controlstoggle="onControlsToggle"
|
||||||
@dblclick="dbclickVideo"
|
></video>
|
||||||
>
|
|
||||||
</video>
|
|
||||||
<view v-if="contrlShow">
|
<view v-if="contrlShow">
|
||||||
<view class="process-container">
|
<view class="process-container">
|
||||||
<view class="controller-play">
|
<view class="controller-play">
|
||||||
@@ -24,7 +23,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="currtime">{{currtime}}</view>
|
<view class="currtime">{{currtime}}</view>
|
||||||
<view class='slider-container'>
|
<view class='slider-container'>
|
||||||
<slider @change="sliderChange" @changing="sliderChanging" step="1" :value="sliderValue" backgroundColor="#9f9587" activeColor="#d6d2cc" block-color="#FFFFFF" block-size="12"/>
|
<slider :disabled="!drag" @change="sliderChange" @changing="sliderChanging" step="1" :value="sliderValue" backgroundColor="#9f9587" activeColor="#d6d2cc" block-color="#FFFFFF" block-size="12"/>
|
||||||
</view>
|
</view>
|
||||||
<view class="druationTime">{{druationTime}}</view>
|
<view class="druationTime">{{druationTime}}</view>
|
||||||
<view class="druationTime">
|
<view class="druationTime">
|
||||||
@@ -60,7 +59,15 @@
|
|||||||
type: String,
|
type: String,
|
||||||
require: true
|
require: true
|
||||||
},
|
},
|
||||||
initTime:{//默认播放的位置,第几秒
|
name:{
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
drag:{
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
inittime:{//默认播放的位置,第几秒
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
},
|
},
|
||||||
@@ -73,13 +80,14 @@
|
|||||||
fullScreenFlag: false,//是否全屏
|
fullScreenFlag: false,//是否全屏
|
||||||
currtime:'00:00',//当前播放时间 字符串 计算后
|
currtime:'00:00',//当前播放时间 字符串 计算后
|
||||||
druationTime:'00:00',//总时间 字符串 计算后
|
druationTime:'00:00',//总时间 字符串 计算后
|
||||||
videoPlayingTime:0,//指定播放的时间位置
|
initPlayingTime:0,//指定播放的时间位置
|
||||||
sliderValue: 0, //控制进度条slider的值,
|
sliderValue: 0, //控制进度条slider的值,
|
||||||
updateState: false, //防止视频播放过程中导致的拖拽失效
|
updateState: true, //防止视频播放过程中导致的拖拽失效
|
||||||
playing:false,//是否在播放中
|
playing:false,//是否在播放中
|
||||||
curVideo:{
|
curVideo:{
|
||||||
duration:0
|
duration:0
|
||||||
},
|
},
|
||||||
|
touchNum:0,
|
||||||
speedListShow:false,
|
speedListShow:false,
|
||||||
speedList:["2.0", "1.5", "1.25", "1.0", "0.75", "0.5"],
|
speedList:["2.0", "1.5", "1.25", "1.0", "0.75", "0.5"],
|
||||||
videoSpeed: 1.0, // 当前倍速:
|
videoSpeed: 1.0, // 当前倍速:
|
||||||
@@ -88,30 +96,26 @@
|
|||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['userInfo']),
|
...mapGetters(['userInfo']),
|
||||||
},
|
},
|
||||||
created() {
|
watch:{
|
||||||
|
url(newVal,oldVal){
|
||||||
|
this.videoContext.pause();
|
||||||
|
this.playing=false;
|
||||||
|
},
|
||||||
|
inittime(newVal,oldVal){
|
||||||
|
this.initPlayingTime=newVal;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
this.initPlayingTime=this.inittime;
|
||||||
this.videoContext=uni.createVideoContext("myVideo", this);
|
this.videoContext=uni.createVideoContext("myVideo", this);
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
// 全屏+退出全屏
|
// 全屏+退出全屏
|
||||||
fullScreen(){
|
fullScreen(){
|
||||||
this.fullScreenFlag ? this.videoContext.exitFullScreen() : this.videoContext.requestFullScreen();
|
this.fullScreenFlag ? this.videoContext.exitFullScreen() : this.videoContext.requestFullScreen();
|
||||||
// this.fullScreenFlag ? this.bool=true : this.bool=false;
|
// this.fullScreenFlag ? this.bool=true : this.bool=false;
|
||||||
this.fullScreenFlag=!this.fullScreenFlag;
|
this.fullScreenFlag=!this.fullScreenFlag;
|
||||||
},
|
},
|
||||||
onFullScreen(e) {
|
|
||||||
this.fullScreenFlag ? this.videoContext.exitFullScreen() : this.videoContext.requestFullScreen();
|
|
||||||
// this.fullScreenFlag ? this.bool=true : this.bool=false;
|
|
||||||
this.fullScreenFlag=!this.fullScreenFlag;
|
|
||||||
},
|
|
||||||
|
|
||||||
videoErrorCallback(e){
|
|
||||||
console.log(e,'播放错误');
|
|
||||||
},
|
|
||||||
// 根据秒获取时间
|
// 根据秒获取时间
|
||||||
formatSeconds(a) {
|
formatSeconds(a) {
|
||||||
var hh = parseInt(a/3600);
|
var hh = parseInt(a/3600);
|
||||||
@@ -177,7 +181,6 @@
|
|||||||
this.druationTime = this.formatSeconds(duration);
|
this.druationTime = this.formatSeconds(duration);
|
||||||
this.currtime = this.formatSeconds(second);
|
this.currtime = this.formatSeconds(second);
|
||||||
}
|
}
|
||||||
else { }
|
|
||||||
},
|
},
|
||||||
clickVideo(){
|
clickVideo(){
|
||||||
// if(this.contrlShowTimeout!=null){
|
// if(this.contrlShowTimeout!=null){
|
||||||
@@ -185,59 +188,70 @@
|
|||||||
// }
|
// }
|
||||||
// this.contrlShow=!this.contrlShow;
|
// this.contrlShow=!this.contrlShow;
|
||||||
},
|
},
|
||||||
dblclickVideo(){
|
onFullScreen(e) {
|
||||||
console.log("双击了");
|
this.$emit('fullscreenchange',e);
|
||||||
|
//this.fullScreenFlag ? this.videoContext.exitFullScreen() : this.videoContext.requestFullScreen();
|
||||||
|
// this.fullScreenFlag ? this.bool=true : this.bool=false;
|
||||||
|
//this.fullScreenFlag=!this.fullScreenFlag;
|
||||||
},
|
},
|
||||||
onPlayerTouchend(e){
|
onError(e){
|
||||||
|
console.log(e,'播放错误');
|
||||||
|
this.$emit('error',e);
|
||||||
|
},
|
||||||
|
onTouchend(e){
|
||||||
// this.onPlayerPause()
|
// this.onPlayerPause()
|
||||||
this.touchNum ++
|
// this.touchNum ++
|
||||||
setTimeout(()=>{
|
// let $this=this;
|
||||||
if(this.touchNum == 1){
|
// setTimeout(()=>{
|
||||||
// console.log('单击')
|
// if($this.touchNum == 1){
|
||||||
}else if(this.touchNum >= 2){
|
// // console.log('单击')
|
||||||
if(this.isPlaying){
|
// }else if($this.touchNum >= 2){
|
||||||
this.onPlayerPause()
|
// if($this.playing){
|
||||||
} else {
|
// $this.onPause()
|
||||||
this.onPlayerPlay()
|
// } else {
|
||||||
}
|
// $this.onPlay()
|
||||||
}
|
// }
|
||||||
this.touchNum = 0
|
// }
|
||||||
},250)
|
// this.touchNum = 0
|
||||||
|
// },250)
|
||||||
},
|
},
|
||||||
onPlayerLoad(e){
|
onLoad(e){
|
||||||
this.contrlShow=false;
|
this.contrlShow=false;
|
||||||
|
this.$emit('loadeddata',e);
|
||||||
},
|
},
|
||||||
onPlayerMetaLoad(e){
|
onMetaLoad(e){
|
||||||
this.curVideo.duration=Number(e.detail.duration);
|
this.curVideo.duration=Number(e.detail.duration);
|
||||||
this.druationTime = this.formatSeconds(this.curVideo.duration);
|
this.druationTime = this.formatSeconds(this.curVideo.duration);
|
||||||
|
this.$emit('loadedmetadata',e);
|
||||||
},
|
},
|
||||||
onPlayerControlsToggle(e){
|
onControlsToggle(e){
|
||||||
console.log(e,"ControlsToggle");
|
console.log(e,"ControlsToggle");
|
||||||
},
|
},
|
||||||
// 开始
|
// 开始
|
||||||
onPlayerPlay(){
|
onPlay(){
|
||||||
this.videoContext.play();
|
this.videoContext.play();
|
||||||
this.playing=true;
|
this.playing=true;
|
||||||
this.contrlShow=true;
|
//this.contrlShow=true;
|
||||||
},
|
|
||||||
onPlayerPlaying(e){
|
|
||||||
this.playing=true;
|
|
||||||
this.updateState=true;
|
|
||||||
this.videoUpdate(e);
|
|
||||||
// let $this=this;
|
// let $this=this;
|
||||||
// if(this.contrlShow){
|
// if(this.contrlShow){
|
||||||
// this.contrlShowTimeout=window.setTimeout(function(){
|
// this.contrlShowTimeout=window.setTimeout(function(){
|
||||||
// $this.contrlShow=false;
|
// $this.contrlShow=false;
|
||||||
// },5000);
|
// },5000);
|
||||||
// }
|
// }
|
||||||
|
this.$emit('play')
|
||||||
},
|
},
|
||||||
// 暂停
|
onPlaying(e){
|
||||||
onPlayerPause() {
|
this.playing=true;
|
||||||
this.videoContext.pause(); //站厅播放
|
this.videoUpdate(e);
|
||||||
this.playing=false;
|
this.$emit('playing',e)
|
||||||
},
|
},
|
||||||
onPlayerEnded(){
|
onPause() {
|
||||||
this.playing=false;
|
this.playing=false;
|
||||||
|
this.$emit('pause')
|
||||||
|
},
|
||||||
|
onEnded(){
|
||||||
|
this.playing=false;
|
||||||
|
this.$emit('ended')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +273,7 @@
|
|||||||
color:#ffffff;
|
color:#ffffff;
|
||||||
left:0;
|
left:0;
|
||||||
right:0;
|
right:0;
|
||||||
z-index:99;
|
z-index:9999;
|
||||||
display:flex;
|
display:flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background:rgba(59, 57, 57, 0.2);
|
background:rgba(59, 57, 57, 0.2);
|
||||||
|
|||||||
@@ -4,11 +4,13 @@
|
|||||||
<video-player
|
<video-player
|
||||||
:url="fileUrl"
|
:url="fileUrl"
|
||||||
:name="title"
|
:name="title"
|
||||||
|
:inittime="initTime"
|
||||||
:drag="true"
|
:drag="true"
|
||||||
@onPlay="videoPlay"
|
@play="videoPlay"
|
||||||
@onPause="videoPause"
|
@pause="videoPause"
|
||||||
@onPlaying="videoPlaying"
|
@playing="videoPlaying"
|
||||||
@onEnded="videoEnd">
|
@ended="videoEnd"
|
||||||
|
@fullscreenchange="videoScreen">
|
||||||
</video-player>
|
</video-player>
|
||||||
</view>
|
</view>
|
||||||
<!-- <view style="padding-top: 30px;display: flex;justify-content: center;">
|
<!-- <view style="padding-top: 30px;display: flex;justify-content: center;">
|
||||||
@@ -22,6 +24,7 @@
|
|||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
fileUrl:'/static/temp/test.mp4',
|
fileUrl:'/static/temp/test.mp4',
|
||||||
|
initTime:20,
|
||||||
title:'测试播放',
|
title:'测试播放',
|
||||||
author:'',
|
author:'',
|
||||||
}
|
}
|
||||||
@@ -51,6 +54,9 @@
|
|||||||
},
|
},
|
||||||
videoPlaying(){
|
videoPlaying(){
|
||||||
console.log('videoPlaying');
|
console.log('videoPlaying');
|
||||||
|
},
|
||||||
|
videoScreen(e){
|
||||||
|
console.log('全屏',e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user