修改视频播放页播放逻辑处理

master
于肖磊 2025-09-18 17:39:50 +08:00
parent 1700945b2e
commit bba13ddefe
2 changed files with 115 additions and 18 deletions

View File

@ -1,6 +1,6 @@
<template>
<view class="content">
<swiper class="swiper-container" :style="swiperStyle" :vertical="true" @change="handleSwiperChange" :current="current_index">
<swiper class="swiper-container" :style="swiperStyle" :vertical="true" @change="handleSwiperChange" :current="current_index" :circular="close_circular ? false : true">
<swiper-item v-for="(video, index) in display_video_list" :key="video.id">
<view class="video-container" @tap="toggle_play_pause">
@ -120,6 +120,8 @@
comment_start_y: 0, //
comment_current_y: 0, //
move_distance: 0,
current_video_id: '1', // ID
is_slide_start: false,
};
},
computed: {
@ -129,18 +131,79 @@
commentContentStyle() {
return this.show_comment_modal ? `transform: translateY(3px); height: calc(70% - ${this.move_distance}px);` : `transform: translateY(0); height: 70%;`
},
current_video_index() {
return this.videoData.findIndex(item => item.id === this.current_video_id);
},
//
close_circular() {
return this.videoData[0].id == this.current_video_id || this.videoData[this.videoData.length - 1].id == this.current_video_id;
}
},
onLoad() {
//
this.init_display_data();
},
onReady() {
this.videoData.forEach((item, index) => {
this.video_contexts[index] = uni.createVideoContext(`video_${index}`, this);
});
setTimeout(() => {
if (this.video_contexts[0]) {
if (this.video_contexts[0]) { // 0
this.video_contexts[0].play();
}
}, 200);
},
methods: {
//
init_display_data() {
this.current_video_id = this.videoData[0].id;
this.display_video_list = [
this.videoData[0], //
this.videoData[this.current_video_index + 1 ], //
this.videoData[this.current_video_index + 2 ] //
];
},
//
update_display_data() {
console.log(this.current_index);
console.log('更新显示数据', this.current_video_index);
let list = [];
// 0
if (this.current_index == 0) {
list = [
this.videoData[this.current_video_index],
this.videoData[this.current_video_index + 1],
this.videoData[this.current_video_index + 2]
];
} else if (this.current_index == 1) { // 1
list = [
this.videoData[this.current_video_index - 1],
this.videoData[this.current_video_index],
this.videoData[this.current_video_index + 1]
];
} else {
list = [
this.videoData[this.current_video_index + 1],
this.videoData[this.current_video_index - 1],
this.videoData[this.current_video_index],
];
}
console.log('更新显示数据', list);
this.setData({
display_video_list: list
})
},
//
preload_adjacent_data() {
//
console.log('预加载数据当前视频ID:', this.current_video_id);
},
handleSwiperChange(event) {
const { current } = event.detail;
@ -154,22 +217,56 @@
this.current_video_progress = 0;
this.current_video_duration = 0;
this.is_seeking = false;
// ID
this.current_video_id = this.display_video_list[current].id;
//
if (this.current_video_index == 0 && this.is_slide_start) {
this.$nextTick(() => {
const list = [
this.videoData[this.current_video_index],
this.videoData[this.current_video_index + 1],
this.videoData[this.current_video_index + 2]
];
this.setData({
is_slide_start: false,
current_index: 0,
display_video_list: list
})
})
} else if (this.current_video_index == this.videoData.length - 1) {
this.$nextTick(() => {
const list = [
this.videoData[this.current_video_index - 2],
this.videoData[this.current_video_index - 1],
this.videoData[this.current_video_index],
];
this.setData({
current_index: this.current_video_index,
display_video_list: list
})
})
} else {
// index
this.update_display_data();
}
setTimeout(() => {
if (this.video_contexts[this.current_index]) {
this.video_contexts[this.current_index].play();
this.is_slide_start = true;
//
if (this.video_contexts[current]) {
this.video_contexts[current].play();
}
}, 250);
}, 100);
},
toggle_play_pause() {
if (!this.video_contexts[this.current_index]) return;
if (!this.video_contexts[this.current_index]) return; // 1
this.paused = !this.paused;
if (this.paused) {
this.video_contexts[this.current_index].pause();
this.video_contexts[this.current_index].pause(); //
} else {
this.video_contexts[this.current_index].play();
this.video_contexts[this.current_index].play(); //
}
},
@ -268,8 +365,8 @@
handle_slider_change(e) {
const seek_time = e.detail.value;
if (this.video_contexts[this.current_index]) {
this.video_contexts[this.current_index].seek(seek_time);
if (this.video_contexts[1]) { //
this.video_contexts[1].seek(seek_time);
this.current_video_progress = seek_time;
}
setTimeout(() => {

View File

@ -8,7 +8,7 @@
"videoUrl": "http://8.146.211.120:8080/upload/douyin/e6fddef474951cc15f5aeb99219b4a91.mp4",
"posterUrl": "http://8.146.211.120:8080/upload/notes/ce5082f76cc9bd82a2bd97ce8b45ea32.jpg",
"userHead": "http://8.146.211.120:8080/upload/notes/8f5ebdab07f9fb592895bd3f0f230ea9.jpg",
"commentObj": {
"comment_obj": {
"count": 2,
"list": [
{
@ -37,7 +37,7 @@
"videoUrl": "http://8.146.211.120:8080/upload/douyin/0985b0f3879c7dca9f6c1c6fb59d4a79.mp4",
"posterUrl": "http://8.146.211.120:8080/upload/background/dab42015a50709f68a75306a572aaaca.jpg",
"userHead": "http://8.146.211.120:8080/upload/background/735feb718119ea7e5f206be7b4410dd6.jpg",
"commentObj": {
"comment_obj": {
"count": 0,
"list": []
}
@ -51,7 +51,7 @@
"videoUrl": "http://8.146.211.120:8080/upload/douyin/a4832a9a37b44196b49c646db148ec65.mp4",
"posterUrl": "http://8.146.211.120:8080/upload/background/8049cff58c46adf4164907fb3abe63a8.jpg",
"userHead": "http://8.146.211.120:8080/upload/notes/b11b2d741a5132b0d733a9861c9f6c7c.jpg",
"commentObj": {
"comment_obj": {
"count": 1,
"list": [
{
@ -73,7 +73,7 @@
"videoUrl": "http://shopxo.com/static/upload/video/goods/2023/08/17/1692267725487534.mp4",
"posterUrl": "http://8.146.211.120:8080/upload/background/8049cff58c46adf4164907fb3abe63a8.jpg",
"userHead": "http://8.146.211.120:8080/upload/notes/b11b2d741a5132b0d733a9861c9f6c7c.jpg",
"commentObj": {
"comment_obj": {
"count": 1,
"list": [
{
@ -95,7 +95,7 @@
"videoUrl": "http://shopxo.com/static/upload/video/goods/2019/01/14/1547458876723311.mp4",
"posterUrl": "",
"userHead": "",
"commentObj": {
"comment_obj": {
"count": 1,
"list": [
{
@ -117,7 +117,7 @@
"videoUrl": "http://shopxo.com/static/upload/video/goods/2023/08/17/1692267246598639.mp4",
"posterUrl": "",
"userHead": "",
"commentObj": {
"comment_obj": {
"count": 1,
"list": [
{
@ -139,7 +139,7 @@
"videoUrl": "http://8.146.211.120:8080/upload/douyin/a4832a9a37b44196b49c646db148ec65.mp4",
"posterUrl": "",
"userHead": "",
"commentObj": {
"comment_obj": {
"count": 1,
"list": [
{
@ -161,7 +161,7 @@
"videoUrl": "http://shopxo.com/static/upload/video/goods/2023/08/17/1692267725487534.mp4",
"posterUrl": "",
"userHead": "",
"commentObj": {
"comment_obj": {
"count": 1,
"list": [
{