react-native-sound icon indicating copy to clipboard operation
react-native-sound copied to clipboard

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

Open meghaptg opened this issue 5 years ago • 19 comments

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

  • [ ] iOS
  • [x] Android
  • [ ] Windows

Are you using...

  • [x] React Native CLI (e.g. react-native run-android)
  • [ ] Expo
  • [ ] Other: (please specify)

Which versions are you using?

  • React Native Sound:0.10.9, 0.11.0
  • React Native:0.59.3
  • iOS: works fine on iOS
  • Android:7, 7.1, 8, 9
  • Windows: not implementing in windows

Does the problem occur on...

  • [x] Simulator
  • [x] Device

meghaptg avatar Aug 16 '19 06:08 meghaptg

Could you post your code, please?

paulmelnikow avatar Aug 16 '19 09:08 paulmelnikow

 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

meghaptg avatar Aug 16 '19 09:08 meghaptg

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

paulmelnikow avatar Aug 16 '19 09:08 paulmelnikow

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

andrespi avatar Aug 16 '19 15:08 andrespi

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

meghaptg avatar Aug 19 '19 10:08 meghaptg

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

ralcant avatar Aug 19 '19 19:08 ralcant

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

arjunghimire avatar Aug 29 '19 04:08 arjunghimire

same here

hsnMoghadasi avatar Aug 29 '19 14:08 hsnMoghadasi

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

paulmelnikow avatar Aug 29 '19 14:08 paulmelnikow

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

meghaptg avatar Aug 30 '19 03:08 meghaptg

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.

paulmelnikow avatar Aug 30 '19 04:08 paulmelnikow

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

creativemind1 avatar Oct 08 '19 22:10 creativemind1

hey.I got this problem . Have solved it?

linyangcong avatar Dec 29 '19 14:12 linyangcong

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 [email protected] 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 .

creativemind1 avatar Dec 29 '19 17:12 creativemind1

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)

linyangcong avatar Dec 30 '19 04:12 linyangcong

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

Mikenso avatar May 21 '20 02:05 Mikenso

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

huseyin39 avatar Apr 03 '21 14:04 huseyin39

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

Harukisatoh avatar Aug 02 '22 21:08 Harukisatoh

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

Dev-Ahmed-Adnan avatar Mar 15 '23 13:03 Dev-Ahmed-Adnan