使用javascript和PHP连续播放视频

时间:2018-04-11 05:47:09

标签: javascript php

我有一个我想要运行的视频名称列表 但不知道如何一个接一个地自动运行视频

function theFunction(video_id,user_id){
    var user_id1=$('#video_lesson_'+video_id).val();
    $.ajax({
                url:'video_selection.php',
                type:'POST',
                dataType:'json',
                 data: {'user_id1':user_id1,'video_id':video_id},
                success: function (data) {
                    var text="";
                    for (var i =0; i <= data.length; i++) {
                        var source="uploads/"+data[i];
                        var source1="uploads/"+data[i+1];
                       $("a[href='source']").attr('href', 'source1');

                    }


                }
            });
}

这是我的Html代码

 <a  video_id="<?php echo $f['id']; ?>" user_id="<?php echo $rows['id'];?>"   onclick="theFunction(this.getAttribute('video_id','user_id'))"  href="uploads/<?php echo $f['file_path'];?>" class="popup-youtube start-btn "><span>Start</span></a>

3 个答案:

答案 0 :(得分:0)

您应该sourcesource1作为变量,但是您在单引号内使用,因此这些被视为字符串。

替换此行

$("a[href='source']").attr('href', 'source1');

到这个

$("a[href='"+source+"']").attr('href', source1);

答案 1 :(得分:0)

File f = new File("route.txt");
Scanner s = new Scanner(new FileInputStream(f));
s.useDelimiter("]],");
while (s.hasNext()) {
    String r = s.next();
    System.out.println(r);
}

答案 2 :(得分:0)

我已经创建了如下示例代码,它可能会对您有所帮助:

<video width="256" height="192"  id="myVideo" controls autoplay>
    <source src="" id="mp4Source" type="video/mp4">
    Your browser does not support the video tag.
</video>

<script type="text/javascript">
    var i = 0;
    var videoCount = 0;
    var player = document.getElementById('myVideo');
    var mp4Vid = document.getElementById('mp4Source');
    var arr_video = new Array();

    $.ajax({
        url:'video_selection.php',
        type:'POST',
        dataType:'json',
        data: {'user_id1':user_id1,'video_id':video_id},
        success: function (data) {
            if (data != 'undefined') {
                arr_video = data;
                videoCount = arr_video.length;              
                videoPlay(0);
                player.addEventListener('ended', myHandler, false);
            }
        }
    });

     // Set video source and start autoplay     
    function videoPlay(num) {
        $(mp4Vid).attr('src', "/uploads/" + arr_video[num]);
        player.load();
        player.play();
   }

   // Continuously play videos one after another
   function myHandler() {
    i++;
    if(i == (videoCount - 1)){
        i = 0;
        videoPlay(i);
    }
    else{
        videoPlay(i);
    }
   }
</script>