PhoneGap unable to getDuration() out of Media API, but other methods work

前端 未结 4 2264
[愿得一人]
[愿得一人] 2021-02-15 14:29

I\'m building out an audio media recorder/player with PhoneGap. It\'s all working beautifully, but I\'ve hit a wrinkle I can\'t seem to iron.

my_media.play();

4条回答
  •  不要未来只要你来
    2021-02-15 15:25

    The metadata for the media in question has not been loaded when you call my_media.getDuration(). In the documentation you referenced in your question the example code puts the getDuration call into an interval:

    var timerDur = setInterval(function() {
        counter = counter + 100;
        if (counter > 2000) {
            clearInterval(timerDur);
        }
        var dur = my_media.getDuration();
        if (dur > 0) {
            clearInterval(timerDur);
            document.getElementById('audio_duration').innerHTML = (dur) + " sec";
        }
    }, 100);
    

    I would recommend doing something similar.

提交回复
热议问题