Improve player playback and quality selection
This commit is contained in:
@ -3,7 +3,7 @@ import Artplayer from "artplayer";
|
|||||||
import Hls from "hls.js";
|
import Hls from "hls.js";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
src: string;
|
urls: any;
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,13 +13,13 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
const emit = defineEmits(['get-instance'])
|
const emit = defineEmits(['get-instance'])
|
||||||
|
|
||||||
const options = computed(() => {
|
const options = computed(() => {
|
||||||
console.log(props.src)
|
|
||||||
return {
|
return {
|
||||||
url: props.src || '',
|
url: props.urls[0].url || '',
|
||||||
type: 'm3u8',
|
type: 'm3u8',
|
||||||
customType: {
|
customType: {
|
||||||
m3u8: playM3u8,
|
m3u8: playM3u8,
|
||||||
},
|
},
|
||||||
|
quality: props.urls,
|
||||||
autoSize: true,
|
autoSize: true,
|
||||||
autoMini: true,
|
autoMini: true,
|
||||||
playbackRate: true,
|
playbackRate: true,
|
||||||
@ -69,18 +69,6 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex items-center justify-center">
|
<div class="flex items-center justify-center">
|
||||||
<div class="w-1/2 aspect-video" ref="artplayerRef"></div>
|
<div class="w-2/3 aspect-video" ref="artplayerRef"></div>
|
||||||
</div>
|
|
||||||
<div class="h-lvh">
|
|
||||||
test
|
|
||||||
test
|
|
||||||
ste
|
|
||||||
t
|
|
||||||
|
|
||||||
t
|
|
||||||
|
|
||||||
t
|
|
||||||
</div>
|
|
||||||
<div class="h-lvh">
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
<p>Media Hash: {{ mediaHash }}</p>
|
<p>Media Hash: {{ mediaHash }}</p>
|
||||||
<p>Episode: {{ episode }}</p>
|
<p>Episode: {{ episode }}</p>
|
||||||
|
|
||||||
<div v-if="hlsUrl">
|
<div v-if="hlsUrls">
|
||||||
<Player :id="mediaId.toString()" :src="hlsUrl" />
|
<Player :id="mediaId.toString().concat(episode?.toString() || '')" :urls="hlsUrls" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Loading and Error States -->
|
<!-- Loading and Error States -->
|
||||||
@ -36,6 +36,7 @@ const results = ref<KodikVideoLinks | null>(null)
|
|||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
const error = ref<unknown>(null)
|
const error = ref<unknown>(null)
|
||||||
const hlsUrl = ref<string | null>(null)
|
const hlsUrl = ref<string | null>(null)
|
||||||
|
const hlsUrls = ref<any>(null)
|
||||||
|
|
||||||
const playerOptions = ref({
|
const playerOptions = ref({
|
||||||
autoplay: false,
|
autoplay: false,
|
||||||
@ -73,23 +74,14 @@ watchEffect(async () => {
|
|||||||
results.value = response?.data || null
|
results.value = response?.data || null
|
||||||
|
|
||||||
if (results.value?.links) {
|
if (results.value?.links) {
|
||||||
const qualities = Object.keys(results.value.links)
|
hlsUrls.value = Object.entries(results.value.links).map(([quality, links], index) => {
|
||||||
const bestQuality = qualities.includes('360') ? '360' :
|
return {
|
||||||
qualities[0]
|
html: quality,
|
||||||
|
url: links.find(link => link.src?.includes('.m3u8') || link.type?.includes('hls'))?.src,
|
||||||
const hlsLink = results.value.links[bestQuality ?? '360']?.find(link =>
|
default: index === 0
|
||||||
link.type?.includes('hls') || link.src?.includes('.m3u8')
|
|
||||||
)
|
|
||||||
console.log(bestQuality)
|
|
||||||
|
|
||||||
if (hlsLink?.src) {
|
|
||||||
hlsUrl.value = hlsLink.src
|
|
||||||
if (playerOptions.value?.sources[0]) {
|
|
||||||
playerOptions.value.sources[0].src = hlsUrl.value
|
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
throw new Error('No HLS stream found in response')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = err
|
error.value = err
|
||||||
|
Reference in New Issue
Block a user