Search code examples
ioscordovaionic-frameworkcordova-plugins

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?


Solution

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