play()onabort iphone safari

时间:2017-01-24 10:54:48

标签: ios iphone video abort

我有一个问题,我无法解决两个星期。我使用jQuery ui Widgets来渲染bootstrap轮播。在那些旋转木马中,我渲染高质量的视频。如果页面上有很多视频元素,则标题中的视频会停止加载并抛出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();

},

1 个答案:

答案 0 :(得分:0)

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