feat: Media stream info in now playing modal (#233)

* feat: add base codec info to player

* fix: redundant console.log

* chore: translation

* fix: only overflow direct play
This commit is contained in:
Lei Nelissen
2024-07-25 17:16:30 +02:00
committed by GitHub
parent 189491b90a
commit 0d09c6f0b8
14 changed files with 148 additions and 13 deletions

View File

@@ -61,6 +61,7 @@ export async function retrieveAlbumTracks(ItemId: string) {
const singleAlbumOptions = {
ParentId: ItemId,
SortBy: 'ParentIndexNumber,IndexNumber,SortName',
Fields: 'MediaStreams',
};
const singleAlbumParams = new URLSearchParams(singleAlbumOptions).toString();

View File

@@ -15,6 +15,9 @@ function generateConfig(credentials: Credentials): RequestInit {
};
}
/**
* Retrieve a copy of the store without getting caught in import cycles.
*/
export function asyncFetchStore() {
return require('@/store').default as Store;
}
@@ -74,7 +77,7 @@ export async function fetchApi<T>(
const data = await response.json();
throw data;
} catch {
throw response;
throw new Error('FailedRequest');
}
}

View File

@@ -22,8 +22,9 @@ const baseTrackOptions: Record<string, string> = {
TranscodingContainer: 'aac',
AudioCodec: 'aac',
Container: 'mp3,aac',
audioBitRate: '320000',
...trackOptionsOsOverrides[Platform.OS],
};
} as const;
/**
* Generate the track streaming url from the trackId
@@ -47,10 +48,12 @@ export function generateTrackUrl(trackId: string) {
* Generate a track object from a Jellyfin ItemId so that
* react-native-track-player can easily consume it.
*/
export function generateTrack(track: AlbumTrack): Track {
export async function generateTrack(track: AlbumTrack): Promise<Track> {
// Also construct the URL for the stream
const url = generateTrackUrl(track.Id);
const response = await fetch(url, { method: 'HEAD' });
return {
url,
backendId: track.Id,
@@ -63,6 +66,9 @@ export function generateTrack(track: AlbumTrack): Track {
: getImage(track.Id),
hasLyrics: track.HasLyrics,
lyrics: track.Lyrics,
contentType: response.headers.get('Content-Type') || undefined,
isDirectPlay: response.headers.has('Content-Length'),
bitRate: baseTrackOptions.audioBitRate,
};
}

View File

@@ -27,9 +27,9 @@ export default function useCurrentTrack(): CurrentTrackResponse {
// Retrieve the current track from the queue using the index
const retrieveCurrentTrack = useCallback(async () => {
const queue = await TrackPlayer.getQueue();
const currentTrackIndex = await TrackPlayer.getCurrentTrack();
if (currentTrackIndex !== null) {
setTrack(queue[currentTrackIndex] as Track);
const currentTrackIndex = await TrackPlayer.getActiveTrackIndex();
if (currentTrackIndex !== undefined) {
setTrack(queue[currentTrackIndex]);
setIndex(currentTrackIndex);
} else {
setTrack(undefined);

View File

@@ -49,7 +49,7 @@ export default function usePlayTracks() {
const queue = await TrackPlayer.getQueue();
// Convert all trackIds to the relevant format for react-native-track-player
const generatedTracks = trackIds.map((trackId) => {
const generatedTracks = (await Promise.all(trackIds.map(async (trackId) => {
const track = tracks[trackId];
// GUARD: Check that the track actually exists in Redux
@@ -58,7 +58,7 @@ export default function usePlayTracks() {
}
// Retrieve the generated track from Jellyfin
const generatedTrack = generateTrack(track);
const generatedTrack = await generateTrack(track);
// Check if a downloaded version exists, and if so rewrite the URL
const download = downloads[trackId];
@@ -67,7 +67,7 @@ export default function usePlayTracks() {
}
return generatedTrack;
}).filter((t): t is Track => typeof t !== 'undefined');
}))).filter((t): t is Track => typeof t !== 'undefined');
// Potentially shuffle all tracks
const newTracks = shuffle ? shuffleArray(generatedTracks) : generatedTracks;