Nat*_*han 4 objective-c uiwebview ios ios6
我似乎无法在iOS 6中播放任何视频.无论是在设备(iP4)还是模拟器上.
我所拥有的是IB中的UIWebView设置.然后在我的viewDidLoad我有以下代码:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://domain.com/app/player.php?vid=%@", [videoDetails objectForKey:@"vid"]]];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[videoWebView loadRequest:requestObj];
Run Code Online (Sandbox Code Playgroud)
只是要解释一下,vimeo上的视频设置是只允许托管在特定域上,否则会显示错误消息.所以我在player.php中设置了一些简单的HTML,它只调用vimeo嵌入代码.
当我进入其上有UIWebView的视图,并且视频已加载并且您在vimeo视频中看到"播放"图标时,我单击该视频,然后视频显示加载图标,然后在大约5-10之后秒,控制台输出以下内容,UIWebView变为白色.
控制台输出:
2013-01-30 16:50:11.809 My App[2807:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-30 16:50:11.821 My App[2807:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-01-30 16:50:11.831 My App[2807:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-30 16:50:12.042 My App[2807:907] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2013-01-30 16:50:21.254 My App[2807:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-01-30 16:50:22.000 My App[2807:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-30 16:50:22.244 My App[2807:907] [MPAVController] Autoplay: Disabling autoplay for pause
2013-01-30 16:50:22.246 My App[2807:907] [MPAVController] Autoplay: Disabling autoplay
2013-01-30 16:50:22.354 My App[2807:907] [MPAVController] Autoplay: Disabling autoplay
2013-01-30 16:50:22.591 My App[2807:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-30 16:50:22.593 My App[2807:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2013-01-30 16:50:22.655 My App[2807:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-30 16:50:22.973 My App[2807:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-30 16:50:23.057 My App[2807:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
Run Code Online (Sandbox Code Playgroud)
在iOS 5上,视频只是按预期播放.问题是,这与vimeo无关.我尝试过以下方法:
Vimeo随机公共视频(没有嵌入在domain.com上托管的文件中)
NSString *htmlStringToLoad = [NSString stringWithFormat:@"http://player.vimeo.com/video/32424117?title=0&byline=0&portrait=0&width=320&height=181&frameborder=0"];
[videoWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:htmlStringToLoad]]];
Run Code Online (Sandbox Code Playgroud)
再次使用YouTube:
[videoWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=dABo_DCIdpM"]]];
Run Code Online (Sandbox Code Playgroud)
我唯一担心的是让它与Vimeo视频一起工作,因为这是它们全部存储的地方.但我不能在这里看到vimeo是问题,因为它在YT上也不起作用,所以必须有一些我做错了让iOS 6保持开心?我已经用Google搜索了一下,我似乎根本找不到任何解决方案,即使我不认为这只是我发生的事情.
提前致谢.
为此,我不得不完全抛弃UIWebView.
我不知道你是否在免费的vimeo帐户上获得这个,但在我们的PRO帐户中,在视频设置中有一个"视频文件"选项卡,在底部有一个标有"HTTP直播流"的字段,实际上是直接的链接到您的视频.
然后我使用MPMoviePlayerViewController来播放视频,而不是UIWebView.
将MediaPlayer.framework添加到"Link Binary With Libraries"设置中.在我的视图控制器的.h文件中,我有一个UIImageView,几个标签和一个播放按钮,我导入#import <MediaPlayer/MediaPlayer.h>并设置了一个属性@property(nonatomic, readonly) MPMoviePlayerViewController *player;
然后,在.m文件中:
-(IBAction)playVideo:(id)sender{
NSString *videoString = @"http://player.vimeo.com/external/THE_VIDEO_ID.m3u8?p=standard,mobile&s=UNIQUE_VALUE_FOR_EACH_VIDEO";
player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoString]];
[player.moviePlayer prepareToPlay];
[player.view setFrame: self.view.bounds];
[self.view addSubview: player.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[player.moviePlayer play];
}
- (void)MPMoviePlayerDidExitFullscreen:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[player.moviePlayer stop];
[player.moviePlayer.view removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
我确实尝试将HTTP Live Stream URL加载到UIWebView中,但它似乎不起作用.短暂出现黑屏,中间有vimeo播放按钮.然后在一秒钟之内全屏播放器打开大约一秒钟,关闭然后UIWebView变为白色.
我还在测试这个,到目前为止已经设法播放我们最长的视频,1小时45分钟,在iOS 6和5.1上没有问题.但希望这将有助于其他人开始.