Audio 我怎样才能在爱奥尼亚中获得记录的文件长度?
我正在使用ionic cordova媒体插件录制用户手机中的音频。一旦录制好,我就可以播放文件,一切都很好。我只想得到文件的持续时间,当我播放录制的文件时,我想显示正在播放的文件的分钟数::秒数。我该怎么做Audio 我怎样才能在爱奥尼亚中获得记录的文件长度?,audio,ionic-framework,media,Audio,Ionic Framework,Media,我正在使用ionic cordova媒体插件录制用户手机中的音频。一旦录制好,我就可以播放文件,一切都很好。我只想得到文件的持续时间,当我播放录制的文件时,我想显示正在播放的文件的分钟数::秒数。我该怎么做 record_audio(){ this.file.startRecord(); this.recording = true; /* let record_opt: CaptureAudioOptions = { limit: 1 }; thi
record_audio(){
this.file.startRecord();
this.recording = true;
/*
let record_opt: CaptureAudioOptions = { limit: 1 };
this.mediacapture.captureAudio(record_opt).then(
(data: MediaFile[]) => alert('audio recorded'),
(err: CaptureError)=> alert('cannot record')
);
*/
}
cancel_record(){
this.file.release();
this.show_record_div = false;
this.recordedfile_available = false;
}
stop_recording(){
this.file.stopRecord();
this.recording = false;
this.recordedfile_available = true;
//this.filelength = this.file.getDuration();
}
play_recorded(){
this.file.play();
}
stop_playing(){
this.file.stop();
}
试试这个
let duration = this.file.getDuration();
console.log(duration);
// get current playback position
file.getCurrentPosition().then((position) => {
console.log(position);
});
谢谢您的回复。。我这么做了,但第一次录制时只显示-1。第二次录制时,可以看到持续时间。