Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed Jul 13, 2024
1 parent c277bbb commit 243bdc9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/docs/public/oplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
deps = [],
m3u = false,
p = undefined,
title = '❤OPlayer'
title = '❤OPlayer',
txt = ''

var _query = decodeURIComponent(query || '')
if (_query.startsWith('http')) {
Expand All @@ -26,6 +27,7 @@
m3u = safeDecodeURIComponent(search.get('m3u'))
p = search.has('p') ? search.get('p') : undefined
p == '' ? (p = undefined) : (p = +p)
txt = safeDecodeURIComponent(search.get('txt'))

subtitle = search.get('subtitle')
? {
Expand Down Expand Up @@ -62,6 +64,19 @@
deps.push(['https://cdn.jsdelivr.net/npm/m3u8-parser@7.1.0/dist/m3u8-parser.min.js'])
}

if (txt) {
fetch(txt)
.then((r) => r.text())
.then((text) => {
console.log(text.split('\n'))
playlist = text.split('\n').map((line) => {
const [title, src] = line.split(',')
return { title, src: src }
})
})
.then(applyPlaylist)
}

var player = OPlayer.make('#oplayer', {
source: { src, poster, title: title },
playbackRate: localStorage.getItem('@oplayer/UserPreferences/speed') || 1,
Expand Down Expand Up @@ -153,6 +168,10 @@
deps.map(([_, fn]) => fn && fn())
} catch (error) {}

applyPlaylist()
})

function applyPlaylist() {
if (playlist.length) {
player.applyPlugin(
new OPlugin.Playlist({
Expand Down Expand Up @@ -181,7 +200,7 @@
})
)
}
})
}

player.on('ratechange', () => {
if (!player.isSourceChanging)
Expand Down

0 comments on commit 243bdc9

Please sign in to comment.