Note that there are some explanatory texts on larger screens.

plurals
  1. POget Youtube video description on click (html.push)
    primarykey
    data
    text
    <p>I'm working with the youtube api (2.0) to pull the 9 most viewed videos from a specific channel. I've got a video player and a list of thumbnails with title + thumbnail image + viewcount + description. When clicking a list-item the chosen video will load within the player. Everything's fine so far.</p> <p>Now I want to add the yt-video description, but not as part of the list items (that already works fine) but next to the player. That means I have to add the 'description' value to the loadVideo function, which fires when clicking on a list-item. But it doesn't work, no matter what I try :-( </p> <p>Here's my code:</p> <pre><code>&lt;script type="text/javascript" src="http://swfobject.googlecode.com/svn/trunk/swfobject/swfobject.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; // Load Video function loadVideo(playerUrl, autoplay) { swfobject.embedSWF( playerUrl + '&amp;rel=1&amp;border=0&amp;fs=1&amp;showinfo=0&amp;autohide=1&amp;autoplay=' + (autoplay?1:0), 'player', '450', '250', '9.0.0', false, false, {allowfullscreen: 'true'}); } // Get feed data and push thumbnails function showMyVideos2(data) { var feed = data.feed; var entries = feed.entry || []; var html = ['&lt;ul class="videos"&gt;']; for (var i = 0; i &lt; entries.length; i++) { var entry = entries[i]; var title = entry.title.$t.substr(0, 20); var description = entries[i].media$group.media$description.$t.substr(0, 100); var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url; var playerUrl = entries[i].media$group.media$content[0].url; var viewcount = entry.yt$statistics.viewCount; html.push('&lt;li onclick="loadVideo(\'', playerUrl, '\', true)"&gt;', '&lt;span class="titlec"&gt;', title, '...&lt;/span&gt;&lt;br /&gt;&lt;img src="', thumbnailUrl, '" width="130" height="97"/&gt;&lt;br /&gt;&lt;span class="views"&gt;Views: ', viewcount,'&lt;/span&gt;&lt;br&gt;&lt;span class="views"&gt;', description,'&lt;/span&gt;&lt;/li&gt;'); } html.push('&lt;/ul&gt;&lt;br style="clear: left;"/&gt;'); document.getElementById('videos2').innerHTML = html.join(''); // Load first video by default if (entries.length &gt; 0) { loadVideo(entries[0].media$group.media$content[0].url, false); } } &lt;/script&gt; &lt;!-- Output --&gt; &lt;div style="width:800px; margin: 0 auto;"&gt; &lt;div id="playerContainer" style="width: 100%; height: 250px; float: left;"&gt;&lt;object id="player"&gt;&lt;/object&gt;&lt;/div&gt; &lt;div id="videos2"&gt;&lt;/div&gt; &lt;/div&gt; &lt;!-- JSON Feed --&gt; &lt;script type="text/javascript" src="http://gdata.youtube.com/feeds/users/100stimmen/uploads?alt=json-in-script&amp;callback=showMyVideos2&amp;max-results=9&amp;orderby=viewCount"&gt; &lt;/script&gt; </code></pre> <p>I think I'll have to manipulate 3 things:</p> <p>1) add the 'description' value to the loadVideo function and print out the description. </p> <p>2) also add the 'description' to the html.push block which defines the click event <em>onclick="loadVideo()"</em>. That for me is the biggest problem, I can't get the syntax right to pass the description value.</p> <p>3) By default the first video will be loaded in the player, so I have to add the description here too, which works like so:</p> <pre><code> if (entries.length &gt; 0) { loadVideo(entries[0].media$group.media$content[0].url, entries[0].media$group.media$description.$t.substr(0, 100), false ); } </code></pre> <p>Here's also a test page: <a href="http://viniblu.de/public/youtube_test.html" rel="nofollow">http://viniblu.de/public/youtube_test.html</a></p> <p>Well, that's what I have so far. Has anybody an idea how to display the description of the clicked video? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload