简体   繁体   English

科尔多瓦媒体插件seekTo第一次无法使用

[英]Cordova media plugin seekTo doesn't work the first time

I'm playing an audio through the cordova-plugin-media using the seekTo method. 我正在使用seekTo方法通过cordova-plugin-media播放音频。

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. 在Android中,它工作正常,但是在iOS中,当我第一次玩游戏时,它会忽略指定的seekTo并从头开始。 If the same media object is played again it works fine. 如果再次播放同一媒体对象,它将正常工作。

If I delay the seekTo call it works: 如果我延迟seekTo调用,它将起作用:

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

Using 100 ms, it seems to work always, but I don't like this approach. 使用100 ms,它似乎总是可以工作,但是我不喜欢这种方法。

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. 我最终听了Media.MEDIA_RUNNING状态并从那里调用seekTo

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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