mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
build(spf): build26 from 45504a2b
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
import { isResolvedTrack } from "../types/index.js";
|
||||
//#region src/media/utils/track-selection.ts
|
||||
/**
|
||||
* Map track type to selected track ID property key in state.
|
||||
*/
|
||||
const SelectedTrackIdKeyByType = {
|
||||
video: "selectedVideoTrackId",
|
||||
audio: "selectedAudioTrackId",
|
||||
text: "selectedTextTrackId"
|
||||
};
|
||||
/**
|
||||
* Get selected track from state by type.
|
||||
* Returns properly typed track (partially or fully resolved) or undefined.
|
||||
* Type parameter T is inferred from the type argument.
|
||||
*
|
||||
* @example
|
||||
* const videoTrack = getSelectedTrack(state, 'video');
|
||||
* if (videoTrack && isResolvedTrack(videoTrack)) {
|
||||
* // videoTrack is VideoTrack
|
||||
* }
|
||||
*/
|
||||
function getSelectedTrack(state, type) {
|
||||
const { presentation } = state;
|
||||
if (!presentation?.selectionSets) return void 0;
|
||||
const trackId = state[SelectedTrackIdKeyByType[type]];
|
||||
return presentation.selectionSets.find(({ type: selectionSetType }) => selectionSetType === type)?.switchingSets[0]?.tracks.find(({ id }) => id === trackId);
|
||||
}
|
||||
/**
|
||||
* Returns the duration of the first resolved selected track, preferring
|
||||
* video over audio. A track is "resolved" once its media playlist has been
|
||||
* parsed (per {@link isResolvedTrack}). Returns `undefined` if neither
|
||||
* selected track is resolved.
|
||||
*/
|
||||
function getResolvedSelectedTrackDuration(state) {
|
||||
if (state.selectedVideoTrackId) {
|
||||
const video = getSelectedTrack(state, "video");
|
||||
if (video && isResolvedTrack(video)) return video.duration;
|
||||
}
|
||||
if (state.selectedAudioTrackId) {
|
||||
const audio = getSelectedTrack(state, "audio");
|
||||
if (audio && isResolvedTrack(audio)) return audio.duration;
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
export { SelectedTrackIdKeyByType, getResolvedSelectedTrackDuration, getSelectedTrack };
|
||||
|
||||
//# sourceMappingURL=track-selection.js.map
|
||||
Reference in New Issue
Block a user