我有一个问题,我两个星期都无法解决。我使用jQuery ui Widgets渲染引导轮播。在那些轮播中,我渲染了高质量的视频。并且如果页面上的视频元素很多,标题中的video会停止加载并引发onAbort事件。我的播放功能看起来像

play: function() {
        var widget = this;
        var videoElement = widget._getVideoElement();
         if(!widget.options.isMobile.iOS){
        videoElement.attr('autoplay', 'true');
        widget._getVideoElementNative().play();
        widget._setPlayIcon('stop');
        widget.options.isPlaying = true;

        if (!widget.options.canPlay) {
            widget._getLoadingIcon().show();
        } else {
            widget._getPosterElement().hide();
         }
        }
        else{ //videoplay for iOS devices
             widget._getVideoElementNative().currentTime = 0.1;
    if(widget._getVideoElementNative().readyState !== 4){
        widget._getVideoElementNative().addEventListener('canplaythrough', onCanPlayVideo, false);
        widget._getVideoElementNative().addEventListener('load', onCanPlayVideo, false); //add load event as well to avoid errors, sometimes 'canplaythrough' won't dispatch.
        setTimeout(function(){
        widget._getVideoElementNative().pause(); //block play so it buffers before playing
    }, 1); //it needs to be after a delay otherwise it doesn't work properly.
   }
   else
   {
       widget._getVideoElementNative().play();
   }
  }

},
     onCanPlayVideo: function(){
widget._getVideoElementNative().removeEventListener('canplaythrough', onCanPlay, false);
widget._getVideoElementNative().removeEventListener('load', onCanPlay, false);
//video is ready
widget._getPosterElement().hide();
widget._getVideoElementNative().play();

},

最佳答案

我通过用jQuery动态注入视频元素解决了问题。现在,当页面加载时,没有视频元素,但是当用户单击“播放”时,我创建了一个特定元素并将其设置为播放。正在this answer

关于ios - play()onabort iphone Safari,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41826333/

10-10 22:57