Skip to content

Commit

Permalink
fix(chromecast): empty track
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed Apr 10, 2024
1 parent 609059e commit f18c774
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/docs/public/ohls.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/index.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/airplay.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].4/dist/chromecast.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].5/dist/chromecast.min.js"></script>

<script>
var playlistScriptCdn = 'https://cdn.jsdelivr.net/npm/@oplayer/plugins@latest/dist/playlist.min.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/plugins",
"version": "1.0.12-beta.4",
"version": "1.0.12-beta.5",
"author": "shiyiya",
"description": "oplayer's plugin",
"homepage": "https://github.com/shiyiya/oplayer",
Expand Down
26 changes: 14 additions & 12 deletions packages/plugins/src/chromecast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,20 @@ class ChromeCast implements PlayerPlugin {
if (source.poster) metadata.images = [{ url: source.poster, height: null, width: null }]
mediaInfo.metadata = metadata

const subtitles = this.player.context.ui?.config.subtitle?.source as any[]
mediaInfo.tracks = subtitles.map((sub, id) => {
const track = new chrome.cast.media.Track(id, chrome.cast.media.TrackType.TEXT)

track.name = sub.name
track.trackContentId = sub.src
track.trackContentType = sub.type || 'text/vtt' //TODO: url match
track.language = sub.language || sub.name
track.subtype = chrome.cast.media.TextTrackType.CAPTIONS

return track
})
const subtitles = this.player.context.ui?.config.subtitle?.source as any[] | undefined
if (subtitles) {
mediaInfo.tracks = subtitles.map((sub, id) => {
const track = new chrome.cast.media.Track(id, chrome.cast.media.TrackType.TEXT)

track.name = sub.name
track.trackContentId = sub.src
track.trackContentType = sub.type || 'text/vtt' //TODO: url match
track.language = sub.language || sub.name
track.subtype = chrome.cast.media.TextTrackType.CAPTIONS

return track
})
}

const request = new chrome.cast.media.LoadRequest(mediaInfo)

Expand Down

0 comments on commit f18c774

Please sign in to comment.