gpt4 book ai didi

iphone - 在 iPhone 上使用 <iframe> 播放 YouTube 失败,但在 iOS 6 下的 iPad 上仍然可以使用(两者在 iOS 5 上都可以正常工作)

转载 作者:行者123 更新时间:2023-12-03 20:06:25 24 4
gpt4 key购买 nike

我使用以下 HTML 模板来传递 UIWebView。我了解这是支持的 YouTube 视频播放方式。

<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>

<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
playerVars: {'autoplay' : 1},
height: 'VIDEO_HEIGHT',
width: 'VIDEO_WIDTH',
videoId: 'VIDEO_ID',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}

// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
if (event.data == YT.PlayerState.ENDED) {
event.target.clearVideo();
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>

显然,我用动态值替换了 HEIGHT、WIDTH 和 VIDEOID 参数。这在 iPhone 和 iPad 上的 iOS 5 下一直运行良好。现在,在 iOS 6 下,当用户点击三角形时,视频似乎会下载并尝试启动,然后放弃。以下是日志文件中显示的内容:

> 2012-09-30 23:27:48.759 xxxxx[6219:c07] [MPAVController] Autoplay: Enabling autoplay
> 2012-09-30 23:27:48.759 xxxxx[6219:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
> 2012-09-30 23:27:48.761 xxxxx[6219:c07] setting movie path: http://o-o---preferred---sn-ab5e6nll---v24---lscache1.c.youtube.com/videoplayback?upn=ag6FiVPe_XY&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=907064%2C908457%2C908310%2C914072%2C922401%2C920704%2C912806%2C913419%2C913546%2C913556%2C919349%2C919351%2C925109%2C919003%2C912706&key=yt1&expire=1349086864&itag=18&ipbits=8&sver=3&ratebypass=yes&mt=1349062032&ip=96.232.106.90&mv=m&source=youtube&ms=au&cp=U0hTTlBTVF9LTkNOM19ITVhJOnRob1gwVHFmQWUw&id=04d71fcbfe79a176&signature=33A43FD457B9FC5DD70284826E7D9BF113F9C0BB.9BC87BDCF97DFCB64F967D2CAD1051D2FC80DAC0

模拟器(所有支持的型号)和硬件设备(iPhone 4s)中的结果相同。奇怪的是,它在 iPad 2(模拟器和硬件)上仍然运行良好,以下是日志记录:

> 2012-09-30 23:32:01.586 xxxxx[6390:c07] [MPAVController] Autoplay: Enabling autoplay
> 2012-09-30 23:32:01.586 xxxxx[6390:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
> 2012-09-30 23:32:01.588 xxxxx[6390:c07] setting movie path: http://o-o---preferred---sn-ab5e6nll---v24---lscache1.c.youtube.com/videoplayback?upn=x7-Ydawtba4&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C926600%2C915704%2C914071%2C922401%2C920704%2C912806%2C913419%2C913546%2C913556%2C919349%2C919351%2C925109%2C919003%2C912706&key=yt1&expire=1349086864&itag=18&ipbits=8&sver=3&ratebypass=yes&mt=1349062271&ip=96.232.106.90&mv=m&source=youtube&ms=au&cp=U0hTTlBTVF9LTkNOM19ITVhJOmVQbjRzVUhBbFpF&id=04d71fcbfe79a176&signature=CD05405B78D1CD7987FE5B9F41DD2C15943BBC2E.863966BDB04003866C6740046C0C2499A0CC4DDD

我最近在这里看到了一些类似的问题,但到目前为止没有人建议可能会发生什么。有人可以建议可能发生什么吗?

问候,-MpK-

最佳答案

您的 html 按原样对我来说效果很好(具有 HEIGHT、WIDTH 和 VIDEOID 替换),加载到 iOS 6 上的 UIWebView、模拟器和设备 (iPhone 5) 中。

问题是否可能是间歇性的 YouTube 或网络问题?此后您是否再次尝试过或尝试过不同的视频 ID?

干杯,克里斯

关于iphone - 在 iPhone 上使用 &lt;iframe&gt; 播放 YouTube 失败,但在 iOS 6 下的 iPad 上仍然可以使用(两者在 iOS 5 上都可以正常工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com