-
{{ movie.title }}
diff --git a/pages/search.vue b/pages/search.vue
index 321cdaa..b105b8f 100644
--- a/pages/search.vue
+++ b/pages/search.vue
@@ -118,7 +118,7 @@ onMounted(() => {
-
+
diff --git a/pages/tv/index.vue b/pages/tv/index.vue
index 3862a3f..3af2c11 100644
--- a/pages/tv/index.vue
+++ b/pages/tv/index.vue
@@ -12,7 +12,7 @@ const videoSrc = ref('');
const modalShow = ref(false);
const videoPlayStatus = ref(false);
const videoLoading = ref(false);
-const videoMuted = ref(true);
+const videoMuted = ref(false);
let hls = null; // 缓存 HLS 实例
let currentEffectIndex = 0;
@@ -23,7 +23,7 @@ const getTvSources = async () => {
const res = await $fetch('https://r2cf.aipan.me/tv.json');
if (videoSrc.value === '') {
videoSrc.value = res[0].url;
- loadHLS(videoSrc.value); // 初始化第一个视频源
+ // loadHLS(videoSrc.value); // 初始化第一个视频源
}
tvSources.value = res;
} catch (error) {
@@ -33,20 +33,36 @@ const getTvSources = async () => {
// 加载 HLS 视频
const loadHLS = (url) => {
- if (!hls && Hls.isSupported()) {
- hls = new Hls();
- hls.attachMedia(videoPlayer.value);
- }
-
- if (Hls.isSupported()) {
- hls.loadSource(url);
- videoPlayer.value.play();
- videoPlayer.value.muted = videoMuted.value;
- videoPlayStatus.value = true;
- videoLoading.value = false;
- modalShow.value = false;
- } else if (videoPlayer.value.canPlayType('application/vnd.apple.mpegurl')) {
+ // 判断是否是 m3u8 格式
+ if (url.endsWith('.m3u8')) {
+ if (!hls && Hls.isSupported()) {
+ hls = new Hls();
+ hls.attachMedia(videoPlayer.value);
+ }
+ if (Hls.isSupported()) {
+ hls.loadSource(url);
+ videoPlayer.value.play();
+ videoPlayer.value.muted = videoMuted.value;
+ videoPlayStatus.value = true;
+ videoLoading.value = false;
+ modalShow.value = false;
+ } else if (videoPlayer.value.canPlayType('application/vnd.apple.mpegurl')) {
+ // 对于 Safari 或其他原生支持 HLS 的浏览器
+ videoPlayer.value.src = url;
+ videoPlayer.value.play();
+ videoPlayer.value.muted = videoMuted.value;
+ videoPlayStatus.value = true;
+ videoLoading.value = false;
+ modalShow.value = false;
+ }
+ } else {
+ // 如果不是 m3u8,直接将 URL 赋值给 videoPlayer 的 src
+ if (hls) {
+ hls.destroy();
+ hls = null; // 确保 HLS 实例不再被使用
+ }
videoPlayer.value.src = url;
+ videoPlayer.value.load(); // 加载新视频
videoPlayer.value.play();
videoPlayer.value.muted = videoMuted.value;
videoPlayStatus.value = true;
@@ -58,10 +74,17 @@ const loadHLS = (url) => {
// 视频切换处理
const handleSwithcSource = (url) => {
videoLoading.value = true;
+
+ // 在切换视频源之前,停止当前视频播放,并清除旧的src
+ if (videoPlayer.value) {
+ videoPlayer.value.pause();
+ videoPlayer.value.removeAttribute('src'); // 清空旧视频源
+ videoPlayer.value.load(); // 重置
标签
+ }
+
videoSrc.value = url;
loadHLS(url);
};
-
// 视频播放和暂停
const handleSwitchVideoStatus = () => {
if (videoPlayer.value.paused) {
@@ -145,6 +168,10 @@ onMounted(() => {
});
onBeforeUnmount(() => {
+ if (hls) {
+ hls.destroy();
+ hls = null; // 确保不再引用该实例
+ }
if (videoPlayer.value) {
videoPlayer.value.removeEventListener('waiting', handleWaiting);
videoPlayer.value.removeEventListener('playing', handlePlaying);
@@ -156,21 +183,29 @@ onBeforeUnmount(() => {
-
-
-
+
+
- 频道
- {{ !videoMuted ? '静音' : '取消静音' }}
@@ -180,22 +215,22 @@ onBeforeUnmount(() => {
{{ !videoPlayStatus ? '播放' : '暂停' }}
换肤
重置
全屏
@@ -234,6 +269,10 @@ onBeforeUnmount(() => {