I'm trying to play a file that's stored locally on the device, but it doesn't work.
The path looks like this:
file:///data/user/0/com.myapp/files/RNFetchBlobTmp_ek4mbn9hjs00p2eiqjllmlh
Initializing the sound:
const localSound = new sound(path);
In render:
<Button
title='Play'
onPress={() => {
localSound.stop(() =>
localSound.play(
success => !success && localSound.reset()
)
);
}}
/>
I've tested this same code with a remote url and it works perfectly. What am I doing wrong here?
This is an Android 8.1.0 emulated device. I'm using react-native 0.55.4 and react-native-sound 0.10.9. Let me know if there's any other details you'd like to know.
react-native-sound doesn't accept having file:// in front of the file path.
Are there any workarounds that will allow react-native-sound to accept having file:// in front of the file path?
@sw5813, the OP wasn't very clear about the fix. You can play local files on Android, just remove the file:// prefix.
Wrong:
file:///data/user/0/com.myapp/files/RNFetchBlobTmp_ek4mbn9hjs00p2eiqjllmlh
Correct:
/data/user/0/com.myapp/files/RNFetchBlobTmp_ek4mbn9hjs00p2eiqjllmlh
@joserocha3
Thank you for your explain. however, I tried to remove "file://" from the file path but still cannot find or open the local file on android, and the error callback is not called also.
I tried to upload the file on this uri to server and download with new Sound(remotePath) and it works fine. But I cannot find any way to directly read it from local storage.
The file's path is
file:///data/user/0/com.myapp/cache/ExperienceData/%2540xxx%252F/Audio/recording-xxx.m4a
The path I tried is
/data/user/0/com.myapp/cache/ExperienceData/%2540xxx%252F/Audio/recording-xxx.m4a
Do you have any thought on it?
im facing this issue too, i need to use file:// so i could post my .aac file to my server is that any solution about this problem?
@SwordElucidator I'm facing the same issue too. Have you found any solution?
@Preethyp @tlweiii6465 Here's a quick hack to workaround this.
const fileLocationWithPrefix = "file:///data/user/0/com.myapp/cache/ExperienceData/%2540xxx%252F/Audio/recording-xxx.m4a"
const fileLocationWithoutPrefix = fileLocation.split("file://")[1]
// '/data/user/0/com.myapp/cache/ExperienceData/%2540xxx%252F/Audio/recording-xxx.m4a'
This could be documented somewhere :) or treated as a new feature...