修复视频播放控制条兼容问题,修改部分代码逻辑,去除部分打印代码
This commit is contained in:
parent
1550bcd19c
commit
91e8d66941
|
|
@ -1,25 +1,31 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="item" @appear="appear" @disappear="disappear" @click.stop :style="{height:height+'px'}" :key="index">
|
<view class="item" @appear="appear" @disappear="disappear" @click.stop :style="{height:height+'px'}" :key="index">
|
||||||
|
|
||||||
|
<!-- :controls="showControls" -->
|
||||||
<video class="u-flex-1 video" :show-fullscreen-btn="false" @controlstoggle="controlstoggles" v-if="showVideo"
|
<video class=" video" :show-fullscreen-btn="false" @controlstoggle="controlstoggles" v-if="showVideo"
|
||||||
play-btn-position="center" :show-center-play-btn="false" :show-play-btn="false" :controls="!isPlying"
|
play-btn-position="bottom" :show-center-play-btn="true" :show-play-btn="true" @click.stop="videoClick()"
|
||||||
@click.stop="videoClick()" @loadedmetadata="loadedmetadata" @timeupdate="timeupdate" @waiting="waiting()"
|
@loadedmetadata="loadedmetadata" @timeupdate="timeupdate" @waiting="waiting()" object-fit="cover"
|
||||||
object-fit="cover" @pause="onpause" @play="videoPlay('myVideo'+item.courseDetailsId,item.courseDetailsId)"
|
@loadeddata="waiting()" @pause="onpause"
|
||||||
:play-strategy="2" :show-loading="true" codec="software" :muted="false" :loop="loop"
|
@play="videoPlay('myVideo'+item.courseDetailsId,item.courseDetailsId)" :play-strategy="2"
|
||||||
:enable-progress-gesture="false" :poster="item.titleImg" :ref="'myVideo'+item.courseDetailsId"
|
:show-loading="true" codec="software" :muted="false" :loop="loop" :enable-progress-gesture="false"
|
||||||
:autoplay="autoplay" @ended="ended" :id="'myVideo'+item.courseDetailsId" :src="item.videoUrl"></video>
|
:poster="item.titleImg" :ref="'myVideo'+item.courseDetailsId" :autoplay="autoplay" @ended="ended"
|
||||||
|
:id="'myVideo'+item.courseDetailsId" :src="item.videoUrl"></video>
|
||||||
|
|
||||||
|
|
||||||
<image class="poster" v-else @click.stop="posterClick" :src="item.titleImg" mode="aspectFill">
|
<image class="poster" v-else @click.stop="posterClick" :src="item.titleImg" mode="aspectFill">
|
||||||
</image>
|
</image>
|
||||||
|
<!-- #ifdef APP -->
|
||||||
|
<view class="control-play-cover" v-if="showControls&&isIos" @click="playCoverClick()">
|
||||||
|
</view>
|
||||||
|
<!-- #endif -->
|
||||||
|
|
||||||
<!-- <view class="progress" v-if="showVideo&&!isPlying" @click.stop>
|
<!-- <view class="progress" v-if="showVideo&&!isPlying" @click.stop>
|
||||||
<progress-vue @touchstart="progressScroll" @touchend="progressScrollEnd"></progress-vue>
|
<progress-vue @touchstart="progressScroll" @touchend="progressScrollEnd"></progress-vue>
|
||||||
</view> -->
|
</view> -->
|
||||||
<view class="play-icon" v-if="videoIsLoadedmetadata&&showVideo&&!isPlying" @click.stop="videoClick()"
|
|
||||||
:style="playStyle">
|
<!-- <view class="play-icon" v-if="showVideo&&!isPlying" @click.stop="playIconClick()" :style="playStyle">
|
||||||
<image class="icon" src="@/static/images/play.png" mode=""></image>
|
<image class="icon" src="@/static/images/play.png" mode=""></image>
|
||||||
</view>
|
</view> -->
|
||||||
|
|
||||||
<view class="info" v-if="!isCommand" :style="infoStyle">
|
<view class="info" v-if="!isCommand" :style="infoStyle">
|
||||||
<text class="color-fff" v-if="item.courseDetailsName">{{item.courseDetailsName}}</text>
|
<text class="color-fff" v-if="item.courseDetailsName">{{item.courseDetailsName}}</text>
|
||||||
|
|
@ -63,6 +69,9 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import * as Api from '@/api/video/index.js'
|
import * as Api from '@/api/video/index.js'
|
||||||
|
// #ifdef APP
|
||||||
|
const domModule = uni.requireNativePlugin('dom')
|
||||||
|
// #endif
|
||||||
import progressVue from './progress.vue'
|
import progressVue from './progress.vue'
|
||||||
import {
|
import {
|
||||||
computed,
|
computed,
|
||||||
|
|
@ -79,6 +88,10 @@
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
isIos:{
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
isAndriod: {
|
isAndriod: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
|
@ -153,12 +166,21 @@
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 1
|
default: 1
|
||||||
},
|
},
|
||||||
showControls: {
|
showAndriod: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let isWaiting = ref(true)
|
||||||
|
|
||||||
|
function waiting() {
|
||||||
|
console.log('waiting');
|
||||||
|
isWaiting.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
let showControls = ref(props.showAndriod?false:true)
|
||||||
|
|
||||||
let playPercent = ref(0)
|
let playPercent = ref(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -184,9 +206,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function controlstoggles(e) {
|
function controlstoggles(e) {
|
||||||
console.log('controlstoggles');
|
showControls.value = e.detail.show
|
||||||
console.log(e);
|
emits('controlstoggles', e)
|
||||||
// emits('controlstoggles', e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toDetail() {
|
function toDetail() {
|
||||||
|
|
@ -196,13 +217,11 @@
|
||||||
emits('toDetail')
|
emits('toDetail')
|
||||||
}
|
}
|
||||||
|
|
||||||
function waiting() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let videoIsLoadedmetadata = ref(false)
|
let videoIsLoadedmetadata = ref(false)
|
||||||
|
|
||||||
function loadedmetadata() {
|
function loadedmetadata() {
|
||||||
|
console.log('loadedmetadata');
|
||||||
videoIsLoadedmetadata.value = true
|
videoIsLoadedmetadata.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,8 +249,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeupdate(e) {
|
function timeupdate(e) {
|
||||||
console.log('timeupdate');
|
|
||||||
console.log(e);
|
|
||||||
playPercent.value = e.detail.currentTime * 100 / e.detail.duration
|
playPercent.value = e.detail.currentTime * 100 / e.detail.duration
|
||||||
//隐藏loding
|
//隐藏loding
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
|
|
@ -246,37 +263,45 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let videoBar = null
|
||||||
|
|
||||||
|
|
||||||
|
let watingTimer = null
|
||||||
|
|
||||||
function videoPlay() {
|
function videoPlay() {
|
||||||
if (isFirstPlay && !isPlayFinish) {
|
if (isFirstPlay && !isPlayFinish) {
|
||||||
sendPlayStatus('start')
|
sendPlayStatus('start')
|
||||||
}
|
}
|
||||||
|
|
||||||
isFirstPlay = false
|
isFirstPlay = false
|
||||||
setTimeout(() => {
|
isPlying.value = true
|
||||||
isPlying.value = true
|
clearTimeout(watingTimer)
|
||||||
}, 100)
|
watingTimer = setTimeout(() => {
|
||||||
|
isWaiting.value = false
|
||||||
|
}, 1000)
|
||||||
|
// showControls.value = false
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
emits('controlstoggles', {
|
videoBar = videoBar ? videoBar : document.querySelector('.uni-video-bar');
|
||||||
detail: {
|
videoBar.style.cssText = 'display:none;';
|
||||||
show: false
|
// #endif
|
||||||
}
|
|
||||||
})
|
// #ifdef APP
|
||||||
|
if (!props.showAndriod) {}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onpause() {
|
function onpause() {
|
||||||
setTimeout(() => {
|
isPlying.value = false
|
||||||
isPlying.value = false
|
// showControls.value = true
|
||||||
}, 100)
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
emits('controlstoggles', {
|
videoBar = videoBar ? videoBar : document.querySelector('.uni-video-bar');
|
||||||
detail: {
|
videoBar.style.cssText = '';
|
||||||
show: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -301,8 +326,36 @@
|
||||||
emits('popupShow', key)
|
emits('popupShow', key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function playCoverClick() {
|
||||||
|
console.log('playCoverClick');
|
||||||
|
if (video) {
|
||||||
|
if (isPlying.value) {
|
||||||
|
video.pause()
|
||||||
|
} else {
|
||||||
|
video.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function playIconClick(){
|
||||||
|
if (video) {
|
||||||
|
if (isPlying.value) {
|
||||||
|
video.pause()
|
||||||
|
} else {
|
||||||
|
video.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function videoClick() {
|
function videoClick() {
|
||||||
console.log('videoClick');
|
console.log('videoClick');
|
||||||
|
// #ifdef APP
|
||||||
|
// 兼容ios控制条和信息展示不同步
|
||||||
|
if (isPlying.value&&showControls.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
if (video) {
|
if (video) {
|
||||||
if (isPlying.value) {
|
if (isPlying.value) {
|
||||||
video.pause()
|
video.pause()
|
||||||
|
|
@ -335,8 +388,6 @@
|
||||||
}
|
}
|
||||||
const showVideo = computed(() => {
|
const showVideo = computed(() => {
|
||||||
if (props.isAndriod) {
|
if (props.isAndriod) {
|
||||||
console.log('props.nowIndex === props.index ');
|
|
||||||
console.log(props.nowIndex, props.index);
|
|
||||||
return (props.nowIndex === props.index && props.item.videoUrl) ? true : false
|
return (props.nowIndex === props.index && props.item.videoUrl) ? true : false
|
||||||
} else {
|
} else {
|
||||||
return props.current === props.index && props.item.videoUrl
|
return props.current === props.index && props.item.videoUrl
|
||||||
|
|
@ -353,7 +404,6 @@
|
||||||
video = uni.createVideoContext('myVideo' + props.item.courseDetailsId)
|
video = uni.createVideoContext('myVideo' + props.item.courseDetailsId)
|
||||||
video.playbackRate(props.playSpeeds)
|
video.playbackRate(props.playSpeeds)
|
||||||
video.play()
|
video.play()
|
||||||
console.log('init play');
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('------')
|
console.error('------')
|
||||||
|
|
@ -367,7 +417,6 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
watch(() => showVideo.value, (newval) => {
|
watch(() => showVideo.value, (newval) => {
|
||||||
console.log('showVideo change:' + newval);
|
|
||||||
if (newval) {
|
if (newval) {
|
||||||
isFirstPlay = true
|
isFirstPlay = true
|
||||||
isPlayFinish = false
|
isPlayFinish = false
|
||||||
|
|
@ -400,15 +449,29 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const infoStyle = computed(() => {
|
const infoStyle = computed(() => {
|
||||||
|
// #ifdef H5
|
||||||
return {
|
return {
|
||||||
transform: `translateX(${(!isPlying.value||!props.item.videoUrl)?0:'-750rpx'})`
|
transform: `translateX(${(!isPlying.value||!props.item.videoUrl)?0:'-750rpx'})`
|
||||||
}
|
}
|
||||||
|
// #endif
|
||||||
|
return {
|
||||||
|
transform: `translateX(${(showControls.value||!props.item.videoUrl)?0:'-750rpx'})`
|
||||||
|
}
|
||||||
|
// return {
|
||||||
|
// transform: `translateX(${(!isPlying.value||!props.item.videoUrl)?0:'-750rpx'})`
|
||||||
|
// }
|
||||||
})
|
})
|
||||||
|
|
||||||
const rightStyle = computed(() => {
|
const rightStyle = computed(() => {
|
||||||
|
// #ifdef H5
|
||||||
return {
|
return {
|
||||||
transform: `translateX(${(!isPlying.value||!props.item.videoUrl)?'0':60}px)`
|
transform: `translateX(${(!isPlying.value||!props.item.videoUrl)?'0':60}px)`
|
||||||
}
|
}
|
||||||
|
// #endif
|
||||||
|
return {
|
||||||
|
transform: `translateX(${(showControls.value||!props.item.videoUrl)?'0':60}px)`
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -419,6 +482,12 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 假设控制条的类名为 uni-video-controls */
|
||||||
|
.uni-video-controls {
|
||||||
|
transition: none !important;
|
||||||
|
-webkit-transition: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
.box {
|
.box {
|
||||||
/* #ifdef H5 */
|
/* #ifdef H5 */
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
@ -579,4 +648,15 @@
|
||||||
width: 56rpx;
|
width: 56rpx;
|
||||||
height: 56rpx;
|
height: 56rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.control-play-cover {
|
||||||
|
position: absolute;
|
||||||
|
left: 10px;
|
||||||
|
bottom: 0;
|
||||||
|
width: 38px;
|
||||||
|
height: 44px;
|
||||||
|
// background-color: red;
|
||||||
|
background-color: transparent;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
@ -4,7 +4,11 @@
|
||||||
<cell v-for="(item,index) in list" :key="item.courseDetailsId" :ref="setRefList(index)">
|
<cell v-for="(item,index) in list" :key="item.courseDetailsId" :ref="setRefList(index)">
|
||||||
<view class="swipers-items" :style="boxStyle" @longpress="popupShow('speed')">
|
<view class="swipers-items" :style="boxStyle" @longpress="popupShow('speed')">
|
||||||
<list-item-vue :total="list.length" :item="item" :current="current" :isCollect="isCollect"
|
<list-item-vue :total="list.length" :item="item" :current="current" :isCollect="isCollect"
|
||||||
:isAndriod="isAndriod" :isTabbar="isTabbar" @playStatusChange="playStatusChange" :height="wHeight"
|
:isAndriod="isAndriod"
|
||||||
|
:showAndriod="showAndriod"
|
||||||
|
:isIos="isIos"
|
||||||
|
:isH5="isH5"
|
||||||
|
:isTabbar="isTabbar" @playStatusChange="playStatusChange" :height="wHeight"
|
||||||
:isCommand="isCommand" :showControls="control.showControls" @toDetail="toDetail(item,index)"
|
:isCommand="isCommand" :showControls="control.showControls" @toDetail="toDetail(item,index)"
|
||||||
@itemMounted="itemMounted" @controlstoggles="controlstoggles" :index="index" :instance="instance"
|
@itemMounted="itemMounted" @controlstoggles="controlstoggles" :index="index" :instance="instance"
|
||||||
:nowIndex="nowIndex" @appear="appear($event,item,index)" :playSpeeds="playSpeeds"
|
:nowIndex="nowIndex" @appear="appear($event,item,index)" :playSpeeds="playSpeeds"
|
||||||
|
|
@ -24,7 +28,11 @@
|
||||||
@transition="transition" :indicator-dots="false" :autoplay="false" :interval="0" :duration="200">
|
@transition="transition" :indicator-dots="false" :autoplay="false" :interval="0" :duration="200">
|
||||||
<swiper-item v-for="(item,index) in videoList" :key="index">
|
<swiper-item v-for="(item,index) in videoList" :key="index">
|
||||||
<list-item-vue :total="list.length" :item="item" :isCommand="isCommand" :height="wHeight"
|
<list-item-vue :total="list.length" :item="item" :isCommand="isCommand" :height="wHeight"
|
||||||
:isAndriod="isAndriod" :isTabbar="isTabbar" @playStatusChange="playStatusChange"
|
:isAndriod="isAndriod"
|
||||||
|
:showAndriod="showAndriod"
|
||||||
|
:isIos="isIos"
|
||||||
|
:isH5="isH5"
|
||||||
|
:isTabbar="isTabbar" @playStatusChange="playStatusChange"
|
||||||
:showControls="control.showControls" :current="current" :isCollect="isCollect"
|
:showControls="control.showControls" :current="current" :isCollect="isCollect"
|
||||||
@toDetail="toDetail(item,index)" @controlstoggles="controlstoggles" :playSpeeds="playSpeeds"
|
@toDetail="toDetail(item,index)" @controlstoggles="controlstoggles" :playSpeeds="playSpeeds"
|
||||||
:index="index" :nowIndex="nowIndex" @dianzanClick="dianzanClick(item,index)" @share="share(item)"
|
:index="index" :nowIndex="nowIndex" @dianzanClick="dianzanClick(item,index)" @share="share(item)"
|
||||||
|
|
@ -346,7 +354,6 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
function controlstoggles(e) {
|
function controlstoggles(e) {
|
||||||
console.log('controlstoggles');
|
|
||||||
control.showControls = e.detail.show
|
control.showControls = e.detail.show
|
||||||
control.showBack = control.showControls
|
control.showBack = control.showControls
|
||||||
}
|
}
|
||||||
|
|
@ -477,7 +484,6 @@
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
$mountedComponents[index] = true
|
$mountedComponents[index] = true
|
||||||
}
|
}
|
||||||
console.log('appear:' + index);
|
|
||||||
if (!initing) {
|
if (!initing) {
|
||||||
cacheIndex = index
|
cacheIndex = index
|
||||||
}
|
}
|
||||||
|
|
@ -612,10 +618,8 @@
|
||||||
|
|
||||||
function goListPosition(index) {
|
function goListPosition(index) {
|
||||||
clearTimeout(positonmer)
|
clearTimeout(positonmer)
|
||||||
console.log('goListPosition:' + index)
|
|
||||||
const el = refList.value[index]
|
const el = refList.value[index]
|
||||||
if (initing) {
|
if (initing) {
|
||||||
console.log($mountedComponents);
|
|
||||||
if (!$mountedComponents[index]) {
|
if (!$mountedComponents[index]) {
|
||||||
positonmer = setTimeout(() => {
|
positonmer = setTimeout(() => {
|
||||||
goListPosition(index)
|
goListPosition(index)
|
||||||
|
|
@ -850,7 +854,6 @@
|
||||||
const lastIndex = listLen - 1
|
const lastIndex = listLen - 1
|
||||||
const index = props.list.findIndex(v => v.courseDetailsId == item.courseDetailsId)
|
const index = props.list.findIndex(v => v.courseDetailsId == item.courseDetailsId)
|
||||||
nowIndex.value = index
|
nowIndex.value = index
|
||||||
console.log('setVideoList nowIndex' + index);
|
|
||||||
let position = ''
|
let position = ''
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
position = 'start'
|
position = 'start'
|
||||||
|
|
@ -885,7 +888,6 @@
|
||||||
videoList.value = [props.list[index + 1], props.list[index - 1], item]
|
videoList.value = [props.list[index + 1], props.list[index - 1], item]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(videoList.value, 'debug');
|
|
||||||
if (!item.videoUrl) {
|
if (!item.videoUrl) {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,6 @@
|
||||||
}
|
}
|
||||||
onLoad((opt) => {
|
onLoad((opt) => {
|
||||||
Object.assign(options, opt)
|
Object.assign(options, opt)
|
||||||
console.log(options);
|
|
||||||
init()
|
init()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue