zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

getDuration() returns negative values for network files - android only #607

Open meghaptg opened 5 years ago

meghaptg commented 5 years ago

Actually I am trying to Load sound from the network. Its works in iOS. But not in android. I'm getting duration as -0.001 in it

Screenshot 2019-08-14 at 8 03 33 PM

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

paulmelnikow commented 5 years ago

Could you post your code, please?

meghaptg commented 5 years ago
 setTimeout(() => {
      console.log('the audiopath being passed to sound library');
      this.sound = new Sound(this.props._audioPath, '', error => {
        if (error) {
          console.log('failed to load the sound : ', error);
        } else {
          console.log('successfully loaded : ', this.sound); 
// image attached below is from this console.log
          this.setState({ loading: false, getDuration: this.sound.getDuration() });
          // if (startPlaying) {
            this.startPlaying();
          // }
        }
      });
    }, 100);
Screenshot 2019-08-14 at 8 03 33 PM
paulmelnikow commented 5 years ago

Maybe it’s a problem with that sound file? Can you post the file or the link?

andrespi commented 5 years ago

I have the same issue with a sound file of 12 sec, but not with longer files (28 min).

meghaptg commented 5 years ago

@paulmelnikow its not one particular file, all the files have the same issue. You can try with this link https://tinyurl.com/y4bycu3s

ralcant commented 5 years ago

This is also a problem with require statements. I am using RN 0.59.8

When i run the code

    var whoosh = new Sound(require('./assets/sounds/test2.mp3'), (error) =>{
      if (error){
        console.log("sad")
        return 
      }
      console.log('duration in seconds: ' + whoosh.getDuration() + 'number of channels: ' + whoosh.getNumberOfChannels());

      whoosh.play()
    })

I get the following output:

duration in seconds: -0.001number of channels: -1

arjunghimire commented 4 years ago

Here also the same problem Screenshot from 2019-08-29 10-15-35

hsnMoghadasi commented 4 years ago

same here

paulmelnikow commented 4 years ago

@ralcant @arjunghimire @hsnMoghadasi Can you open new issues that include your code? Having more replicable examples will help, because it helps to validate a fix.

meghaptg commented 4 years ago

@paulmelnikow any updates? are you able to reproduce this issue on your end?

paulmelnikow commented 4 years ago

I haven't had time to try, sorry! One thing that I think would help a lot with this kind of thing is #589, because problems like this could easily be demonstrated with PRs to the sample app.

creativemind1 commented 4 years ago

@paulmelnikow,

Today I ejected from expo. I found duration is displaying negative in Android though iOS is working fine. Would you help us rectifying the issue or guide somewhere to fix it. Your demo too causing issue.

linyangcong commented 4 years ago

hey.I got this problem . Have solved it?

creativemind1 commented 4 years ago

I noticed this problem only occurring when we are using local files but it is working fine when fetching from the server.

On Sun, Dec 29, 2019, 8:03 PM linyangcong notifications@github.com wrote:

hey.I got this problem . Have solved it?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zmxv/react-native-sound/issues/607?email_source=notifications&email_token=ABH54CLR6AFP3NOWUUTIKADQ3CYNFA5CNFSM4IMEKWKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHZAYRQ#issuecomment-569510982, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABH54CJ445SYPMX6FAKML4LQ3CYNFANCNFSM4IMEKWKA .

linyangcong commented 4 years ago

emmm,as you said,I have tried to put the video on the server and it worked. in the meantime,i found the video cannot be mp3,otherwise it will not work ,even report an error!(Android)

Mikenso commented 4 years ago

Recently I discovered that some audio files can show different durations on different devices. So it was not this library bug. The only way to fix it - to format audio files to files with "constant bit rate". In my case I used "Audacity" on mac to fix it

huseyin39 commented 3 years ago

@Mikenso your solution seems working indeed. I got the duration of 0 seconds while converting to constant bit rate, I got the actual one.

Harukisatoh commented 2 years ago

@Mikenso Thanks, man!! That works and in consequence solved the #646 issue for me. Awesome!!

Dev-Ahmed-Adnan commented 1 year ago

@ralcant I'm facing the same issue, have you solved it?