Youtube Api playVideo方法在某些移动设备上不起作用(Youtube Api playVideo method doesn't work on some mobile devices)
我正在尝试创建一个移动网站,点击图像后播放YouTube视频。
我已经在几款Android手机/版本上进行了测试,有些手机没有达到预期的效果。
我的意思是它停止缓冲,永远不会播放视频。 我注意到的另一件事是播放器在用户触发视频后播放而不是以编程方式播放。 更详细,如果我直接显示youtube播放器,用户点击播放视频,然后点击一个按钮/图像播放另一个视频这是有效的。
我在这里发布了与JsFiddle合作的测试页面
$(document).ready(function () { // Caching jQuery objects var $body = $('body'), $log = $('#log'), $yt = $('#ytplayer'), $ytwrap = $('#ytwrapper'), $choices = $('#choices'); // This code loads the YouTube API var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; $body.append(tag); // This will become the player object when the API is ready var player; // See what kind of device we're using var userAgent = navigator.userAgent.toLowerCase(); var isAndroid = userAgent.indexOf('android') > -1; var isIpad = userAgent.indexOf('ipad') > -1; var isIphone = userAgent.indexOf('iphone') > -1; window.onYouTubeIframeAPIReady = function onYouTubeIframeAPIReady() { player = new YT.Player('ytplayer', { videoId: videos[0], playerVars: { allowfullscreen: 'allowfullscreen', playsinline: 0 }, events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); window.player = player; //hide player slidePlayer(false); }; function onPlayerStateChange(event) { // When a video starts playing, // enable the fake fullscreen mode on Android & iPad if (event.data == YT.PlayerState.PLAYING) { if (isIpad) { fakeFullScreen(true); } else if (isAndroid) { fakeFullScreen(true); } } // On pause: hide the player, show thumbs if (event.data == YT.PlayerState.PAUSED) { if (isAndroid) { // Exit fullscreen fakeFullScreen(false); // Scroll back to choices window.scrollTo(0, playerTop); } else if (isIpad) { fakeFullScreen(false); window.scrollTo(0, playerTop); } else if (isIphone) { slide(false); } } } $('#vstImageAd .imageWrap img').click(function (e) { e.preventDefault(); var $this = $(this); if (player) { $this.css("display", "none"); slidePlayer(true); player.playVideo(); } }); // When a thumb image is pushed, start the video $('#choices .playthumb img').click(function (e) { var $this = $(this), nr = parseInt($this.data('nr')); if (!videos[nr]) nr = 1; player.loadVideoById(videos[nr]); // Hide the thumbs slide(true); }); });
I am trying to create a website for mobile where after clicking on an image a youtube video to play.
I have tested on several Android mobile phones/versions and on some doesn't behaves as intended.
What I mean is it stops at buffering and never reaches to play the video. Another thing that I noticed is that the player works after the user triggers the video to play and not programatically. More detailed if I directly show the youtube player, the user click to play video and afterward click a button/image to play another video this works.
I have posted here the test page that I worked with JsFiddle
$(document).ready(function () { // Caching jQuery objects var $body = $('body'), $log = $('#log'), $yt = $('#ytplayer'), $ytwrap = $('#ytwrapper'), $choices = $('#choices'); // This code loads the YouTube API var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; $body.append(tag); // This will become the player object when the API is ready var player; // See what kind of device we're using var userAgent = navigator.userAgent.toLowerCase(); var isAndroid = userAgent.indexOf('android') > -1; var isIpad = userAgent.indexOf('ipad') > -1; var isIphone = userAgent.indexOf('iphone') > -1; window.onYouTubeIframeAPIReady = function onYouTubeIframeAPIReady() { player = new YT.Player('ytplayer', { videoId: videos[0], playerVars: { allowfullscreen: 'allowfullscreen', playsinline: 0 }, events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); window.player = player; //hide player slidePlayer(false); }; function onPlayerStateChange(event) { // When a video starts playing, // enable the fake fullscreen mode on Android & iPad if (event.data == YT.PlayerState.PLAYING) { if (isIpad) { fakeFullScreen(true); } else if (isAndroid) { fakeFullScreen(true); } } // On pause: hide the player, show thumbs if (event.data == YT.PlayerState.PAUSED) { if (isAndroid) { // Exit fullscreen fakeFullScreen(false); // Scroll back to choices window.scrollTo(0, playerTop); } else if (isIpad) { fakeFullScreen(false); window.scrollTo(0, playerTop); } else if (isIphone) { slide(false); } } } $('#vstImageAd .imageWrap img').click(function (e) { e.preventDefault(); var $this = $(this); if (player) { $this.css("display", "none"); slidePlayer(true); player.playVideo(); } }); // When a thumb image is pushed, start the video $('#choices .playthumb img').click(function (e) { var $this = $(this), nr = parseInt($this.data('nr')); if (!videos[nr]) nr = 1; player.loadVideoById(videos[nr]); // Hide the thumbs slide(true); }); });
原文:https://stackoverflow.com/questions/26658869
最满意答案
首先要确保关闭所有soffice的实例和进程,因为如果office已经打开,它将不会开始监听套接字。
那么你的命令有问题; 它不适合我。 我通常使用的是:
chdir "%ProgramFiles(x86)%\LibreOffice 5\program\" start soffice -accept=socket,host=0,port=2002;urp;
在Linux上,我使用以下命令,并且相同的参数适用于Windows:
loffice "--accept=socket,host=localhost,port=2002;urp;" --writer
编辑 :
从您的评论中,听起来您可以通过删除各种参数来查看哪一个导致问题。
First be sure that all instances and processes of soffice are closed, because if office is already open, it will not start listening on a socket.
Well there is something wrong with your command; it isn't working for me. What I normally use is:
chdir "%ProgramFiles(x86)%\LibreOffice 5\program\" start soffice -accept=socket,host=0,port=2002;urp;
On Linux I use the following command, and the same arguments work on Windows:
loffice "--accept=socket,host=localhost,port=2002;urp;" --writer
EDIT:
From your comment, it sounds like you were able to get it to work by removing various arguments to see which one was causing the problem.
相关问答
更多-
很抱歉让你失望,但那是不可能的。 此时,只能从Internet访问工作空间中的TCP端口8080。 因此,您可以开发UDP服务器并从同一工作区测试其功能,但要使其从外部源工作,您应该将代码部署到托管提供商。 Sorry to disappoint you, but that is not possible. At this moment only TCP port 8080 in the workspace can be accessed from the internet. So you can deve ...
-
似乎你没有试图找到它的答案。 试试 - > shell中的pkill node* 并重新启动您的应用 如果你能够通过它,请告诉我? Seems you did not tried to find its answer. try -> pkill node* in shell and restart your app. Let me know if you were able to get through it or not?
-
好吧,你使用签名的小程序。 用户必须接受applet,之后您可以对独立Java应用程序执行任何操作。 Well, you use a signed applet. The user has to accept the applet and after that you can do about anything you can do with a standalone Java application.
-
通过将HOST设置为'my_ip' ,您可以收听仅为计算机解析到计算机的专用IP。 最着名的例子是127.0.0.1 。 而是传递一个空字符串( HOST='' )来侦听来自指定端口的任何请求。 确保在两台计算机上使用相同的端口号,即5000或8000。 另外,检查计算机之间(或安装在其中一台计算机上)之间的防火墙是否阻止连接。 要测试您的计算机原则上是否可访问,请在服务器上没有私有信息的目录中运行python -m SimpleHTTPServer ,并尝试访问从客户端启动的Web服务器。 By sett ...
-
你不需要将密钥加载到Java密钥库中吗? 这是一个单独的计划。 http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/keytool.html -importcert {-alias alias} {-file cert_file} [-keypass keypass] {-noprompt} {-trustcacerts} {-storetype storetype} {-keystore keystore} [-storepass st ...
-
LibreOffice(soffice)问题,同时在Amazon ec2上转换(LibreOffice (soffice) issue while converting on Amazon ec2)[2023-02-17]
编辑:这对我有用,调整代码的步骤。 更改文件夹的权限和我发现的其他答案根本没有帮助。 我自己想出来了。 升级/更新实例 $ sudo apt-get升级 $ sudo apt-get update 安装java jdk 8 $ sudo add-apt-repository ppa:webupd8team / java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer $ sudo apt-get install orac ... -
如果文件来自新版本,请打开新版本。 如果文件来自旧版本,则显示对话框以进行选择 If the file is from new version, open new version. If file is from old version, show dialog box to select
-
这是因为您使用的SOL_PACKET仅用于packet(7)套接字。 对于原始INET套接字,您不需要该选项。 It's because you use SOL_PACKET which is only used for packet(7) sockets. For raw INET sockets, you don't need that option.
-
首先要确保关闭所有soffice的实例和进程,因为如果office已经打开,它将不会开始监听套接字。 那么你的命令有问题; 它不适合我。 我通常使用的是: chdir "%ProgramFiles(x86)%\LibreOffice 5\program\" start soffice -accept=socket,host=0,port=2002;urp; 在Linux上,我使用以下命令,并且相同的参数适用于Windows: loffice "--accept=socket,host=localhost, ...
-
在调试器下运行它,并在socket()设置断点。 当断点命中时,执行堆栈跟踪。 Run it under a debugger, and set a breakpoint in socket(). When the breakpoint hits, do a stack trace.