【发布时间】:2012-01-08 15:10:12
【问题描述】:
我尝试在网络上搜索,但我找不到与此问题相关的不超过 1 年的主题;
如何在 iOS 应用中播放 Vimeo 视频?
EDIT1:当使用the solution 时,我有时会收到来自 Vimeo 的 HTTP 响应
为什么?
【问题讨论】:
-
你的意思是,不使用
UIWebView?
标签: objective-c ios vimeo
我尝试在网络上搜索,但我找不到与此问题相关的不超过 1 年的主题;
如何在 iOS 应用中播放 Vimeo 视频?
EDIT1:当使用the solution 时,我有时会收到来自 Vimeo 的 HTTP 响应
为什么?
【问题讨论】:
UIWebView?
标签: objective-c ios vimeo
这是我在应用内播放 Vimeo 视频的方式。
我正在使用 iFrame 在我的应用中加载 Vimeo 视频。
按照这些步骤,你也会的。
创建一个 uiwebview 并将其连接到您的 .h 文件。我的是 _webView。
将此方法添加到您的 .m 文件中。
-(void)embedVimeo{
NSString *embedHTML = @"<iframe width=\"300\" height=\"250\" src=\"http://www.vimeo.com/embed/rOPI5LDo7mg\" frameborder=\"0\" allowfullscreen></iframe>";
NSString *html = [NSString stringWithFormat:embedHTML];
[_webView loadHTMLString:html baseURL:nil];
[self.view addSubview:_webView];
}
我正在使用 Vimeo 视频中的嵌入代码。 (我希望你知道它是什么)
在你的 viewdidload 中调用这个方法
[self embedVimeo];
运行应用程序,您将在视图中看到视频。这种方式对我来说非常有效,我认为这对你也有帮助。
【讨论】:
你可以使用YTVimeoExtractor,对我来说很好。
【讨论】:
您可以使用此代码
NSString *htmlStringToLoad = [NSString stringWithFormat:@"http://player.vimeo.com/video/%@?title=0&byline=0&portrait=0\%%22%%20width=\%%22%0.0f\%%22%%20height=\%%22%0.0f\%%22%%20frameborder=\%%230\%%22", videoID];
[aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:htmlStringToLoad]]];
【讨论】:
UIWebView 解决方案,因为使用MPMoviePlayerController 比使用大型webkit 更好。
请尝试this, 它适用于我,只需几行代码。
- (void)viewDidLoad
{
[super viewDidLoad];
vimeoHelper = [[VimeoHelper alloc] init];
[vimeoHelper getVimeoRedirectUrlWithUrl:@"http://vimeo.com/52760742" delegate:(id)self];
}
- (void)finishedGetVimeoURL:(NSString *)url
{
_moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
[self presentViewController:_moviePlayerController animated:NO completion:nil];
}
【讨论】:
使用下面的代码,它会正常工作
NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1] ;
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: transparent;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendString:@"<iframe src=\"//player.vimeo.com/video/84403700?autoplay=1&loop=1\" width=\"1024\" height=\"768\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"];
[html appendString:@"</body></html>"];
[viewWeb loadHTMLString:html baseURL:urlMovie];
【讨论】:
urlMovie 应该设置为什么?您没有在代码中显示该定义。 :)
我用过这段代码:
NSString *embedSr = @"<iframe width=\"304\"height=\"350\" src=\"http://player.vimeo.com/video/... \" frameborder=\"0\" allowfullscreen></iframe>";
[[self WebView] loadHTMLString:embedSr baseURL:nil];
【讨论】:
我试过universal player,它在iOS 5 的设备上是成功的,但在iOS 4.2 的iPhone 3G 上却失败了。我不知道为什么。 Here's 嵌入它的链接。
或者您可以从 Vimeo 站点手动嵌入,单击嵌入,然后根据需要配置配置。
【讨论】: