【问题标题】:mpmovie player didexitfulscreen notification not working in iosmpmovie player didexitfulscreen 通知在 ios 中不起作用
【发布时间】:2014-11-02 16:46:27
【问题描述】:

我正在 web 视图中加载 youtube 视频。由于我的应用程序是在线广播应用程序,因此收音机在后台播放。当我单击 webview 时,它会在 mpmovieplayer 中以全屏模式重定向视频。我想要的是当有人点击 webview 或 mpmovieplayer 开始播放视频时,收音机应该暂停。但是我如何跟踪 mpmoviepayer 何时开始播放和退出全屏。我还在我的viewdidload 方法中设置了通知 MPMoviePlayerDidExitFullscreenNotification。但它从未被调用过。

self.videoTitleLabel.text = videoInfo.videoTitle;

//NSString *vidUrl = [videoInfo.videoURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

CGSize scrSize = [[UIScreen mainScreen] bounds].size;//appDel.window.frame.size;

float imgSclToX = scrSize.width/16.0;

int imgWidth = (int) (scrSize.width -18);
int imgHeight = (int) ((float)(9.0)*imgSclToX);

// DebugLog(@"Yo-----> Window: %@ Width: %i Height: %i", NSStringFromCGSize(scrSize), imgWidth, imgHeight);

NSString *htmlStr = @"";
// htmlStr = [htmlStr stringByAppendingFormat:@"<iframe width=\"%i\" height=\"%i\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>", imgWidth, imgHeight, vidUrl];

NSString *tStr = videoInfo.videoURL;
// NSString *tStr = @"https://www.youtube.com/watch?v=yz_j7nVCJJ0";
tStr = [tStr substringFromIndex:([tStr rangeOfString:@"v="].location+2)];

htmlStr = [NSString stringWithFormat:@"<iframe  type=\"application/x-shockwave-flash\" width=\"%i\" height=\"%i\" src=\"https://www.youtube.com/embed/%@\" frameborder=\"0\" allowfullscreen></iframe>", imgWidth, imgHeight, tStr];

NSString *embedHTML = [NSString stringWithFormat:@"<html><head></head><body>%@<p><b>Artist:</b> %@<br><b>Composer:</b>%@<p>%@</p></body></html>", htmlStr, videoInfo.videoArtist, videoInfo.videoCompositor, videoInfo.videoDescription];
[self.myWebview loadHTMLString: embedHTML baseURL: nil];

if([appDelegate.lastState isEqualToString:@"play"])
{
    [appDelegate pausePlayer];
    manuallyPause = YES;
}

【问题讨论】:

  • 我有同样的问题...通知(UIMoviePlayerControllerWillExitFullscreenNotification、UIMoviePlayerControllerDidExitFullscreenNotification、MPMoviePlayerDidExitFullscreenNotification、MPMoviePlayerPlaybackDidFinishNotification)在 iOS 8 上无法正常工作。在 iOS 7 上处理这些事件可以正常工作!
  • 更新:MPMoviePlayerDidExitFullscreenNotification 和 MPMoviePlayerPlaybackDidFinishNotification 工作正常。

标签: ios webview ios8 mpmovieplayer


【解决方案1】:

查看https://stackoverflow.com/a/26263803/1756448user1717750)和https://stackoverflow.com/a/26096400/1756448Selvin)的答案。

将 AVPlayerItemBecameCurrentNotification 与 iOS 8 的 UIWindowDidBecomeVisibleNotification 和 UIWindowDidBecomeHiddenNotification 结合使用 而不是 UIMoviePlayerControllerDidExitFullscreenNotification。

它对我有用! )

【讨论】:

    猜你喜欢
    • 2018-03-02
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    • 2015-06-28
    • 2019-09-22
    • 2015-12-19
    • 2016-10-20
    • 1970-01-01
    相关资源
    最近更新 更多