简体   繁体   中英

Cordova media plugin seekTo doesn't work the first time

I'm playing an audio through the cordova-plugin-media using the seekTo method.

media.play();
media.seekTo(time);

In Android it works fine but in iOS the first time I play, it ignores the seekTo specified and starts at the beginning. If the same media object is played again it works fine.

If I delay the seekTo call it works:

setTimeout(function () {
  media.seekTo(time);
}, 100);

Using 100 ms, it seems to work always, but I don't like this approach.

Any insight?

Using a delay doesn't work always either.

I ended up listening to the Media.MEDIA_RUNNING status and calling seekTo from there.

It works fine now.

EDIT:

A snippet:

new Media(audio, function(){
    // Finished
  },
  function(){
    // Error
  },
  function(status){
    // State changed

    if (Media.MEDIA_RUNNING==status) {
        media.seekTo(start);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM