【问题标题】:How to play a Vimeo video in iOS?如何在 iOS 中播放 Vimeo 视频?
【发布时间】:2012-01-08 15:10:12
【问题描述】:

我尝试在网络上搜索,但我找不到与此问题相关的不超过 1 年的主题;

如何在 iOS 应用中播放 Vimeo 视频?

EDIT1:当使用the solution 时,我有时会收到来自 Vimeo 的 HTTP 响应

为什么?

【问题讨论】:

  • 你的意思是,不使用UIWebView?

标签: objective-c ios vimeo


【解决方案1】:

这是我在应用内播放 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];

运行应用程序,您将在视图中看到视频。这种方式对我来说非常有效,我认为这对你也有帮助。

【讨论】:

    【解决方案2】:

    你可以使用YTVimeoExtractor,对我来说很好。

    【讨论】:

    • 这是未来的证明吗?
    • 未来有什么证据吗?
    • 不,这不是未来的证明,Vimeo 也不支持。
    • 该项目仍在维护中,新功能即将推出。你可以继续使用它:)
    • 不要沮丧,但我确定这在 Vimeo ToS 中是不允许的:/
    【解决方案3】:

    您可以使用此代码

    NSString *htmlStringToLoad = [NSString stringWithFormat:@"http://player.vimeo.com/video/%@?title=0&amp;byline=0&amp;portrait=0\%%22%%20width=\%%22%0.0f\%%22%%20height=\%%22%0.0f\%%22%%20frameborder=\%%230\%%22", videoID];
            [aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:htmlStringToLoad]]];
    

    【讨论】:

    • 感谢您的解决方案。但似乎这只适用于某些视频?对于我的视频,我收到此消息“无法使用您的设置播放此视频”,而其他视频工作正常(例如 vimeo.com/32424117)。为什么?
    • 我需要一个 Vimeo Plus 帐户吗?
    • 我真的不知道,在YouTube上我知道有些视频是私人视频或仅限于某些地区,因此无法嵌入。无论如何,尝试使用 Vimeo API(适用于 iOS),并获取从服务器收到的错误。
    • 否决了这个UIWebView 解决方案,因为使用MPMoviePlayerController 比使用大型webkit 更好。
    • @ChristianBeer 当然,但这并不总是可能的。
    【解决方案4】:

    请尝试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];
    }
    

    【讨论】:

    • Vimeo ToS 是否允许这样做?我知道 YouTube 不允许直接解析视频文件。
    【解决方案5】:

    使用下面的代码,它会正常工作

    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&amp;loop=1\" width=\"1024\" height=\"768\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"];
    [html appendString:@"</body></html>"];
    
    
    [viewWeb loadHTMLString:html baseURL:urlMovie];
    

    【讨论】:

    • urlMovie 应该设置为什么?您没有在代码中显示该定义。 :)
    【解决方案6】:

    我用过这段代码:

    NSString *embedSr = @"<iframe width=\"304\"height=\"350\" src=\"http://player.vimeo.com/video/... \" frameborder=\"0\" allowfullscreen></iframe>";
    
    [[self WebView] loadHTMLString:embedSr baseURL:nil];
    

    【讨论】:

      【解决方案7】:

      我试过universal player,它在iOS 5 的设备上是成功的,但在iOS 4.2 的iPhone 3G 上却失败了。我不知道为什么。 Here's 嵌入它的链接。

      或者您可以从 Vimeo 站点手动嵌入,单击嵌入,然后根据需要配置配置。

      【讨论】:

        猜你喜欢
        • 2017-04-07
        • 2016-03-16
        • 2014-09-23
        • 2020-06-12
        • 1970-01-01
        • 1970-01-01
        • 2016-12-28
        • 2018-12-09
        • 1970-01-01
        相关资源
        最近更新 更多