我试图在jQuery mobile ui-block中创建youtube视频的JSON提要,但每个视频都有相同的网址,因此它为每个视频提取相同的ID并且不能为我的生活搞清楚!我在网上找到了 - http://www.abbeyshruletidyvillages.ie/app/#videos。 谢谢 皮尔斯
/
// Video YouTube JSON Feed
//
function listVideos(data) {
console.log(data);
var output='';
for (var i=0; i<data.feed.entry.length; i++) {
// Title
var title = data.feed.entry[i].title.$t;
// Tumbnail
var thumbnail = data.feed.entry[i].media$group.media$thumbnail[0].url;
// Description
var description = data.feed.entry[0].media$group.media$description.$t;
// Video ID
var id = data.feed.entry[0].id.$t.substring(39);
var blocktype = ((i % 2) === 1) ? 'b' : 'a';
output += '<a href="#videoplayer" data-transition-"fade" onclick="playVideo(' + id + '\',\'' + title + '\',\'' + escape(description) + '\')">';
output += '<div class="ui-block-' + blocktype + '">';
output += '<h3 class=""movivetitle">' + title + '</h3>';
output += '<img src="' + thumbnail + '" alt="' + title + '" />';
output += "</a>"
output += "</div>";
}
$('#videolist').html(output);
}
function playVideo(id, title, description) {
var output ='<iframe src="http://www.youtube.com/embed/'+ id +'?wmode=transparent&HD=0&rel=0&showinfo=0&controls=1&autoplay=1" frameborder="0" allowfullscreen></iframe>';
output += '<h3>' + title + '</h3>';
output += '<p>' + unescape(description) + '</p>';
$('#myplayer').html(output);
}
答案 0 :(得分:0)
使用它可行吗
var description = data.feed.entry [i] .media $ group.media $ description。$ t;
var id = data.feed.entry[i].id.$t.substring(39);