如何获得离子中记录的文件长度?

时间:2017-07-22 06:49:41

标签: audio ionic-framework media

我正在使用离子cordova媒体插件来录制来自用户手机的音频。一旦录制我得到文件播放,一切都很好。我只想获得文件的持续时间,当我播放录制的文件时,我想显示正在播放的文件的分钟::秒。我怎么做?

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();
}

1 个答案:

答案 0 :(得分:0)

试试这个。

let duration = this.file.getDuration();
  console.log(duration);
// get current playback position
file.getCurrentPosition().then((position) => {
    console.log(position);
});