IsidroGH IsidroGH - 1 year ago 127
iOS Question

Cordova media plugin seekTo doesn't work the first time

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

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

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

Any insight?

Answer Source

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.


A snippet:

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

    if (Media.MEDIA_RUNNING==status) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download