videojs播放列表playbackRate在新视频加载时不会保留

时间:2017-03-02 15:33:47

标签: javascript video.js

我已成功使用videojs和videojs播放列表插件组合了一个视频播放列表。播放视频时,如果您将播放速率从1更改为2,当视频自动前进到列表中的下一个视频时,playbackRate默认返回1,您必须重新调整它。问题是你如何使playbackRate持续存在?

虽然我可以获得playbackRate并设置playbackRate,但我无法继续播放。除了将其写入隐藏的div之外,还有更优雅的解决方案吗?

我有以下代码:

// JavaScript Document

var videoList = [{
  sources: [{
    src: 'http://localhost/gpifmlocal/publichtml/eUFM/1_intro.mp4',
    type: 'video/mp4'
  }],
  poster: ''
  },{
  sources: [{
    src: 'http://localhost/gpifmlocal/publichtml/eUFM/2_UFM_barter.mp4',
    type: 'video/mp4'
  }],
  poster: ''
  },{
  sources: [{
    src: 'http://localhost/gpifmlocal/publichtml/eUFM/3_UFM_goldsmith.mp4',
    type: 'video/mp4'
  }],
  poster: ''
  } ];

var player = videojs(document.querySelector('video'), {
  inactivityTimeout: 0
});

 player.playlist(videoList);

 document.querySelector('.previous').addEventListener('click', function() {

      var playing  = player.playlist.currentItem();

      player.playlist.currentItem(playing -1);
});

document.querySelector('.next').addEventListener('click', function() {

   var playing  = player.playlist.currentItem();
   player.playlist.currentItem(playing +1); 

    });  

  var onlinevideo =document.querySelectorAll('.onlinevideo');

     for(var i=0;i<onlinevideo.length;i++){
     onlinevideo[i].addEventListener('click',videonumber);
     }

 function videonumber(){
  var vid = parseInt($(this).attr('data-vid'));
    if (!player.play()) {
      player.play();
      }else{
      player.playlist.currentItem(vid);

     // var playrate = parseFloat(player.playbackRate());   

      // player.playbackRate(playrate);

 } 
  $(this).css('color','green');

 }

 var endvideo = document.getElementsByTagName("video")[0];

   endvideo.addEventListener("ended", function() { 

   var playing  = player.playlist.currentItem();

    $('a[data-vid]').each(function() {
    var vid = parseInt($(this).attr('data-vid'))

      if (vid ==playing){
        $(this).css('color','green');
    }
  });

  }, true);


  player.playlist.autoadvance(JSON.parse(0));

1 个答案:

答案 0 :(得分:2)

很多道歉,如果你的狗足够深,可以链接到api中的所有方法和事件:https://github.com/brightcove/videojs-playlist/blob/master/docs/api.md#playlistitem

因此,为了回答我的问题,我只是使用了:

var playrate;
player.on('beforeplaylistitem', function() {
  playrate = player.playbackRate();

  });

 player.on('playlistitem', function() {
   player.playbackRate(playrate);
 });