我试图在MPMoviePlayercontroller
按下的按钮上获得某种通知。问题是按下按钮时我没有收到任何通知。我正在使用NSNotification
。为什么我没有收到通知?
ViewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(exitedFullScreen)
name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
和方法
-(void) exitedFullScreen
{
NSLog(@"TEST");
}
调用MPMoviePlayer
的代码:
NSString *youTubeVideoHTML = @"<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_api\"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'%0.0f', height:'%0.0f', videoId:'%@', events: { } }); } function onPlayerReady(event) { event.target.playVideo(); } </script> </body> </html>";
NSString *embedHtml = [NSString stringWithFormat: youTubeVideoHTML,
webView.frame.size.width,
webView.frame.size.height,
youtubeId[0]];
webView.mediaPlaybackRequiresUserAction = NO;
[webView loadHTMLString: embedHtml baseURL: [NSURL URLWithString: @"http://youtube.com"]];
答案 0 :(得分:1)
退出全屏不会改变播放状态。如果您想知道何时退出全屏,请注册MPMoviePlayerDidExitFullscreenNotification
。
另外,就一般情况而言,回调方法最好有一个冒号(例如exitedFullScreen:
);参数是通知本身:
- (void) exitedFullScreen: (NSNotification*) n {
NSLog(@"%@", @"TEST");
}
答案 1 :(得分:0)
您应该创建一个MPMoviePlayerViewController
并使用您的视频网址初始化并展示它。播放视频并关闭后,您将收到通知。