Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
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 :-
<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 14-Mar-13 21:40pm
Edited 15-Mar-13 2:53am
(no name)498.5K
v4
Comments
sri senthil kumar at 15-Mar-13 4:57am
   
can u post the code what you have written so far, so that we can help you?
Sweetynewb at 15-Mar-13 7:47am
   
Please suggest me any solution..
sri senthil kumar at 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 at 15-Mar-13 9:14am
   
Which url?
sri senthil kumar at 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.
Sweetynewb at 16-Mar-13 1:15am
   
https://developers.google.com/youtube/youtube_player_demo
 
https://developers.google.com/youtube/js_api_reference#Queueing_Functions
 
I just want to load new video on click of link..
sri senthil kumar at 16-Mar-13 4:22am
   
check this code whether it works... is this what you want?
 

<html>
<head></head>
<body>
 
<div id="player">
 
<object width="640" height="360">
<param name="movie" value="https://www.youtube.com/v/Zhawgd0REhA?version=3"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<embed src="https://www.youtube.com/v/Zhawgd0REhA?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed>
</object>
 
</div>
HTY dargon
despicable me 2
 
<script>
function changevideo(id)
{

var divObj = document.getElementById('player');
divObj.innerHTML = '<object width="640" height="360">'+
'<param name="movie" value="https://www.youtube.com/v/'+ id + '?version=3"></param>' +
'<param name="allowFullScreen" value="true"></param>'+
'<param name="allowScriptAccess" value="always"></param>'+
'<embed src="https://www.youtube.com/v/'+id+'?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed>'+
'</object>';
}
</script>
 
</body>
</html>
Sweetynewb at 16-Mar-13 6:15am
   
Thank you for try.. I solved that problem.

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

  Print Answers RSS
0 BillWoodruff 260
1 Mathew Soji 244
2 Afzaal Ahmad Zeeshan 232
3 OriginalGriff 231
4 Maciej Los 230
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100