JavaScript - Dynamically Embedding Youtube Video
see below
Similar TutorialsHello, This question is not really about js per se, but more having to do with w3c specifications. I did not see a more appropriate place to post it. I wish there were such a thing as a w3c forum. I have a large number of QT movies in an archive that I have been displaying using the ol' object/embed tag method. In an attempt to bring the pages up to w3 standards, which does not allow embed tags, I have considered this recommendation from Apple for embedding QT videos: http://developer.apple.com/internet/ieembedprep.html Great, now the pages validate. However, when viewing the generated source written by the js, what do I find? Exactly the same code I used that would not validate - object tags with an embed tag in the container. My question may be somewhat philosophical : Is this just merely a way of "tricking" the w3 validator? I mean, if the effective code that the browser sees is the same, why not just put it in there with HTML in the first place, other than to be able to put the w3 'validates!' icon at the bottom of the page? You see what I am getting at? Hi, I started with the template on this site: http://www.pupinc.com/videobox/ However, I have about a dozen videos with more to come so I added a vertical scrollbar to navigate through the thumbnails. My problem is I don't know how to separate the main video player so that it doesn't scroll with the thumbnails. HTML: Code: <div id="middle4"> <div class="videobox" style="height: 360px; overflow-y: scroll;"> <ul> <li><a href="http://www.youtube.com/watch?v=iFGEHtqNZis">TRS 50X35</a></li> <li><a href="http://www.youtube.com/watch?v=9CaN2KBYpo8">98X104 Automobile Shredder</a></li> <li><a href="http://www.youtube.com/watch?v=BWHXX6u3tVk">60x60 Aluminum</a></li> <li><a href="http://www.youtube.com/watch?v=ZiWDKtdfqWQ">60X60 System</a></li> <li><a href="http://www.youtube.com/watch?v=VMbbXcFju9E">Portable Shredding System</a></li> <li><a href="http://www.youtube.com/watch?v=WEn5xtJwtu4">60X85 System</a></li> <li><a href="http://www.youtube.com/watch?v=1cOxYQB5icg">60X60 White Goods</a></li> </ul> </div> </div> JS: Code: // Videobox object VideoBox = Class.create(); VideoBox.prototype = { // Initialize object. initialize: function(index, item) { this.index = index; this.item = item; this.item.addClassName('videoboxjs'); this.list = this.item.getElementsBySelector('ul')[0]; // Create div.bigvideo and add it just before the ul. this.bigvideo = document.createElement('div'); Element.addClassName(this.bigvideo, 'bigvideo'); this.item.insertBefore(this.bigvideo, this.list); // Create array of videothumbs. this.thumbs = new Array; // Opera 9 doesn't like 'li a' in getElementsBySelector, so you // have to break it apart. var links = this.item.getElementsBySelector('li'); for (var i=0; i < links.length; i++) { this.thumbs[i] = new VideoThumb(index, i, links[i].getElementsBySelector('a')[0]); } // Load up the first video. this.swap(0); }, // Replace existing video with new one. swap: function(index) { // IE 6 won't show the video unless something else is in the box. // I chose to add a <br /> which I hide via CSS. this.bigvideo.innerHTML = '<br /><object width="425" height="350"><param name="movie" value="' + this.thumbs[index].video + '"></param><param name="wmode" value="transparent"></param><embed src="' + this.thumbs[index].video + '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>'; // Deselect all the thumbnails. this.thumbs.invoke('deselect'); // Select the current thumbnail. this.thumbs[index].select(); } }; // Videothumb object VideoThumb = Class.create(); VideoThumb.prototype = { // Initialize object. initialize: function(boxindex, index, link) { this.boxindex = boxindex; this.index = index; this.item = link; this.href = this.item.getAttribute('href'); // Extract the v querystring value from the href. Youtube uses this // value for everything. this.videocode = this.href.toQueryParams().v; // Direct link to the video for use in the object/embed this.video = 'http://www.youtube.com/v/' + this.videocode; // Create thumbnail image and append it inside the list item var img = document.createElement('img'); img.src = 'http://img.youtube.com/vi/' + this.videocode + '/default.jpg'; img.alt = this.item.innerHTML; img.title = this.item.innerHTML; this.item.innerHTML = ""; this.item.appendChild(img); // Observe the click event. Event.observe(this.item, 'click', this.swap.bindAsEventListener(this)); }, swap: function(evt) { // Call the swap method of the parent videobox with the thumbnail // thumbnail index as a parameter. aVB[this.boxindex].swap(this.index); // Stop the event so the browser doesn't follow the link. if (evt) { Event.stop(evt); } }, select: function() { this.item.addClassName('current'); }, deselect: function() { this.item.removeClassName('current'); } }; // Don't do anything if we're using Opera 8 or earlier. if (!Prototype.Browser.Opera || (Prototype.Browser.Opera && navigator.userAgent.toLowerCase().charAt(navigator.userAgent.toLowerCase().indexOf('opera') + 6) > 8)) { // Create array of videoboxes so you can have more than one on a page. var aVB = new Array; $$('div.videobox').each ( function(videobox, index) { aVB[index] = new VideoBox(index, videobox); }); } I'm using Fiddler (web debugging tool) and the below code is JScript .NET, which is basically a .NET version of Javascript. Code: if (oSession.HostnameIs("www.youtube.com") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")) // oSession is a Fiddler object session { oSession.utilDecodeResponse(); // Remove any compression or chunking oSession.utilReplaceInResponse('<b>','<u>'); // Search and replace in HTML } How do I replace youtube video player with this message? Code: <div id="player-unavailable" class=" player-width player-height player-unavailable "> <div class="icon meh"></div> <div class="content"> <h1 id="unavailable-message" class="message"> This video is no longer available because of inappropriate content. </h1> <div id="unavailable-submessage" class="submessage"> Sorry about that. </div> </div> </div> Thank you hi I am trying to play a video from youtube. What I have done so far is getting videos from my database and displaying all those videos thumbnails. So now what i want is to when i click any thumbnail it should play that video in my website. How can I do this? Here is my code Code: function showResult(result) { $('#videosLoader').css('display','none'); var videoId = result.split(" "); for(i = 0; i < videoId.length - 1; i++) { var vidId = $.trim(videoId[i]); vidLink = getScreen(vidId,"small"); $('#videosList').append("<div class='playVid'>" + "<img width=80 height=80 src=" + vidLink + " alt='' /> " + "<input type='hidden' name='vidId' value='" + vidId + "' />" + "</div>").addClass("playVid"); } $('.playVid').click(function() { var val = $("input[name='vidId']").val(); alert("val"); $("#haveYourDefinition").append("<embed src='http://www.youtube.com/v/" + val + "&rel=1' pluginspage='http://adobe.com/go/getflashplayer' type='application/x-shockwave-flash' quality='high' width='450' height='376' bgcolor='#ffffff' loop='false'></embed>"); }); When I click any thumbnail it does nothing. Why and please tell me how to do this? Help Hi, I currently created a video uploader, but when the video is too big in size, the page seems to be not doing any until the video is completely uploaded. I want to put somewhat like "loading.. please wait" script until the video is not completely uploaded. Thanks. //Ana Hi there, does anoyne know how to embed a RSS feed into a webpage? The code I was using before is now no longer supported Thanks Joe Hi - I am using the tinyslideshow and need to be able to embed a wmv file into it. It needs to open within the slideshow as the thumbnail loads and when clicked just as the image does. I have not been able to figure this out or know if it is possible and any help would be greatly appreciated! Thanks so much.
Is there a way to use google anayltics to track how many people clicked onto my video from my site to watch it? how long they stayed on the video, where they came from, ect?
I'm trying to embed flash onto a web page using the flash player that comes with Dreamweaver CS4. I've used other players in the past, such as the Longtail FLV player, but need to use one that's free for commercial use in this case. I've set up the file with a script to load the video dynamically using the swfobject (the CS4 flash player uses a modified version, not sure what's different about it). Everything works as expect on PC, but on Mac for some reason instead of playing the video it just displays the components of the flash player's skin (i.e. play button, etc.). Here's the script: Code: <script src="scripts/swfobject_modified.js" type="text/javascript"></script> <script type="text/javascript"> var flashvars = {}; flashvars.MM_ComponentVersion = '1'; flashvars.skinName = "skins/Halo_Skin_3"; flashvars.streamName = "videos/base"; flashvars.autoPlay = "false"; var params = {}; var attributes = {}; swfobject.embedSWF("FLVPlayer_Progressive.swf", "myContent", "768", "432", "9.0.0","expressInstall.swf", flashvars, params, attributes); </script> And the HTML: Code: <div id="myContent"> <p>Some content requires Adobe Flash Player. You can download it <a href="http://get.adobe.com/flashplayer/" rel="nofollow" target="_blank">here</a></p> </div> Any thoughts on what might be causing the problem? Thanks. i'm newb to java, but need to get my quicktime movie embeds working on windows/explorer. apparently i need to call external java script to make it work: http://developer.apple.com/internet/ieembedprep.html here is my HEAD code: <script src="kitchslideembed.js" language="JavaScript" type="text/javascript"></script> and BODY code: <script language="JavaScript"type="text/javascript">InsertKitchSlideMovie();</script> and my "kitchslideembed.js" file... function InsertKitchSlideMovie() { document.write('<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width="768" height="591" codebase='http://www.apple.com/qtactivex/qtplugin.cab'>\n'); document.write('<param name='src' value="http://jamesgivensdesign.com/public_html/notes/kitchenslide1.mov">\n'); document.write('<param name='autoplay' value="false">\n'); document.write('<param name='controller' value="true">\n'); document.write('<param name='loop' value="false">\n'); document.write('<embed src="kitchenslide1.mov" width="768" height="591" autoplay="false" controller="true" loop="false" pluginspage='http://www.apple.com/quicktime/download/'>\n'); document.write('</embed>\n'); document.write('</object>\n'); } any help out there? I'm getting Error: Object doesn't support property or method 'addEvent' in my webpage. I'm trying to embed a flash carousel in an asp.net page and I have this, but nothing is showing on my page. Using IE9 and FF4 Code: <script type="text/javascript"> window.addEvent('load', function() { var flashvars = { xmlLocation: "<%=ResolveUrl("upload/data.xml")%>", imageLocation: "<%=ResolveUrl("~/upload/")%>" }; swfobject.embedSWF("<%=ResolveUrl("~/upload/Carousel-Test.swf")%>", "FlashContainer", "576", "242", "10.0.32", "", flashvars, null, null); }); </script> The xml has some settings for the images and all my images are in the upload folder in my project. I have reference to the swfobject js in the masterpage (head) and the homepage inherits from it: Code: <script src="javascript/swfobject.js" type="text/javascript"></script>. Anyone give some suggestions? For a project in my high school web design class, I need to integrate an Excel spreadsheet as data so to speak for a web page. I want to pull the prices from the sheet, and make them appear on the page. I'd like to pull it from the sheet so that the client can still adjust and edit the prices without having to reach the actual webpage. Conceptually, I thought this would be fairly straight forward, but in researching how to do this, I got very confused. I'm not even positive that I'm putting this in the right section. So my main question is this: Is there a way to integrate an Excel spreadsheet in such a way that it can provide data for certain fields of a webpage? If so, can someone please explain how? Thanks, A Confused High School Girl Can anyone help me modify this script to be able to view feeds of type media rather apps? I want it to work as it does for a channel rather than all of youtube. I've tried changing the settings at the top and a lot of other stuff but no luck so far... getting desperate here. I'm willing to pay at this point but I don't have much. I neeeeeed this script. It could be in PHP even. However it must be completely dynamic and allow me to make searches against the channel. Code: var quvic = {}; quvic.MAX_RESULTS_LIST = 50; quvic.THUMBNAIL_WIDTH = 124; quvic.THUMBNAIL_HEIGHT = 93; quvic.PLAYER_WIDESCREEN_WIDTH = 720; quvic.PLAYER_STANDARD_WIDTH = 540; quvic.PLAYER_HEIGHT = 405; quvic.VIDEO_LIST_CSS_CLASS = 'videolist'; quvic.PREVIOUS_PAGE_BUTTON = 'previousPageButton'; quvic.NEXT_PAGE_BUTTON = 'nextPageButton'; quvic.STANDARD_FEED_URL_TOP_RATED = 'http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?'; quvic.STANDARD_FEED_URL_MOST_VIEWED = 'http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed?'; quvic.STANDARD_FEED_URL_MOST_POPULAR = 'http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?'; quvic.STANDARD_FEED_URL_RECENTLY_FEATURED = 'http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?'; quvic.VIDEO_FEED_URL = 'http://gdata.youtube.com/feeds/api/videos?'; quvic.QUERY_URL_MAP = { 'top_rated' : quvic.STANDARD_FEED_URL_TOP_RATED, 'most_viewed' : quvic.STANDARD_FEED_URL_MOST_VIEWED, 'most_popular' : quvic.STANDARD_FEED_URL_MOST_POPULAR, 'recently_featured' : quvic.STANDARD_FEED_URL_RECENTLY_FEATURED, 'search' : quvic.VIDEO_FEED_URL }; quvic.nextPage = 2; quvic.previousPage = 0; quvic.previousSearchTerm = ''; quvic.previousQueryType = 'search'; quvic.jsonFeed_ = ''; quvic.appendScriptTag = function(scriptSrc, scriptId, scriptCallback) { var oldScriptTag = document.getElementById(scriptId); if (oldScriptTag) { oldScriptTag.parentNode.removeChild(oldScriptTag); } var script = document.createElement('script'); script.setAttribute('src', scriptSrc + '&v=2&alt=jsonc&callback=' + scriptCallback); script.setAttribute('id', scriptId); script.setAttribute('type', 'text/javascript'); document.getElementsByTagName('head')[0].appendChild(script); }; quvic.listVideos = function(queryType, searchTerm, page) { quvic.previousSearchTerm = searchTerm; quvic.previousQueryType = queryType; var queryUrl = quvic.QUERY_URL_MAP[queryType]; if (queryUrl) { queryUrl += 'max-results=' + quvic.MAX_RESULTS_LIST + '&format=5&start-index=' + (((page - 1) * quvic.MAX_RESULTS_LIST) + 1); if (searchTerm != '') { queryUrl += '&q=' + encodeURI(searchTerm); } quvic.appendScriptTag(queryUrl, 'searchResultsVideoListScript', 'quvic.listVideosCallback'); quvic.updateNavigation(page); } else { alert('Unknown feed type specified'); } }; quvic.PresentVideos = function(queryType, searchTerm, page) { quvic.previousSearchTerm = searchTerm; quvic.previousQueryType = queryType; var queryUrl = quvic.QUERY_URL_MAP[queryType]; if (queryUrl) { queryUrl += 'max-results=' + quvic.MAX_RESULTS_LIST + '&format=5&start-index=' + (((page - 1) * quvic.MAX_RESULTS_LIST) + 1); if (searchTerm != '') { queryUrl += '&q=' + encodeURI(searchTerm); } quvic.appendScriptTag(queryUrl, 'searchResultsVideoListScript', 'quvic.listVideosCall'); quvic.updateNavigation(page); } }; quvic.listVideosCall = function(json) { quvic.jsonFeed_ = json.data; var div = document.getElementById(quvic.VIDEO_LIST_CSS_CLASS); var items = json.data.items || []; var html = ['<dl class="videos">']; for (var i = 0; i < items.length; i++) { var title = json.data.items[i].title; var thumbnailUrl = json.data.items[i].thumbnail.sqDefault; var videoID = json.data.items[i].id; var duration = json.data.items[i].duration; html.push('<dt><span class="video_thumb thumbbox"><a href="javascript:playVideo(\''+videoID+'\',\''+addslashes(title)+'\')">'); html.push('<img src="',thumbnailUrl,'" width="',quvic.THUMBNAIL_WIDTH,'" height="',quvic.THUMBNAIL_HEIGHT,'" onmouseout="mouseOutImage(this)" onmouseover="mousOverImage(this,\'',videoID,'\',1)"></a>'); html.push('<span class="duration">',getDurationTime(duration),'</span>'); html.push('</span>'); html.push('<br/>', title.substr(0,37), '</dt>');} html.push('</dl><br style="clear: left;"/>'); jQuery(div).fadeTo(500, 1.0); document.getElementById(quvic.VIDEO_LIST_CSS_CLASS).innerHTML = html.join(''); if (items.length > 0) { loadVideo(json.data.items[0].id); } }; function loadVideo(videoID) { swfobject.embedSWF("http://www.youtube.com/v/" + videoID + "?version=3&enablejsapi=1&playerapiid=ytplayer&fs=1&autohide=1", 'player', quvic.PLAYER_WIDESCREEN_WIDTH, quvic.PLAYER_HEIGHT, '9.0.0', false, false, {allowScriptAccess: 'always',allowfullscreen: 'true'}); } quvic.listVideosCallback = function(json) { quvic.jsonFeed_ = json.data; var div = document.getElementById(quvic.VIDEO_LIST_CSS_CLASS); while (div.childNodes.length >= 1) { div.removeChild(div.firstChild); jQuery(div).fadeTo(0, '.01'); } var items = json.data.items || []; var html = ['<dl class="videos">']; for (var i = 0; i < items.length; i++) { var title = json.data.items[i].title; var thumbnailUrl = json.data.items[i].thumbnail.sqDefault; var videoID = json.data.items[i].id; var duration = json.data.items[i].duration; html.push('<dt><span class="video_thumb thumbbox"><a href="javascript:playVideo(\''+videoID+'\',\''+addslashes(title)+'\')">'); html.push('<img src="',thumbnailUrl,'" width="',quvic.THUMBNAIL_WIDTH,'" height="',quvic.THUMBNAIL_HEIGHT,'" onmouseout="mouseOutImage(this)" onmouseover="mousOverImage(this,\'',videoID,'\',1)"></a>'); html.push('<span class="duration">',getDurationTime(duration),'</span>'); html.push('</span>'); html.push('<br/>', title.substr(0,37), '</dt>');} html.push('</dl><br style="clear: left;"/>'); jQuery(div).fadeTo(500, 1.0); document.getElementById(quvic.VIDEO_LIST_CSS_CLASS).innerHTML = html.join(''); }; quvic.updateNavigation = function(page) { quvic.nextPage = page + 1; quvic.previousPage = page - 1; document.getElementById(quvic.NEXT_PAGE_BUTTON).style.display = 'inline'; document.getElementById(quvic.PREVIOUS_PAGE_BUTTON).style.display = 'inline'; if (quvic.previousPage < 1) { document.getElementById(quvic.PREVIOUS_PAGE_BUTTON).disabled = true; } else { document.getElementById(quvic.PREVIOUS_PAGE_BUTTON).disabled = false; } document.getElementById(quvic.NEXT_PAGE_BUTTON).disabled = false; }; function onPlayerError(errorCode) { alert("An error occured of type:" + errorCode); } function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById("player"); ytplayer.addEventListener("onError", "onPlayerError"); } function playVideo(videoID,title){ if(document.title) document.title = title; ytplayer.loadVideoById(videoID); } function HDPlayer() { resizePlayer(quvic.PLAYER_WIDESCREEN_WIDTH, quvic.PLAYER_HEIGHT); } function HQPlayer() { resizePlayer(quvic.PLAYER_STANDARD_WIDTH, quvic.PLAYER_HEIGHT); } function resizePlayer(width, height) { var playerObj = document.getElementById("player"); playerObj.height = height; playerObj.width = width; } function addslashes(str) { str=str.replace(/\'/g,'\\\''); str=str.replace(/\"/g,''); return str; } function stripslashes(str) { str=str.replace(/\\'/g,'\''); return str; } var imname; var timer; function mousOverImage(name,id,nr){ if(name) imname = name; imname.src = "http://img.youtube.com/vi/"+id+"/"+nr+".jpg"; imname.style.border = '3px solid silver'; nr++; if(nr > 3) nr = 1; timer = setTimeout("mousOverImage(false,'"+id+"',"+nr+");",1000); } function mouseOutImage(name){ if(name) imname = name; imname.style.border = '3px solid #fff'; if(timer) clearTimeout(timer); } function getDurationTime(sec) { var sec_div = ''+((sec%60) | 0); if(sec_div.length == 1) sec_div = '0'+sec_div; return ((sec/60) | 0)+':'+sec_div; } This draws on jQuery JavaScript Library v1.4.2 and swfObject; A similar script providing this functionality would also be acceptable. Just to let you know if you don't know how to do this is the code I use: It will solve the problem of the clip scrolling over text etc. <embed wmode="transparent" src="youtube URL" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="280" height="240"></embed> (mods, do with this as you please). I am using a javascript replace code to embed youtube videos in my forum. It works fine except users on iPhone or iPad can't see the videos. I would like to added the url to the video under the embed code - so these users can just click the link and see the vid on youtube. Here is the script in question: Code: z[x].innerHTML = z[x].innerHTML.split("[YOUTUBE]").join("<iframe width=560 height=410 src='").split("/watch?v=").join("/v/").split("[/YOUTUBE]").join("' frameborder=0 allowfullscreen></iframe>"); I am not very good with the split & join functions. Can someone help me out.. I would like the code to place the you tube video link like so: Code: z[x].innerHTML = z[x].innerHTML.split("[YOUTUBE]").join("<iframe width=560 height=410 src='").split("/watch?v=").join("/v/").split("[/YOUTUBE]").join("' frameborder=0 allowfullscreen></iframe>< br><a href="youtube video link">View on YouTube</a> "); I have used this tool in order to display all my youtube videos. http://www.php-help.ro/mootools-12-j...ched-playlist/ When you go over the thumbnail of one of the videos, you can see the title of each video (the title of the specific video in youtube). I want this title to be displayed before the thumbnail (above it). Can someone tell me please how can I do it? There are 4 JS files, 1 CSS and a small html code (all on the link provided). Thanks! I am looking to create a Stylesheet for YouTube, to make it look nicer and customise it completely I wanted to change the logo, but its a graphic. I was wondering if it would be possible to do this by linking to one hosted on Flickr? Or is there another trick? Hi all. I'm new comer here and i have no idea to find the way how to create youtube like content locker. Is possible to lock / hide content for visitor until they liked video on youtube ? I'm very basic using javascript and i don't know how to start coding. I would to thanks to all who answering my questions. Regards |