- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在一个简单的单页网站中使用 YouTube API。我能够播放视频并且我的所有 YouTube 功能在桌面浏览器中都能成功运行(IE 7 除外——也许这个问题会在你帮助我回答这个问题时得到解决)但它似乎不起作用在 iOS(iPhone 和 iPad)中完全没有。YouTube 播放器根本不显示,并且在 iOS 中根本没有 YouTube 功能的内存。
下面是我的代码实现。如果有任何我没有提供的问题信息对这个问题有帮助,请告诉我。我想尽可能简单地开始解决这个问题,然后在必要时提供更多信息。
/*==========================================================================
YOUTUBE
========================================================================== */
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var YTready = false,
playerIdList = [],
ytPlayers = {};
// When YouTube API is ready, switch YTready to true and run the queue of videos should any exist
// and run a list of page-specified functions such as carousel setups
var YTreadyFunctions = {};
function onYouTubeIframeAPIReady() {
console.log('YT Ready');
YTready = true;
if (playerIdList.length > 0) {
runYouTubeIframeList(playerIdList);
}
for(id in YTreadyFunctions){
var thisFunc = YTreadyFunctions[id];
var thisArgs = thisFunc.args;
thisFunc.func(thisArgs.id,thisArgs.counters,thisArgs.isHome,thisArgs.isAutoRot,thisArgs.galleryType);
}
}
function shortID(elemId){
return elemId.split('-').join('');
}
function initializeYouTubeIframe(playerId,params){
//var playerId = thisList[x];
var thisPlayer = document.getElementById(playerId);
ytPlayers[shortID(playerId)] = new YT.Player(playerId, {
width: thisPlayer.getAttribute('width'),
height: thisPlayer.getAttribute('height'),
playerVars: {
autohide: 1,
//autoplay: 1,
theme: 'light',
showinfo: 0,
color: 'white',
rel: 0,
origin: document.location.hostname,
wmode: 'transparent'
},
videoId: playerId,
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function runYouTubeIframeList(thisList) {
// If the YouTube iFrame API (onYouTubeIframeAPIReady is not ready yet,
// add the player(s) to a list (playerIdList) to wait until the API is ready and then initialize
if (!YTready) {
playerIdList.concat(thisList);
} else {
// YT API is ready. Initialize the list of player iframes.
var thisListLength = thisList.length;
for (var x = 0; x < thisListLength; x++) {
initializeYouTubeIframe(thisList[x]);
}
}
}
function onPlayerReady(event) {
//alert('player ready');
}
function onPlayerStateChange(event) {
//alert('state changed: ' + event.data);
if (event.data == 3) {
$('.loading').remove();
}
if (event.data == 1) {
$('#i360-static-panel').css('display','none');
$('.loading').remove();
$('div#i360-questions > h2').fadeIn(500).removeClass('transparent');
}
if (event.data == 0) {
$('#i360-answer-mask').slideUp(function () {
$('p.active-answer').remove();
$('div#i360-questions > ul').fadeIn(500).removeClass('transparent');
$('div#i360-questions > ul > li').removeClass('i360-clicked-question');
});
$('.i360-shown').fadeOut(300);
$(event.target.a.parentNode).children('#i360-static-panel').css('display','block');
}
}
// run through all yt-players and add their ID to a list of to-be-initialized players
$('.yt-player').each(function(i){
playerIdList.push($(this).attr('id'));
});
runYouTubeIframeList(playerIdList);
function setVideoCarouselThumb(response,element){
if(response.data){
if(response.data.thumbnail.hqDefault){
element.getElementsByTagName('img')[0].src = response.data.thumbnail.hqDefault;
} else if(response.data.thumbnail.sqDefault){
element.getElementsByTagName('img')[0].src = response.data.thumbnail.sqDefault;
}
} else if (response.status){
if(response.status == '403'){
element.setAttribute('class',element.getAttribute('class') ? element.getAttribute('class') + ' private' : 'private');
}
}
}
function getYouTubeInfoById(type,getID,callback,args){
//window.console && console.log('function: getYouTubeInfoById | type = ',type,' | getId = ',getID,' | args = ',args);
//consoleThis('https://gdata.youtube.com/feeds/api/' + type + '/' + getID + '?v=2&prettyprint=true&alt=jsonc');
$.ajax({
url: 'https://gdata.youtube.com/feeds/api/' + type + '/' + getID + '?v=2&prettyprint=true&alt=jsonc',
dataType: 'jsonp',
context: args ? args : '',
success: function(response){
callback(response,this);
},
error: function(response){
callback(response,this);
//consoleThis(response);
}
});
}
// END YOUTUBE
</script>
<meta name="apple-mobile-web-app-title" content="Roundup" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Roundup" />
<meta name="viewport" content="minimum-scale=1.0, maximum-scale=1.0">
最佳答案
根据 this other SO post ,在 iOS 上存在限制,其中 “......无法在 iOS 上的 Safari 中以编程方式自动播放嵌入式媒体 - 用户始终启动播放。”
我有同样的问题,事实证明你可以有一个 YouTube-API IFrame 正确嵌入并显示在 iOS 上,带有 YouTube 的大红色“播放”按钮,只是 iOS 不允许您可以使用自己的控件和 JavaScript 开始/停止视频。例如。您可以使用 JavaScript 进行下一个/上一个,但不能播放/暂停,这必须通过点击视频,然后使用视频进度条旁边的 native 控件来完成。
但关于您第一段的最后一句话并撇开这些限制,YouTube 播放器应该显示您所做的事情有问题(虽然我不够专业,无法判断是什么).我也在 a simple one-page website 中这样做,随时看看我做了什么。
希望对您有所帮助!
关于javascript - YouTube API 无法在 iOS (iPhone/iPad) 中运行,但在桌面浏览器中运行良好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16513620/
是否有任何解决方案来禁用右键单击选项并从 Youtube 视频中删除右下角水印 Logo ?我在搜索 GOOGLE 后尝试过。谁能告诉我? 谢谢你。 最佳答案 试试 modestbranding范围:
我想使用 YouTube API (v3) 来启用仅音乐轨道的搜索(没有猫或藤蔓或任何其他非音乐视频)。我查看了 API Explorer 和文档以获取有关该问题的任何指示,但找不到任何有用的信息。
我需要为网站使用YouTube视频缩略图的maxresdefault版本,但是在开发实现此目的的代码后,我发现并非所有视频都具有这些缩略图,尽管这些视频均为1080p。 有没有一种方法可以自动为我的所
我想通过“iframe”嵌入youtube视频,但YouTube在我国禁止使用,建议我如何在我的网站上嵌入视频! [1]:以下图片显示了在我的国家/地区无法访问youtube 最佳答案 该视频将被嵌入
我正在为myBB使用一个名为Profile Music Plugin的插件,可以在此处找到http://community.mybb.com/mods.php?action=view&pid=75 我
Youtube IFRAME API中是否有可以执行命令的功能,例如在播放的视频结尾处打开网站? (我相信有一个功能可以在旧的Java API下执行此操作,但该功能已于去年弃用。) 最佳答案 您可以引
我试图在Videos.insert和Videos.update查询中设置3d尺寸标志。但是标志不会改变。 更新查询示例: 请求: PUT https://www.googleapis.com/yout
使用此获取评论 评论主题:列表 GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet { "error": {
最近,我尝试使用OEmbed服务通过播放列表查询参数获取视频网址的iframe代码,但是OEmbed为我们提供了与我要求的视频不同的iframe代码。 这是带有播放列表查询参数的视频网址: https
我正在使用此代码: https://www.googleapis.com/youtube/v3/search?q=global+warming&part=id&maxResults=50&key=MY
我有一个LiveBroadcast,并且将来会添加一个scheduledStartTime。据我所知,这次测试不会对LiveBroadcast的整体状态产生影响,即广播是否具有准备就绪/测试的life
YouTube API是否支持在特定时间后关闭浏览器的参数? 这需要使用链接在不同位置共享来推广促销视频。视频播放结束后关闭浏览器。 最佳答案 您可以使用Youtube API监控视频是否播放完毕,然
如果没有表单上的透明面板,YouTube Player将可以正常播放视频,或者可以全屏播放视频,透明面板中有一些图像没有什么特别的。如果我取出透明面板,则YouTube播放器会按需工作,并嵌入到应用程
我正在通过Google进行身份验证,以尝试获取YouTube分析数据,但我的问题是我不知道在查询YouTube时如何向您填充参数 在这里,我正在提供一项新服务:然后尝试查询它 我不确定要在“ids”参
我想添加youtube视频列表,但不添加视频播放器。所以我需要的是 视频标题 视频缩略图 视频时长 我以某种方式设法通过使用此http://img.youtube.com/vi/4wew2uWoARw
我正在使用youtube api和python库gdata 我遵循了文档,但似乎没有出路。 问题是 - How do i get the size of the youtube video fil
使用Youtube API,我如何获得评论或顶过youtube视频的用户ID /处理列表? 提前致谢 最佳答案 在这里,您可以了解如何使用YouTube API v2(v3尚不支持此注释)获取评论:h
我正在为所有相关数据构建一个仪表板(以php为单位),我还想在YouTube“稍后观看”播放列表中显示我的商品数量。 我知道无法使用YouTube API来解决这个问题,但是也许有人想出一种解决方法?
我尝试使用YouTube API,但存在引号问题。 SearchResource.ListRequest searchListRequest = yt.Search.List("sni
我想为我的Android应用程序的用户构建视频推荐器。我有Google OAuth可以登录我的应用程序。我可以获取有关我的应用程序用户在YouTube上观看的视频的数据吗? 最佳答案 v3 API分为
我是一名优秀的程序员,十分优秀!