|
|
@ -16,6 +16,7 @@ import { updateSource } from "@/video/state/logic/source"; |
|
|
|
import { resetStateForSource } from "@/video/state/providers/helpers"; |
|
|
|
import { resetStateForSource } from "@/video/state/providers/helpers"; |
|
|
|
|
|
|
|
|
|
|
|
import { VideoPlayerStateProvider } from "./providerTypes"; |
|
|
|
import { VideoPlayerStateProvider } from "./providerTypes"; |
|
|
|
|
|
|
|
import { SettingsStore } from "../../../state/settings/store"; |
|
|
|
import { getPlayerState } from "../cache"; |
|
|
|
import { getPlayerState } from "../cache"; |
|
|
|
import { updateMediaPlaying } from "../logic/mediaplaying"; |
|
|
|
import { updateMediaPlaying } from "../logic/mediaplaying"; |
|
|
|
import { updateProgress } from "../logic/progress"; |
|
|
|
import { updateProgress } from "../logic/progress"; |
|
|
@ -140,18 +141,53 @@ export function createCastingStateProvider( |
|
|
|
mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED; |
|
|
|
mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED; |
|
|
|
mediaInfo.metadata = movieMeta; |
|
|
|
mediaInfo.metadata = movieMeta; |
|
|
|
|
|
|
|
|
|
|
|
const request = new chrome.cast.media.LoadRequest(mediaInfo); |
|
|
|
const loadRequest = new chrome.cast.media.LoadRequest(mediaInfo); |
|
|
|
request.autoplay = true; |
|
|
|
loadRequest.autoplay = true; |
|
|
|
|
|
|
|
// start where video left off before cast
|
|
|
|
|
|
|
|
loadRequest.currentTime = state.progress.time; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let captions = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.source?.caption?.url) { |
|
|
|
|
|
|
|
const subtitles = new chrome.cast.media.Track( |
|
|
|
|
|
|
|
1, |
|
|
|
|
|
|
|
chrome.cast.media.TrackType.TEXT |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
subtitles.trackContentId = |
|
|
|
|
|
|
|
"https://cc.2cdns.com/a8/d8/a8d8c98288d4db1d6404e54c644091f5/eng-9.vtt"; |
|
|
|
|
|
|
|
subtitles.trackContentType = "text/vtt"; |
|
|
|
|
|
|
|
subtitles.subtype = chrome.cast.media.TextTrackType.SUBTITLES; |
|
|
|
|
|
|
|
subtitles.name = "Subtitles"; |
|
|
|
|
|
|
|
subtitles.language = "en"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tracks = [subtitles]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mediaInfo.tracks = tracks; |
|
|
|
|
|
|
|
mediaInfo.textTrackStyle = new chrome.cast.media.TextTrackStyle(); |
|
|
|
|
|
|
|
mediaInfo.textTrackStyle.backgroundColor = |
|
|
|
|
|
|
|
SettingsStore.get().captionSettings.style.backgroundColor; |
|
|
|
|
|
|
|
mediaInfo.textTrackStyle.foregroundColor = |
|
|
|
|
|
|
|
SettingsStore.get().captionSettings.style.color.concat("ff"); // needs to be in RGBA format
|
|
|
|
|
|
|
|
mediaInfo.textTrackStyle.fontScale = |
|
|
|
|
|
|
|
SettingsStore.get().captionSettings.style.fontSize / 40; // scale factor way smaller than fortSize
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadRequest.activeTrackIds = [1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
captions = { |
|
|
|
|
|
|
|
url: state.source.caption.url, |
|
|
|
|
|
|
|
id: state.source.caption.id, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const session = ins?.getCurrentSession(); |
|
|
|
const session = ins?.getCurrentSession(); |
|
|
|
session?.loadMedia(request); |
|
|
|
session?.loadMedia(loadRequest); |
|
|
|
|
|
|
|
|
|
|
|
// update state
|
|
|
|
// update state
|
|
|
|
state.source = { |
|
|
|
state.source = { |
|
|
|
quality: source.quality, |
|
|
|
quality: source.quality, |
|
|
|
type: source.type, |
|
|
|
type: source.type, |
|
|
|
url: source.source, |
|
|
|
url: source.source, |
|
|
|
caption: null, |
|
|
|
caption: captions, |
|
|
|
embedId: source.embedId, |
|
|
|
embedId: source.embedId, |
|
|
|
providerId: source.providerId, |
|
|
|
providerId: source.providerId, |
|
|
|
thumbnails: [], |
|
|
|
thumbnails: [], |
|
|
@ -166,6 +202,16 @@ export function createCastingStateProvider( |
|
|
|
id, |
|
|
|
id, |
|
|
|
url, |
|
|
|
url, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// media has to be loaded again to use the new captions
|
|
|
|
|
|
|
|
this.setSource({ |
|
|
|
|
|
|
|
quality: state.source.quality, |
|
|
|
|
|
|
|
source: state.source.url, |
|
|
|
|
|
|
|
type: state.source.type, |
|
|
|
|
|
|
|
embedId: state.source.embedId, |
|
|
|
|
|
|
|
providerId: state.source.providerId, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
updateSource(descriptor, state); |
|
|
|
updateSource(descriptor, state); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
@ -173,6 +219,17 @@ export function createCastingStateProvider( |
|
|
|
if (state.source) { |
|
|
|
if (state.source) { |
|
|
|
revokeCaptionBlob(state.source.caption?.url); |
|
|
|
revokeCaptionBlob(state.source.caption?.url); |
|
|
|
state.source.caption = null; |
|
|
|
state.source.caption = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tracksInfoRequest = new chrome.cast.media.EditTracksInfoRequest( |
|
|
|
|
|
|
|
[] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const session = ins?.getCurrentSession(); |
|
|
|
|
|
|
|
session?.getMediaSession()?.editTracksInfo( |
|
|
|
|
|
|
|
tracksInfoRequest, |
|
|
|
|
|
|
|
() => console.log("Captions cleared"), |
|
|
|
|
|
|
|
(error) => console.log(error) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
updateSource(descriptor, state); |
|
|
|
updateSource(descriptor, state); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|