修改视频播放器逻辑

master
于肖磊 2026-02-11 10:36:17 +08:00
parent 74a6beb665
commit 80a20f365d
2 changed files with 35 additions and 26 deletions

View File

@ -15,6 +15,7 @@
</view>
</view>
</view>
<!-- 视频列表 -->
<swiper class="swiper-container" :key="'top-or-buttom-' + swiper_key" :style="swiperStyle" :duration="500" :vertical="true" :circular="close_circular ? false : true" :skip-hidden-item-layout="true" :current="current_index" easing-function="linear" @transition="on_transition" @change="handle_swiper_change">
<swiper-item v-for="(video_item, index) in display_video_list" :key="video_item.id">
<view class="video-container pr" @tap.stop="toggle_play_pause">
@ -287,14 +288,14 @@
this.get_last_or_next_data_list(this.params.id, 1, 1);
} else {
this.setData({
data_tabs_loding_status: 2,
data_list_loding_status: 2,
data_tabs_loding_msg: data.msg,
});
}
},
fail: (err) => {
this.setData({
data_tabs_loding_status: 2,
data_list_loding_status: 2,
data_list_loding_msg: this.$t('common.internet_error_tips'),
});
}
@ -332,17 +333,18 @@
} else if (is_next == 1 && new_data.next.length > 0) { //
data_list.push(...new_data.next);
}
const new_index = data_list.findIndex(item => item.id == this.params.id);
console.log(data_list);
const new_index = data_list.findIndex(item => item.id == this.params.id);
this.setData({
video_data_list: data_list,
current_index: is_last == 1 && is_next == 1 ? (new_index < data_list.length - 1 ? new_index : 0) : this.current_index,
current_index: is_last == 1 && is_next == 1 ? (new_index == data_list.length - 1 ? 2 : (new_index == data_list.length - 2 ? 1 : 0)) : this.current_index,
});
//
this.update_display_data();
if (is_last == 1 && is_next == 1) {
//
this.update_display_data();
setTimeout(() => {
// //
this.update_share_info(this.display_video_list[0]);
@ -354,33 +356,37 @@
setTimeout(() => {
if (this.video_contexts[0]) { // 0
this.video_play_event(this.video_contexts[0]);
this.video_play_event(this.video_contexts[0], true);
}
}, 200);
}, 0);
}
} else {
this.setData({
data_tabs_loding_status: 2,
data_list_loding_status: 2,
data_tabs_loding_msg: data.msg,
});
}
},
fail: (err) => {
this.setData({
data_tabs_loding_status: 2,
data_list_loding_status: 2,
data_list_loding_msg: this.$t('common.internet_error_tips'),
});
}
});
},
video_play_event(video_contexts) {
video_play_event(video_contexts, is_first_play = false) {
try {
video_contexts.play().catch(() => {
this.setData({
paused: true,
if (is_first_play) {
video_contexts.play().catch(() => {
this.setData({
paused: true,
});
});
});
} else {
video_contexts.play();
}
} catch (error) {
this.setData({
paused: true,
@ -558,8 +564,8 @@
const { current } = event.detail;
const previousIndex = this.current_index;
if (this.video_contexts[previousIndex]) {
this.video_contexts[previousIndex].pause();
if (this.create_video_contexts[previousIndex]) {
this.create_video_contexts[previousIndex].pause();
}
this.setData({
current_index: current,
@ -608,32 +614,35 @@
swiper_key: get_math()
})
} else {
this.is_slide_start = true;
this.setData({
is_slide_start: true
})
// index
this.update_display_data();
}
//
this.update_share_info(this.display_video_list[current]);
setTimeout(() => {
//
if (this.video_contexts[current]) {
this.video_play_event(this.video_contexts[current]);
if (this.create_video_contexts[current]) {
this.video_play_event(this.create_video_contexts[current], false);
}
}, 100);
},
//
toggle_play_pause() {
if (this.video_contexts[this.current_index] == null) return; // 1
if (this.create_video_contexts[this.current_index] == null) return; // 1
this.setData({
paused: !this.paused
});
//
if (this.paused) {
this.video_contexts[this.current_index].pause(); //
this.create_video_contexts[this.current_index].pause(); //
} else {
this.video_play_event(this.video_contexts[this.current_index]); //
this.video_play_event(this.create_video_contexts[this.current_index], false); //
}
},
//

View File

@ -82,7 +82,7 @@ export default {
// #endif
search_query: '',
tabs: [],
current_tabs_index: '',
current_tabs_index: 0,
current_tabs_id: '',
recommend_videos: [],
isLoadingMore: false,
@ -94,7 +94,7 @@ export default {
header_padding_left: '',
};
},
onshow() {
onShow() {
this.init();
},
methods: {