Skip to content

Commit

Permalink
feat: local playback
Browse files Browse the repository at this point in the history
  • Loading branch information
lovegaoshi committed Feb 23, 2024
1 parent eda66ec commit 8fd5372
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/stores/appStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { logger } from '@utils/Logger';
import rejson from '../utils/rejson.json';
import { LoadJSONRegExtractors } from '../utils/re';
import { SOURCE } from '@enums/MediaFetch';

interface AppStore {
pipMode: boolean;
Expand Down Expand Up @@ -180,9 +181,12 @@ export const cacheResolvedURL = async (
) {
logger.debug(`[CacheResolveURL] ${song.parsedName} needs to be refetched.`);
const result = await resolveURL(song);
appStore.setState({
cachedResolveURLMap: { ...cachedResolveURLMap, [song.id]: result },
});
// HACK: do not cache any local source files
if (song.source !== SOURCE.local) {
appStore.setState({
cachedResolveURLMap: { ...cachedResolveURLMap, [song.id]: result },
});
}
return result;
}
return cachedResolvedURL;
Expand Down
1 change: 1 addition & 0 deletions src/utils/SongOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const resolveUrl = async (song: NoxMedia.Song, iOS = true) => {
logger.debug(
`[SongResolveURL] cache ${cachedUrl ? 'found' : 'missed'}, ${song.id}`
);

const cacheWrapper = async (
song: NoxMedia.Song
): Promise<NoxNetwork.ResolvedNoxMediaURL> => {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/ffmpeg/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import TrackPlayer from 'react-native-track-player';
import { logger } from '../Logger';
import { r128gain2Volume } from '../Utils';

export const cacheAlbumArt = async (fpath: string) => {
// HACK: exoplayer handles embedded art but I also need this for the UI...
await FFmpegKit.execute(
`-i '${fpath}' -an -vcodec copy ${RNFetchBlob.fs.dirs.CacheDir}/tempCover.jpg`
);
return `${RNFetchBlob.fs.dirs.CacheDir}/tempCover.jpg`;
};

export const probeMetadata = async (fspath: string) => {
const session = await FFprobeKit.execute(
`-v quiet -print_format json -show_format '${fspath}'`
Expand Down
9 changes: 4 additions & 5 deletions src/utils/mediafetch/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* steps to refactor:
* each site needs a fetch to parse regex extracted, a videoinfo fetcher and a song fetcher.
*/
import { Platform, NativeModules } from 'react-native';
import { NativeModules } from 'react-native';

import { probeMetadata } from '@utils/ffmpeg/ffmpeg';
import { probeMetadata, cacheAlbumArt } from '@utils/ffmpeg/ffmpeg';
import { SOURCE } from '@enums/MediaFetch';
import { regexFetchProps } from './generic';
import SongTS from '@objects/Song';
Expand All @@ -35,8 +35,7 @@ const songFetch = async (
nameRaw: probedMetadata.tags?.title || v.fileName,
singer: probedMetadata.tags?.artist || '',
singerId: probedMetadata.tags?.artist || '',
cover:
'https://i2.hdslb.com/bfs/face/b70f6e62e4582d4fa5d48d86047e64eb57d7504e.jpg',
cover: '',
lyric: '',
page: 0,
duration: Number(probedMetadata.duration) || 0,
Expand All @@ -55,7 +54,7 @@ const regexFetch = async ({
});

const resolveURL = async (song: NoxMedia.Song) => {
return { url: song.bvid };
return { url: song.bvid, cover: await cacheAlbumArt(song.bvid) };
};

const refreshSong = (song: NoxMedia.Song) => song;
Expand Down

0 comments on commit 8fd5372

Please sign in to comment.