Giter Club home page Giter Club logo

Comments (9)

bitfabrikken avatar bitfabrikken commented on July 21, 2024 4

@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.

jadsonlourenco avatar jadsonlourenco commented on July 21, 2024 2

@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.

azizijunaid-zz avatar azizijunaid-zz commented on July 21, 2024 2
DocumentDirectoryPath 

DocumentDirectoryPath path already contains /files/

from react-native-sound.

zmxv avatar zmxv commented on July 21, 2024

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.

huangzuizui avatar huangzuizui commented on July 21, 2024

@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.

skizzo avatar skizzo commented on July 21, 2024

(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..
screen shot 2016-04-28 at 15 14 27

from react-native-sound.

fredbt avatar fredbt commented on July 21, 2024

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.

bitfabrikken avatar bitfabrikken commented on July 21, 2024

@fredbt did you ever figure out how to play a downloaded and saved file?

from react-native-sound.

fredbt avatar fredbt commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.