IOS中的YouTube自动播放功能 [英] YouTube Autoplay Possibilities In IOS

查看:910
本文介绍了IOS中的YouTube自动播放功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个webView:

I have created a webView:

videoView.delegate = self;
videoView.userInteractionEnabled = true;
[videoView loadRequest:[[NSURLRequest alloc]initWithURL:[[NSURL alloc]   initWithString:@"website"]]];

我有html / javascript来处理视频的加载以及自动播放和下一个视频。这一切都有效,但我的问题是IOS自动加载像quicktime这样的播放器,这也是一件好事,但我不知道如何控制它,也不知道如何让视频播放一旦发生。我希望播放器中显示的按钮能够自动播放。我想在任何时候加载新视频时都会发生这种情况。

I have html/javascript to handle the video's loading as well as the autoplay and next video. This all works, but my problem is that IOS autoloads the quicktime - like player, which is also a good thing, but I do not know how to control that, nor do I know how to get the video to play once that has happened. I would like the button that shows up in the player to autoplay. I would like that to happen anytime a new video is loaded.

JS代码的工作原理如下。我列出了一个列表,这是我的播放列表。我没有从youTube加载播放列表我只是制作自己的列表,当调用视频结束时,我按ID加载新视频。我还自动播放了视频,这就是IOS在视频加载时随时提供的按钮。另外,我使用iframe来完成所有这些,使用youTube api,这就是我对js方面的控制。

JS code works like this. I take in a list and that is my playlist. I do not load a playlist from youTube I just make my own list and when end of video is called I load a new video by id. I also autoplay the video which is what gives me the button that IOS supplies anytime a video loads. Also, I am using an iframe to do all of this, with the youTube api's that is how I have control on the js side of things.

问题:有没有办法通过代码控制播放?如果是这样的话,当播放器已经加载并且我加载另一个视频时,我怎样才能获得自动播放?

Question: Is there a way to control the play via code? If so how, also when the player is already loaded and I load another video how can I get that to autoplay as well?

我找到了答案:

如果你在 webViewDidFinishLoad 中放入 webView.mediaPlaybackRequiresUserAction = FALSE; 然后它会自动播放,但仍然允许你使用其他按钮。这就像一个魅力,建议使用它。

If you put webView.mediaPlaybackRequiresUserAction=FALSE; in the webViewDidFinishLoad then it will autoplay and still let you use the other buttons as well. This worked like a charm and suggest using it.

推荐答案

我找到答案:如果你把

webView。 mediaPlaybackRequiresUserAction = FALSE;
在webViewDidFinishLoad中:然后它将自动播放并仍然允许您使用其他按钮。这就像一个魅力,建议使用它。

webView.mediaPlaybackRequiresUserAction=FALSE; In the webViewDidFinishLoad: then it will autoplay and still let you use the other buttons as well. This worked like a charm and suggest using it.

这篇关于IOS中的YouTube自动播放功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆