How to change the video playing in Youtube embedde

2020-07-23 08:37发布

I'd like to make a playlist, where a click on each <li> will change the video link just below. The list will look like this:

  • video1

    <li><a href="MzfAvHlIVjE&hl=en&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999">">video1</a></li>
    
  • bbbbb

  • ccccc

video player here


So clicking on aaaaa will play aaaaa , clicking on bbbbb will play bbbbb, etc.

I'd like to make it ajax, without redraw, just clic and play.

Here is the youtube object to edit

<object width="320" height="265">
  <param name="movie" value="http://www.youtube.com/v/MzfAvHlIVjE&hl=en&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999"></param>
  <param name="allowFullScreen" value="true"></param>
  <param name="allowscriptaccess" value="always"></param>
  <embed src="http://www.youtube.com/v/MzfAvHlIVjE&hl=en&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed>
</object>

How can I change the video playing in Youtube embedded player ?

7条回答
时光不老,我们不散
2楼-- · 2020-07-23 08:52

check out the jQuery TubePlayer Plugin --

the plugin handles the player initialization for you and you'd be able to get full control of the player.. allowing you to put jQuery("#player").tubeplayer("play", "[videoId]") on the event handler on your li's..

查看更多
【Aperson】
3楼-- · 2020-07-23 08:55

I have something that worked for me:

In head:

    <script type="text/javascript" src="../../../Assets/js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript"> 
        $(document).ready(function(){
            $(".button").click(function() {
            $("#playvideo").html(play(  $(this).find("a").attr("linkattr")));           
            return false; 
            });
        });
    function play(id)   {
           var html  = '';     
           html += '<iframe width="671" height="495" src="'+id+'" frameborder="0" allowfullscreen></iframe>';
           return html;
        };  
    </script>

In body:

    <h2 class="button"><a linkattr="https://www.youtube.com/embed/uopXg6NxboQ?rel=0&amp;showinfo=0" href="#"> video 1 </a></h2>
    <h2 class="button"><a linkattr="https://www.youtube.com/embed/h-v1c2kNw70?rel=0&amp;showinfo=0" href="#"> video 2 </a></h2>

    <div id="playvideo">
          <iframe width="671" height="495" src="https://www.youtube.com/embed/uopXg6NxboQ?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
    </div>

See this page for result: https://cllccavo.asc.ohio-state.edu/Public/Modules/help/howto.php

查看更多
劫难
4楼-- · 2020-07-23 08:58

Look at the jquery youtube plugin: http://saidur.wordpress.com/2007/12/03/jquery-youtube-beta-plugin/

You have a demo here:

http://bijon.rightbrainsolution.com/youtube/video.html

Exact the same interface as you need, after you searched the videos. (So you can get rid of searching feature)

Hope this helps.

查看更多
Lonely孤独者°
5楼-- · 2020-07-23 09:06

If you dun like the popup just get rid of it:

function play(id)
    {
       var html  = '';

       html += '<object >';
       html += '<param name="movie" value="http://www.youtube.com/v/'+id+'"></param>';
       html += '<param name="autoplay" value="1">';
       html += '<param name="wmode" value="transparent"></param>';
       html += '<embed src="http://www.youtube.com/v/'+id+'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" ></embed>';
       html += '</object>';

       return html;
    };

<div id="button1" />
<div id="playvideo" />

$("#button1").click(function() { $("#playvideo").html(play("YOURVIDEOID")); });

Hope this helps

查看更多
迷人小祖宗
6楼-- · 2020-07-23 09:09

here is the final solution :

http://www.studioteknik.com/youtube/index2.html

here is the final code :

<script type="text/javascript"> 
    $(document).ready( function(){
        $(".button").click(function() {
        console.log($(this).find("a").attr("href"));
        $("#playvideo").html(play($(this).find("a").attr("href"))); 
        return false; 
        });
    });
</script>

</head>

<body>

<div>
  <ul>
    <li class="button"><a href="MzfAvHlIVjE&hl=en&fs=1">Video 1</a></li>
    <li class="button"><a href="uN2OGjsLuY8&hl=en&fs=1">Video 2</a></li>
    <li class="button"><a href="EZOTMcqaH98&hl=en&fs=1">Video 3</a></li>
    <li class="button"><a href="PSTDZEZV72Q&hl=en&fs=1">Video 4</a></li>
    <li class="button"><a href="QYlOaoqgMdw&hl=en&fs=1">Video 5</a></li>
    <li class="button"><a href="GEcBhbXEFz8&hl=en&fs=1">Video 6</a></li>
    <li class="button"><a href="cU6sJ0CQWAc&hl=en&fs=1">Video 7</a></li>
    </ul>
</div>
查看更多
Fickle 薄情
7楼-- · 2020-07-23 09:09

Marc-Andre Menard - can you modify the script so that one of the videos automatically loads on page load?

查看更多
登录 后发表回答