检查 YouTube 视频 (MPMoviePlayer) 是否结束
我有一个带有加载 YouTube 视频的网络视图的视图。我使用以下方法在加载网络视图时自动启动 YouTube 视频。
Web 视图会打开 iPhone 的本机电影播放器。有什么方法可以检查视频是否已结束或用户是否已按下电影播放器的“确定”按钮并从而关闭播放器?
这些是我用来自动启动网络视图的方法:
- (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;
if([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if(view.subviews && [view.subviews count] > 0) {
for(UIView *subview in view.subviews) {
button = [self findButtonInView:subview];
if(button) return button;
}
}
return button;
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
UIButton *b = [self findButtonInView:_webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}
I have a view with a web view which loads a YouTube video. I am using the following methods to automatically start the YouTube video when the web view is loaded.
The web view opens the iPhones native movie player. Is there any way to check if the video has ended or the user has pushed the "OK" button of the movie player and the player is thereby closed?
These are the methods I use for automatically starting the web view:
- (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;
if([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if(view.subviews && [view.subviews count] > 0) {
for(UIView *subview in view.subviews) {
button = [self findButtonInView:subview];
if(button) return button;
}
}
return button;
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
UIButton *b = [self findButtonInView:_webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
苹果不会为此推送[记录的]通知,所以你必须采取一些技巧。
我这样做的方法是检查应用程序的 keyWindow。我从这里得到了这个想法。
在您的 .h 文件中,跟踪计时器和所需的 keyWindow:
在 .m 文件中,您需要以下内容:
然后编辑您的委托方法并添加一个新方法:
Apple doesn't push a [documented] notification for this, so you have to get a little tricky.
The way I do it is to check the application's keyWindow. I got the idea from here.
in your .h file, keep track of your timer and the desired keyWindow:
in your .m file, you need the following:
Then Edit your delegate method and add one new method: