react-native-sound
react-native-sound copied to clipboard
getDuration() returns negative values for network files - android only
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
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
Could you post your code, please?
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);

Maybe it’s a problem with that sound file? Can you post the file or the link?
I have the same issue with a sound file of 12 sec, but not with longer files (28 min).
@paulmelnikow its not one particular file, all the files have the same issue. You can try with this link https://tinyurl.com/y4bycu3s
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
Here also the same problem
same here
@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 any updates? are you able to reproduce this issue on your end?
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,
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.
hey.I got this problem . Have solved it?
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 .
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)
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 your solution seems working indeed. I got the duration of 0 seconds while converting to constant bit rate, I got the actual one.
@Mikenso Thanks, man!! That works and in consequence solved the #646 issue for me. Awesome!!
@ralcant I'm facing the same issue, have you solved it?