mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 18:22:42 -08:00
refactor mpv state mapping into mpv-state helper
This commit is contained in:
25
src/core/services/mpv-state.ts
Normal file
25
src/core/services/mpv-state.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export type MpvTrackProperty = {
|
||||
type?: string;
|
||||
id?: number;
|
||||
selected?: boolean;
|
||||
"ff-index"?: number;
|
||||
};
|
||||
|
||||
export function resolveCurrentAudioStreamIndex(
|
||||
tracks: Array<MpvTrackProperty> | null | undefined,
|
||||
currentAudioTrackId: number | null,
|
||||
): number | null {
|
||||
if (!Array.isArray(tracks)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const audioTracks = tracks.filter((track) => track.type === "audio");
|
||||
const activeTrack =
|
||||
audioTracks.find((track) => track.id === currentAudioTrackId) ||
|
||||
audioTracks.find((track) => track.selected === true);
|
||||
|
||||
const ffIndex = activeTrack?.["ff-index"];
|
||||
return typeof ffIndex === "number" && Number.isInteger(ffIndex) && ffIndex >= 0
|
||||
? ffIndex
|
||||
: null;
|
||||
}
|
||||
Reference in New Issue
Block a user