使用iOS 6的iPhone应用程序中嵌入的vimeo视频无法播放 [英] Embedded vimeo video in iPhone app using iOS 6 not playing

查看:158
本文介绍了使用iOS 6的iPhone应用程序中嵌入的vimeo视频无法播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在iOS 6中播放任何视频。无论是在设备(iP4)还是模拟器上。

I can't seem to get any videos playing in iOS 6. Both on the device (iP4) and simulator.

我所拥有的是UIWebView设置IB。然后在我的 viewDidLoad 中,我有以下代码:

What I have is a UIWebView setup in IB. Then in my viewDidLoad I have the following code:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://domain.com/app/player.php?vid=%@", [videoDetails objectForKey:@"vid"]]];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[videoWebView loadRequest:requestObj];

只是为了解释,vimeo上的视频设置是只允许托管在特定的域,否则将显示错误消息。所以我在player.php中设置了一些简单的HTML,只调用vimeo嵌入代码。

Just to explain, the video settings on vimeo are that it is only allowed to be hosted on a specific domain, otherwise it will display an error message. So I have some simple HTML set up in player.php that just calls the vimeo embed code.

当我转到其上有UIWebView的视图时,视频已加载并且您在vimeo视频中看到播放图标,我点击该图标然后视频显示加载图标,然后大约5-10秒后,控制台输出以下内容,UIWebView变为白色。

When I go to the view that has the UIWebView on it, and the video has loaded in and you see the 'play' icon in the vimeo video, I click that and then the video shows a loading icon and then after about 5-10 seconds, the console outputs the below and the UIWebView just goes white.

控制台输出:

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)

在iOS 5上,vi deo只是按预期播放。问题是,这与vimeo无关。我尝试了以下内容:

On iOS 5, the video just plays as expected. The thing is, this isn't related to just vimeo. I've tried the following:

Vimeo随机公开视频(没有嵌入在domain.com上托管的文件中)

Vimeo random public video (no embedding in a file hosted on 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]]];

然后再次使用YouTube:

And then again with YouTube:

[videoWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=dABo_DCIdpM"]]];

我唯一关心的是让它使用Vimeo视频,因为这是它们全部存储的地方。但我不能看到vimeo在这里成为问题因为它在YT上也不起作用所以必须有一些我做错了让iOS 6保持开心?我已经用Google搜索了一下,我似乎根本找不到任何解决方案,即使我认为这只是我发生的事情。

My only concern is getting it working with Vimeo videos, as this is where they are all stored. But I can't see vimeo being the problem here as it doesn't work on YT either so there must be something I'm doing wrong to keep iOS 6 happy? I've Googled around a bit and I can't seem to find any solution at all, even though I don't think it's just me this has happened to.

在此先感谢。

推荐答案

为此,我不得不完全抛弃UIWebView。

For this I had to ditch the UIWebView completely.

我不知道你是否在免费的vimeo账户上获得这个,但在我们的PRO账户上,在视频设置中有一个视频文件选项卡,在底部有一个标有HTTP直播流的字段,这几乎是你视频的直接链接。

I don't know if you get this on free vimeo accounts, but on our PRO account, in the video settings there's a tab for 'video file' and at the bottom there's a field labelled 'HTTP Live Streaming' and there's practically a direct link to your video.

然后我使用MPMoviePlayerViewController来播放视频,而不是UIWebView。

And then instead of the UIWebView, I used MPMoviePlayerViewController to play the video.

将MediaPlayer.framework添加到Link Binary With Libraries设置中。
在我的视图控制器的.h文件中,我有一个UIImageView,几个标签和一个播放按钮,我导入了 #import< MediaPlayer / MediaPlayer.h> 并设置一个属性 @property(nonatomic,readonly)MPMoviePlayerViewController * player;

Add the MediaPlayer.framework into your 'Link Binary With Libraries' setting. In the .h file of my view controller that has a UIImageView, a couple of labels, and a play button, I imported #import <MediaPlayer/MediaPlayer.h> and setup a property @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];
}

我确实尝试将HTTP实时流URL加载到UIWebView中,但它没有似乎工作。短暂出现黑屏,中间有vimeo播放按钮。然后在一秒钟之内,全屏播放器打开大约一秒钟,关闭然后UIWebView变白。

I did try loading the HTTP Live Stream URL into the UIWebView, but it doesn't seem to work. A black screen briefly appears with the vimeo play button in the middle. Then within a second of that the fullscreen player opens for about a second, closes and then the UIWebView goes white.

我还在测试这个,到目前为止设法播放我们最长的视频,1小时45分钟,无需在iOS 6和5.1上通过WiFi发布。但希望这将有助于其他人作为开始。

I'm still testing around with this and so far have managed to play our longest video, 1hr 45min without issue over WiFi on iOS 6 and 5.1. But hopefully this will help others out as a start.

这篇关于使用iOS 6的iPhone应用程序中嵌入的vimeo视频无法播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆