在UIWebView中视频启动或停止时获取通知 [英] Get Notification when a video starts or stops in UIWebView
问题描述
你好,我是目标新手 - c
Hello i am new to objective - c
我遇到了 UIWebView
和<的问题code> MPMoviePlayerController :我的 UIWebView
在html中有一部电影(它是一个本地的html文件),我正在使用html5和一个视频的视频标签。
I'm having a problem with the UIWebView
and MPMoviePlayerController
: My UIWebView
has a movie inside the html (it's a local html file), I'm using html5 and a video tag for the video.
我希望在视频开始或停止时收到通知 UIWebView
....
I want a notification when video starts or stops in UIWebView
....
我尝试过使用 MPMoviePlayerPlaybackDidFinishNotification
,但它没有开火......
I have tried using MPMoviePlayerPlaybackDidFinishNotification
, but it doesnt fire ...
I我也尝试让我的主 UIViewController
查看我自己的视图,并拦截 -didAddSubview:
和 -willRemoveSubview:
。但没有成功...
I have also tried to make the my main UIViewController
's view a view of my own, and intercept -didAddSubview:
and -willRemoveSubview:
. but with no sucess...
是否有任何机构知道如何从 uiwebview
??
Does any body know how to get notification from uiwebview
??
推荐答案
您可以观察 @MPAVControllerPlaybackStateChangedNotification
(使用 nil
为对象)。此通知未记录,因此我不知道App Store是否会批准您的应用。
You can observe @"MPAVControllerPlaybackStateChangedNotification"
(use nil
for the object). This notification isn't documented so I don't know if the App Store will approve your app.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateDidChange:)
name:@"MPAVControllerPlaybackStateChangedNotification"
object:nil];
通知中的密钥为 MPAVControllerNewStateParameter
USERINFO
。播放开始前该值似乎为0,暂停时为1,正在播放时为2,拖动播放滑块时为3(暂时)。
The notification has the key MPAVControllerNewStateParameter
in its userInfo
. The value seems to be 0 before playback starts, 1 when it is paused, 2 when it is playing, and 3 (momentarily) when you are dragging the playback slider.
- (void)playbackStateDidChange:(NSNotification *)note
{
NSLog(@"note.name=%@ state=%d", note.name, [[note.userInfo objectForKey:@"MPAVControllerNewStateParameter"] intValue]);
}
这篇关于在UIWebView中视频启动或停止时获取通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!