getDuration() not working
I am trying to use getDuration() to determine when the user is at the end of their playback, but it is returning incorrect values. For example I have a 7 minute 12 second recording for which it should be returning something in the vicinity of 432 seconds, but it is currently returning approximately 410.5. This is on iOS, have not tested on Android. I know for sure the recording is 7 minutes and 12 seconds because I can sit there and listen to it, and watch the timer based on getCurrentTime() count all the way up..
EDIT: To add some more context for this, I was playing an .aac audio file recorded using the package react-native-audio
Do you have some code we can see?
I'm also experiencing an issue where getDuration() is not returning the correct length of an aac file recorded with react-native-audio.
loadRecording() {
let recordingFilePath = AudioUtils.DocumentDirectoryPath + "/" + this.props.recording.filename;
let soundFile = new Sound(recordingFilePath, '', (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
// loaded successfully
console.log('duration in seconds: ' + soundFile.getDuration() + ', number of channels: ' + soundFile.getNumberOfChannels());
});
}
I currently don't have a setup with react-native-audio, so it's a bit difficult for me to test it. I'll test it with a 'normal' aac-file, to see if it's happing with this also.
@dereksweet I believe we discussed something similar in #225 Does it help?
I have this issue on Android. It works fine on iOS, but on Android the call to getDuration() is returning -0.001 seconds. Any idea why?
+1
+1
I am having this same issue, I am using react-native-audio lib to record the audio. This is my audio config:
SampleRate: 22050,
Channels: 1,
AudioQuality: "Low",
AudioEncoding: "aac",
AudioEncodingBitRate: 32000
Audio recorded in android device works fine in both android and iOS devices, able to get duration for them. Audio recorded from iOS device works fine iOS device, but for same iOS recorded audio, I am not able to get duration while playing that in android(it give -0.001 seconds duration, which is default). Any idea how to solve this? Help appreciated. Thanks.
Could you post a link to an .aac file that exhibits the problem, along with code that demonstrates the problem?
Hi @paulmelnikow , this is the link for iPhone recorded audio: http://reantamchet.zluck.com/storage/app/audios/1562906494-1562906495986.aac
this is the record function:
async _record() {
AudioRecorder.prepareRecordingAtPath(audioPath, {
SampleRate: 22050,
Channels: 1,
AudioQuality: "Low",
AudioEncoding: "aac",
});
try {
const filePath = await AudioRecorder.startRecording();
} catch (error) {
console.log("error",error);
}
}
this is upload audio api function:
export const postRes = (token,course_id,id,answer,audio) => {
return new Promise((resolve,reject) => {
var params = new FormData();
params.append("audio",{uri: Platform.OS == 'ios' ? audio.split('file://')[1] : ('file://'+audio), type: 'audio/aac', name: new Date().getTime()+'.aac', filename : new Date().getTime()+'.aac'});
fetch(config.API_URL+`/courses/addanswer?`,{
method: 'post',
body : params,
headers: {
'authorization': 'Bearer '+token,
'accept': 'application/json',
},
})
.then(res => res.json())
.then(json => resolve(json))
.catch(e =>{
reject(error)
});
});
}
this is the play function:
play = async () => {
if(this.sound){
this.sound.play(this.playComplete);
this.setState({playState:'playing'});
}else{
const filepath = 'http://reantamchet.zluck.com/storage/app/audios/1562906494-1562906495986.aac;
this.sound = new Sound(filepath, '', (error) => {
if (error) {
console.log('failed to load the sound', error);
Alert.alert('Notice', 'audio file error. (Error code : 1)');
this.setState({playState:'paused'});
}else{
this.setState({playState:'playing', duration:this.sound.getDuration()});
this.sound.play(this.playComplete);
}
});
}
}
Seems it is still not resolved
Any news for this issue?
I have this issue on Android. It works fine on iOS, but on Android the call to getDuration() is returning -0.001 seconds. Any idea why?
same here, have you got the solution?
Issue is still here... Getting wrong values when using getDuration() of .aac file
I encountered this issue and wrote up a first attempt at fixing it. More information and caveats can be found in the PR: #784