【问题标题】:how can i get the recorded file length in ionic?如何在离子中获取记录的文件长度?
【发布时间】:2017-07-22 18:59:34
【问题描述】:

我正在使用 ionic 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();
}

【问题讨论】:

    标签: audio ionic-framework media


    【解决方案1】:

    试试这个。

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

    【讨论】:

    • 感谢@enRaiser 的回复。我这样做了,但它只在我第一次录制时显示-1。我第二次录制然后可以看到持续时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-31
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多