react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

Android assets

Open mkraina opened this issue 8 years ago • 8 comments

Is it possible to load file (both artwork & audio) from android assets? I'm receiving error "unexpected url: asset:/path/to/file/in/assets/file.jpg" for artwork, setting audio doesn't cause crash, but it's still not giving any sound

mkraina avatar May 06 '18 07:05 mkraina

If you want to load a file from the app bundle, use require/import:

{
    artwork: require('./file.jpg')
}

If you want to load a file from the file system, you can prepend file:/// to the path:

{
    artwork: 'file:///path/to/file/file.jpg'
}

Guichaguri avatar May 06 '18 15:05 Guichaguri

@Guichaguri thanks for quick reply, tried it with no luck, Android's assets folder really seems to be unsupported for now, since it needs different MediaPlayer data source handling, see react-native-sound I think using/handling the 'asset:/' prefix is just OK, I'll create PR soon

mkraina avatar May 08 '18 11:05 mkraina

Why not use the app bundle instead? It basically works the same way as the assets folder

Guichaguri avatar May 08 '18 17:05 Guichaguri

I'm closing this issue for inactivity. Feel free to reopen.

Guichaguri avatar Oct 23 '18 23:10 Guichaguri

I am using something like this { artwork: this.props.player.currentTrack.img } where this.props.player.currentTrack.img is this for example:

file:///storage/emulated/0/com.myapp.app/covers/covers/covers783.jpg

but notification is still white and I can't get any images there. I was not able to find anything useful on documentation. Does anyone have any idea how to show local files in notification?

DNA-h avatar Jan 01 '20 15:01 DNA-h

it appears a url like so works: file:///android_asset/path/to/file.mp3

jasongaare avatar Apr 08 '20 05:04 jasongaare

Why not use the app bundle instead? It basically works the same way as the assets folder @Guichaguri, the app bundle will be load in startup time, if the file is large it will prolong the startup time when user opens the app, cause reducing UX.

truongpham17 avatar Jun 03 '20 01:06 truongpham17

@truongpham17 I have never experienced that. In Android, the files in the app bundle are moved to the assets folder and the import/require returns a reference ID to that Android asset. The only ones that prolong the startup time are JS or JSON files.

Guichaguri avatar Jun 03 '20 07:06 Guichaguri