refactor source plugin
This commit is contained in:
parent
6ebfa2e7e7
commit
466994fb3e
|
@ -7,28 +7,59 @@ interface artplayPluginSource {
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function artplayPluginSource(option: artplayPluginSource[]) {
|
const switchSource = (art: Artplayer, source: artplayPluginSource) => {
|
||||||
|
const status = art.plugins["syncPlugin"].currentStatus();
|
||||||
|
art.once("video:canplay", () => {
|
||||||
|
art.plugins["syncPlugin"].setAndNoPublishStatus(status);
|
||||||
|
art.emit("restart", source.url);
|
||||||
|
});
|
||||||
|
if (art.controls["quality"]) art.controls.remove("quality");
|
||||||
|
if (art.setting.find("quality")) art.setting.remove("quality");
|
||||||
|
destroyOldCustomPlayLib(art);
|
||||||
|
art.option.type = source.type;
|
||||||
|
art.url = source.url;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function artplayPluginSource(sources: artplayPluginSource[]) {
|
||||||
return (art: Artplayer) => {
|
return (art: Artplayer) => {
|
||||||
art.controls.add({
|
let currentSourceName = sources.length > 0 ? sources[0].html : "";
|
||||||
position: "right",
|
const onSelect = (source: artplayPluginSource) => {
|
||||||
html: "源",
|
currentSourceName = source.html;
|
||||||
selector: option,
|
switchSource(art, source);
|
||||||
onSelect: function (item: artplayPluginSource) {
|
return "源";
|
||||||
const status = art.plugins["syncPlugin"].currentStatus();
|
};
|
||||||
art.once("video:canplay", () => {
|
const setSelector = (newSources: artplayPluginSource[]) => {
|
||||||
art.plugins["syncPlugin"].setAndNoPublishStatus(status);
|
if (newSources.length === 0) {
|
||||||
art.emit("restart", item.url);
|
if (art.controls["source"]) art.controls.remove("source");
|
||||||
|
if (art.setting.find("source")) art.setting.remove("source");
|
||||||
|
} else {
|
||||||
|
art.controls.update({
|
||||||
|
name: "source",
|
||||||
|
position: "right",
|
||||||
|
html: "源",
|
||||||
|
selector: newSources,
|
||||||
|
onSelect
|
||||||
|
});
|
||||||
|
art.setting.update({
|
||||||
|
name: "source",
|
||||||
|
position: "right",
|
||||||
|
html: "源",
|
||||||
|
selector: newSources,
|
||||||
|
onSelect
|
||||||
});
|
});
|
||||||
if (art.controls["quality"]) art.controls.remove("quality");
|
|
||||||
if (art.setting.find("quality")) art.setting.remove("quality");
|
|
||||||
destroyOldCustomPlayLib(art);
|
|
||||||
art.option.type = item.type;
|
|
||||||
art.url = item.url;
|
|
||||||
return "源";
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
const updateSources = (newSources: artplayPluginSource[]) => {
|
||||||
|
setSelector(newSources);
|
||||||
|
const oldSource = newSources.find((v) => v.html === currentSourceName);
|
||||||
|
if (oldSource) {
|
||||||
|
onSelect(oldSource);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setSelector(sources);
|
||||||
return {
|
return {
|
||||||
name: "source"
|
name: "source",
|
||||||
|
updateSources
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import artplayerPluginAss from "@/plugins/artplayer-plugin-ass";
|
||||||
import { newSyncPlugin } from "@/plugins/sync";
|
import { newSyncPlugin } from "@/plugins/sync";
|
||||||
import artplayerPluginQuality from "@/plugins/quality";
|
import artplayerPluginQuality from "@/plugins/quality";
|
||||||
import { artplayPluginSource } from "@/plugins/source";
|
import { artplayPluginSource } from "@/plugins/source";
|
||||||
|
import { currentMovieApi } from "@/services/apis/movie";
|
||||||
|
|
||||||
const Player = defineAsyncComponent(() => import("@/components/Player.vue"));
|
const Player = defineAsyncComponent(() => import("@/components/Player.vue"));
|
||||||
|
|
||||||
|
@ -163,7 +164,7 @@ const playerOption = computed<options>(() => {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (room.currentMovie.base!.moreSources) {
|
if (room.currentMovie.base!.moreSources) {
|
||||||
const obj = room.currentMovie.base!.moreSources;
|
const obj = room.currentMovie.base!.moreSources || [];
|
||||||
option.plugins!.push(
|
option.plugins!.push(
|
||||||
artplayPluginSource([
|
artplayPluginSource([
|
||||||
{
|
{
|
||||||
|
@ -222,6 +223,52 @@ const newLazyInitSubtitlePlugin = (subtitle: Subtitles) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { state: currentMovie, execute: reqCurrentMovieApi } = currentMovieApi();
|
||||||
|
const updateSources = async () => {
|
||||||
|
try {
|
||||||
|
await reqCurrentMovieApi({
|
||||||
|
headers: { Authorization: roomToken.value }
|
||||||
|
});
|
||||||
|
if (!currentMovie.value) return;
|
||||||
|
if (currentMovie.value.movie.base.url.startsWith("/")) {
|
||||||
|
currentMovie.value.movie.base.url = `${window.location.origin}${currentMovie.value.movie.base.url}`;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
currentMovie.value.movie.base.moreSources &&
|
||||||
|
currentMovie.value.movie.base.moreSources.length > 0
|
||||||
|
) {
|
||||||
|
for (let i = 0; i < currentMovie.value.movie.base.moreSources.length; i++) {
|
||||||
|
if (currentMovie.value.movie.base.moreSources[i].url.startsWith("/")) {
|
||||||
|
currentMovie.value.movie.base.moreSources[i].url =
|
||||||
|
`${window.location.origin}${currentMovie.value.movie.base.moreSources[i].url}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!player) return;
|
||||||
|
room.currentExpireId = currentMovie.value.expireId;
|
||||||
|
const moreSources = currentMovie.value.movie.base.moreSources || [];
|
||||||
|
player.plugins["source"].updateSources([
|
||||||
|
{
|
||||||
|
url: currentMovie.value.movie.base.url,
|
||||||
|
html: "默认",
|
||||||
|
type: currentMovie.value.movie.base.type || ""
|
||||||
|
},
|
||||||
|
...moreSources.map((item) => ({
|
||||||
|
url: item.url,
|
||||||
|
html: item.name,
|
||||||
|
type: item.type
|
||||||
|
}))
|
||||||
|
]);
|
||||||
|
} catch (err: any) {
|
||||||
|
console.log(err);
|
||||||
|
ElNotification({
|
||||||
|
title: "获取影片列表失败",
|
||||||
|
message: err.response.data.error || err.message,
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getPlayerInstance = (art: Artplayer) => {
|
const getPlayerInstance = (art: Artplayer) => {
|
||||||
player = art;
|
player = art;
|
||||||
};
|
};
|
||||||
|
@ -295,13 +342,16 @@ const handleElementMessage = (msg: ElementMessage) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置正在播放的影片
|
|
||||||
case ElementMessageType.CURRENT_EXPIRED: {
|
case ElementMessageType.CURRENT_EXPIRED: {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
title: "链接过期,刷新中",
|
title: "链接过期,刷新中",
|
||||||
type: "info"
|
type: "info"
|
||||||
});
|
});
|
||||||
|
updateSources();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置正在播放的影片
|
||||||
case ElementMessageType.CURRENT_CHANGED: {
|
case ElementMessageType.CURRENT_CHANGED: {
|
||||||
getCurrentMovie();
|
getCurrentMovie();
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue