1

I'm building a smartphone app in HTML5 with the help of JQueryMobile. Since I want it to retrieve a list of videos from a user on youtube I used YouTube's API to do that, after I get all that I needed with it, I made a new page exclusively for the player. When I pick the video, it redirects me to the player I have in my page(an iframe) and plays the video, its plays fine just how I want it but when I press the back button to check my list of videos, if I havent stopped the video before it keeps playing.. Do you have any idea how can I stop that from happening?

Javascript:

 function playVideo(id, title, description) {
var output ='<iframe src="http://www.youtube.com/embed/'+ id +'?wmode=transparent&amp;HD=0&amp;rel=0&amp;showinfo=0&amp;controls=1&amp;autoplay=1" frameborder="0" allowfullscreen></iframe>';
output += '<h3>' + title + '</h3>';
output += '<p>' + unescape(description) + '</p>';
$('#myplayer').html(output);
}
4

1 回答 1

2

工作示例:http: //jsfiddle.net/Gajotres/CnKZh/

$(document).on('pagebeforeshow', '#second', function(){       
    var output ='<iframe width="560" height="315" src="http://www.youtube.com/embed/_js1gWuxB_E" frameborder="0" allowfullscreen></iframe>';
    $('#video-container').append(output);
});

$(document).on('pagebeforehide', '#second', function(){       
    $('#video-container').empty();
});

基本上,当您关闭包含该视频的页面时,必须将其从 DOM 中删除。这是唯一正确的方法。

于 2013-05-28T14:54:18.690 回答