Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

There is page with one div in which i set video to play.
now i have one problem that, i want to change that video on click on video name.
I am using javascript to set video on click of name.

I am using ytplayer and playing youtube video.
but its not changing video.

Please help me....

My Javascript Code is :-
HTML
<script type="text/javascript">
      /*
       * Polling the player for information
       */
       
      // Update a particular HTML element with a new value
      function updateHTML(elmId, value) {
        document.getElementById(elmId).innerHTML = value;
      }
      
      // This function is called when an error is thrown by the player
      function onPlayerError(errorCode) {
        alert("An error occured of type:" + errorCode);
      }
      
       // This function is called when the player changes state
      function onPlayerStateChange(newState) {
        updateHTML("playerState", newState);
      }

function onYouTubePlayerReady(playerId,video_ID,wt_title,wt_synopsis,wt_div_id,user_id)
      {
      //alert("hi" + wt_title);
            if(typeof(video_ID)=="string")
            {
                document.getElementById("lbl_title").innerHTML =wt_title;
                //alert(document.getElementById("lbl_title").innerHTML);
                //document.getElementById("ctl00_ContentPlaceHolder1_lbl_synopsis").innerHTML=wt_synopsis;
                document.getElementById("lbl_synopsis").innerHTML =wt_synopsis;
                document.getElementById("hidden_wt_div_id").value =wt_div_id;
                document.getElementById("hidden_user_id").value =user_id;
                document.getElementById("hidden_video_id").value =video_ID;
                //alert("Video ID is=" + video_ID);

                ytplayer = document.getElementById("ytPlayer");
                setInterval(updatePlayerInfo, 250);
                updatePlayerInfo();
                ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
                ytplayer.addEventListener("onError", "onPlayerError");

               //For Database entry
                var xmlhttp;
                if (window.XMLHttpRequest)      // code for IE7+, Firefox, Chrome, Opera, Safari
                {
                    xmlhttp=new XMLHttpRequest();
                }
                else if (window.ActiveXObject)      // code for IE6, IE5
                {
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                else
                {
                    ert("Your browser does not support XMLHTTP!");
                }
                xmlhttp.onreadystatechange = function()
                {
                    if(xmlhttp.readyState==4)
                    {
                    //alert(xmlhttp.responseText);
                    }
                }
                xmlhttp.open("POST","Wocktube_View_Ajax.aspx?reqWtDivID="+wt_div_id+"&reqUserID="+user_id+"&reqWtStatus=0",true);
                xmlhttp.send(null);
                //end database
            }
      }
<pre lang="cs">function loadPlayer(videoID) {

        //var videoID =  document.getElementById(&quot;hidden_video_id&quot;).value.toString();
        //var videoID = &quot;gFnkHHQHVX0&quot;;

        alert(&quot;Function load player VideoID= &quot; + videoID);
        var params = { allowScriptAccess: &quot;always&quot; , allowfullscreen: &quot;true&quot; };
        var atts = { id: &quot;ytPlayer&quot; };

        var strSWF=&quot;http://www.youtube.com/v/&quot; + videoID +&quot;?version=3&amp;enablejsapi=1&amp;playerapiid=player1&quot;;

        swfobject.embedSWF(&quot;http://www.youtube.com/v/&quot; + videoID +
                           &quot;?version=3&amp;enablejsapi=1&amp;playerapiid=player1&quot;,
                           &quot;videoDiv&quot;, &quot;360&quot;, &quot;270&quot;, &quot;9&quot;, null, null, params, atts);

      }
      function _run() {
        //loadPlayer();
      }
      google.setOnLoadCallback(_run);
    &lt;/script&gt;
Posted
Updated 15-Mar-13 1:53am
v4
Comments
sri senthil kumar 15-Mar-13 4:57am    
can u post the code what you have written so far, so that we can help you?
Sweetynewb 15-Mar-13 7:47am    
Please suggest me any solution..
sri senthil kumar 15-Mar-13 8:22am    
I havent used YTplayer. send me the url you got that. Will work on it and send you a solution ASAP.
Sweetynewb 15-Mar-13 9:14am    
Which url?
sri senthil kumar 15-Mar-13 9:30am    
I mean, just to get started. I want to check how the player code looks and i need to run it once :). After tht i can customize whatever the way you require.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900