当我的当前视频使用java脚本完成时,如何播放下一个视频?

时间:2016-01-03 03:22:30

标签: javascript

在这里,我根据当前时间成功播放视频,但是在根据当前时间完成当前视频后无法检索下一个视频。这里的源标签中的startat attribue是该视频的开始时间。

HTML

<video id="media-video" width="600" height="300">                   
    <source class="active" src="marimatrubhasha.mp4" id="videosource1" type="video/mp4" startat="00:00:00" endat="00:04:07" name="Gujarati Bhasha" description="This is Gujarati Video">                    
    <source class="active" src="php.mp4" id="videosource2" type="video/mp4" startat="00:04:07" endat="00:19:06" name="PHP Video 00:04:07" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource3" type="video/mp4" startat="00:19:06" endat="00:34:05" name="PHP Video" description="This is PHP Video">                   
    <source class="active" src="php.mp4" id="videosource4" type="video/mp4" startat="00:34:05" endat="00:49:04" name="PHP Video" description="This is PHP Video">                   
    <source class="active" src="marimatrubhasha.mp4" id="videosource5" type="video/mp4" startat="00:49:04" endat="00:53:11" name="Gujarati Bhasha" description="This is Gujarati Video">                    
    <source class="active" src="php.mp4" id="videosource6" type="video/mp4" startat="00:53:11" endat="01:08:10" name="PHP Video" description="This is PHP Video">                   
    <source class="active" src="php.mp4" id="videosource7" type="video/mp4" startat="01:08:10" endat="01:23:09" name="PHP Video" description="This is PHP Video">                   
    <source class="active" src="php.mp4" id="videosource8" type="video/mp4" startat="01:23:09" endat="01:38:08" name="PHP Video" description="This is PHP Video">                   
    <source class="active" src="php.mp4" id="videosource9" type="video/mp4" startat="01:38:08" endat="01:53:07" name="PHP Video" description="This is PHP Video">                   
    <source class="active" src="php.mp4" id="videosource10" type="video/mp4" startat="01:53:07" endat="02:08:06" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource11" type="video/mp4" startat="02:08:06" endat="02:23:05" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource12" type="video/mp4" startat="02:23:05" endat="02:38:04" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource13" type="video/mp4" startat="02:38:04" endat="02:53:03" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource14" type="video/mp4" startat="02:53:03" endat="03:08:02" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource15" type="video/mp4" startat="03:08:02" endat="03:23:01" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource16" type="video/mp4" startat="03:23:01" endat="03:38:00" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource17" type="video/mp4" startat="03:38:00" endat="03:52:59" name="3.38 PHP Video" description="This is PHP Video to be played on 3.38">                    
    <source class="active" src="php.mp4" id="videosource18" type="video/mp4" startat="03:52:59" endat="04:07:58" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource19" type="video/mp4" startat="04:07:58" endat="04:22:57" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource20" type="video/mp4" startat="04:22:57" endat="04:37:56" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource21" type="video/mp4" startat="04:37:56" endat="04:52:55" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource22" type="video/mp4" startat="04:52:55" endat="05:07:54" name="PHP Video" description="This is PHP Video">
    <source class="active" src="php.mp4" id="videosource23" type="video/mp4" startat="05:07:54" endat="05:22:53" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource24" type="video/mp4" startat="05:22:53" endat="05:37:52" name="php" description="PHP Video to be played at 5.37">                   
    <source class="active" src="php.mp4" id="videosource25" type="video/mp4" startat="05:37:52" endat="05:52:51" name="PHP Video to be played at 5.37" description="This is PHP Video">                 
    <source class="active" src="php.mp4" id="videosource26" type="video/mp4" startat="05:52:51" endat="06:07:50" name="PHP Video to be played on 5.52" description="PHP Video to be played on 5.52">                    
    <source class="active" src="php.mp4" id="videosource27" type="video/mp4" startat="06:07:50" endat="06:22:49" name="PHP Video to be played on 6.07" description="This is PHP Video">                 
    <source class="active" src="php.mp4" id="videosource28" type="video/mp4" startat="06:22:49" endat="06:37:48" name="PHP Video to be played on 6.22" description="This is PHP Video">                 
    <source class="active" src="php.mp4" id="videosource29" type="video/mp4" startat="06:37:48" endat="06:52:47" name="PHP Video to be played on 6.37" description="This is PHP Video">                 
    <source class="active" src="php.mp4" id="videosource30" type="video/mp4" startat="06:52:47" endat="07:07:46" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource31" type="video/mp4" startat="07:07:46" endat="07:22:45" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource32" type="video/mp4" startat="07:22:45" endat="07:37:44" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource33" type="video/mp4" startat="07:37:44" endat="07:52:43" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource34" type="video/mp4" startat="07:52:43" endat="08:07:42" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource35" type="video/mp4" startat="08:07:42" endat="08:22:41" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource36" type="video/mp4" startat="08:22:41" endat="08:37:40" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource37" type="video/mp4" startat="08:37:40" endat="08:52:39" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource38" type="video/mp4" startat="08:52:39" endat="09:07:38" name="PHP Video" description="This is PHP Video">                  
    <source class="active" src="php.mp4" id="videosource39" type="video/mp4" startat="09:07:38" endat="09:22:37" name="PHP Video" description="This is PHP Video">                          
</video>

Java脚本

  $(document).ready(function(){
            var mediaPlayer = document.getElementById('media-video');
             var videosource=document.getElementById('source');
            var Startvideo = mediaPlayer.querySelectorAll('source[startat]');   
            if (mediaPlayer.paused || mediaPlayer.ended) {
                // Change the button to be a pause button
                changeButtonType(playPauseBtn, 'pause');
                // Play the media
                //mediaPlayer.play();
                var d=new Date();       
                var hh=d.getHours();        
                var mm=d.getMinutes();      
                var ss=d.getSeconds();
                var timeString = ((hh < 10) ? "0" : "") + hh;
                timeString  += ((mm < 10) ? ":0" : ":") + mm;
                timeString  += ((ss < 10) ? ":0" : ":") + ss;
                console.log(timeString);        
                var currentTime=timeString;
                console.log('current  time is '+currentTime);       
                Array.prototype.forEach.call(Startvideo, function(elem) {        
                var getStartTime = elem.getAttribute('startat');        
                console.log('start time is '+ getStartTime )                
                     if(getStartTime <= currentTime && elem.getAttribute('endat') >= currentTime){                      
                    var currentTimeSecond=currentTime.split(':');
                    var getStartTimeSecond=getStartTime.split(':');         
                    var TimeSecondsCurrent = (+currentTimeSecond[0]) * 60 * 60 + (+currentTimeSecond[1]) * 60 + (+currentTimeSecond[2]);
                    console.log(TimeSecondsCurrent);
                    var TimeSecondsGetStart= (+getStartTimeSecond[0]) * 60 * 60 + (+getStartTimeSecond[1]) * 60 + (+getStartTimeSecond[2]); 
                    console.log(TimeSecondsGetStart);
                    var totalSeconds= TimeSecondsCurrent - TimeSecondsGetStart;             
                    console.log(totalSeconds);
                    var c=elem.getAttribute('src');         
                    mediaPlayer.src = c;
                    mediaPlayer.currentTime= totalSeconds;  
                    mediaPlayer.play();
                }       
              }); 
            }               
        });

1 个答案:

答案 0 :(得分:1)

以下是实现此目的的代码。

Post.select("((upvotes_count + 1 + random + 1.9208) / (upvotes_count + downvotes_count + 2) - " + "1.96 * SQRT(((upvotes_count + 1 + random) * (downvotes_count + 1)) / (upvotes_count + downvotes_count + 2) + 0.9604) / " + "(upvotes_count + random + downvotes_count + 2)) / (1 + 3.8416 / (upvotes_count + random + downvotes_count + 2)) " + "AS ci_lower_bound, posts.*") 会读取loadVideo()代码的startat属性。

这些来源维护在隐藏的source内。视频结束后,下一个视频会加载并写入div标记。

video