Comments (9)
@fredbt ok - I just figured it out, how to play a local file downloaded previously :)
var file_uri = RNFS.DocumentDirectoryPath + "/files/somemp3.downoaded";
this.sound = new Sound(file_uri, '', (err) => {
if (err) {
console.log("err: "+err);
return;
}
this.sound.play();
});
from react-native-sound.
@huangzuizui can be like this:
let localSong = RNFS.CachesDirectoryPath + '/song-name.mp3';
RNFS.downloadFile('http://your-song.online/song.mp3', localSong).then(() => {
let song = new Sound(localSong, '', (error) => {
song.play();
});
});
PS: On real device you can't save songs on MainBundlePath
.
PS-2: You need define the absolute path to the downloaded song.
from react-native-sound.
DocumentDirectoryPath
DocumentDirectoryPath path already contains /files/
from react-native-sound.
As noted in the feature comparison matrix, this is a known limitation of the current Android version. I plan to implement it later, but pull requests are always welcome.
from react-native-sound.
@jadsonlourenco
thanks, i assume u r talking about ios platform. it is ok on my iphone. i got that issue on android. react-native-fs support DocumentDirectory only.
from react-native-sound.
(How) did you manage to actually play the sound downloaded with react-native-fs? Listing my directory content shows that after the download, the file is available and has the correct size (see attached debugger screenshot), but when trying to play this exact path with let song = new Sound(localPath, '', (error) => { }
, I get an error message saying that the resource has not been found..
from react-native-sound.
I have an use case which is a bit more complex (?)
I have a server that returns a mp3 to the app as a response to an HTTP request (i.e., my response has the bytes of the mp3 file along other things that I want to display to the user).
My questions are:
- I want to save the mp3 locally (having some issues for that, see itinance/react-native-fs#309).
- I want to play it upon user request. Some questions here:
--- apparently, react-native-fs does not support Blob files (the accepted encoding options are utf8, base64 and ascii). How should I save the file in the disk to later open it with react-native-sound?
Thanks,
Fred
from react-native-sound.
@fredbt did you ever figure out how to play a downloaded and saved file?
from react-native-sound.
hello @bitfabrikken I ended up not saving the file, but always playing it from the network.
var sound = new Sound(myServerEndPoint() + filename, '', (error) => {
if (error) {
console.log(error)
}
})
<Button onPress={() => sound.play()}>
from react-native-sound.
Related Issues (20)
- setCategory() mixWithOthers boolean does not work HOT 3
- using new AvAudioPlayer feature fadeDuration issue. setVolume(1, {fadeDuration:3}) doesnt work it just plays at volume 1 immediately HOT 1
- Is there any audio puase/stop listener? HOT 2
- Fail to load sound in Android apk. { extra: -2147483648, what: 1 } HOT 1
- Audio plays as soon as an instance is created HOT 10
- Update import format to XCode 14.2 compat
- Audio after playing not stopped
- Sound.setCategory('Playback') not working
- Play function stops working after playing multiple videos HOT 1
- Playing the next track in the done callback of the play() function doesn't work HOT 1
- Can not build in Windows HOT 4
- It is not working on Ios version 16.6 HOT 2
- Uncaught Error: Cannot read property 'IsAndroid' of null HOT 2
- React Native 0.71.0 incompatibility HOT 1
- Include Guidelines for Allowing Assets in Audio Files
- Can't play sound from "App Group" paths.
- onEnd callback is not fired on Android if setSpeed() HOT 3
- × Build failed with message C:\Users\91626\Downloads\testwindowsapp\node_modules\react-native-sound\windows\RNSoundModule\RNSoundModule\RNSoundPackage.cs(1,7): error CS0246: The type or namespace name 'ReactNative' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\91626\Downloads\testwindowsapp\node_modules\react-native-sound\windows\RNSoundModule\RNSoundModule\RNSoundModule.csproj]. Check your build configuration. HOT 3
- delay between sounds played HOT 3
- Is there a software update plan? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-sound.