2017-07-15 42 views
0

如何在更改視頻後強制克萊普播放器保持全屏顯示? 我編寫的PLAYER_ENDED事件觸發的函數,函數加載下一個視頻與此load方法:全屏幕不能與克拉普播放器一起工作

enter code here`enter code here`player.load([{source: 'video_url_exmpl'}], null, true); 

但是,當觸發事件和新的視頻播放器加載取消全屏模式。我設置選項:

exitFullscreenOnEnd: false, 

我寫的假設切換全屏,但瀏覽器拋出一個警告信息插件:

Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture 

這裏是我的Clappr播放器初始化和設置:

player = new Clappr.Player({ 
     source: sourceUrl, 
     parentId: "#player", 
     autoPlay: true, 
     width: '100%', 
     height: '100%', 
     exitFullscreenOnEnd: false, 
     playInline: true, 
     recycleVideo: Clappr.Browser.isMobile, 
     poster: '', 
    }).on(Clappr.Events.PLAYER_ENDED, function() { 
      player.load([{source: 'video_url'}], null, true); 
      } 
    }); 

回答

1

在官方Clappr GitHub問題上找到臨時解決方案。感謝kslimani

var player = new Clappr.Player({ 
    parentId: "#player-wrapper", 
    source: 'http://clappr.io/highline.mp4', 
    height: 360, 
    width: 640, 
    exitFullscreenOnEnd: false, 
    playback: { 
    playInline: true, 
    recycleVideo: true, 
    }, 
    events: { 
    onEnded: function() { 
     var setSource = function (newSrc) { 
     this.core.options.source = newSrc; 
     var container = this.core.getCurrentContainer(); 
     var playback = this.core.getCurrentPlayback(); 
     if (container) { 
      container.options.source = newSrc; 
     } 
     if (playback) { 
      playback.options.source = newSrc; 
      playback._setupSrc && playback._setupSrc(newSrc); 
     } 
     }.bind(this); 

     // Set another .mp4 source and start again player 
     setSource('https://static.playmedia-cdn.net/resources/sample/h264_sintel_trailer-1080p.mp4'); 
     this.play(); 
    } 
    } 
}); 

請注意,這個代碼是一個醜陋的技巧可以讓某些狀態不一致的播放器組件(如插件)。只有源文件格式相同時(即:所有源文件都是.mp4文件),才能進行此項工作。 但應該給你一些提示,從哪裏開始挖掘。 Link on Clappr GitHub threat