【问题标题】:Youtube - iPhone - displaying UIWebView of videoYoutube - iPhone - 显示视频的 UIWebView
【发布时间】:2011-06-11 09:37:32
【问题描述】:

我的应用程序中有一个脚本,它在 UIView 的一部分中加载一个 Youtube 链接,该链接由我的服务器(mySQL/使用 php)提供,并从中加载......下面的这个脚本工作正常。 ....然而...

这就是我现在所拥有的,我正在寻找以编程方式删除它的部分(它提供尺寸并可能用 UIWebView 替换它),所以我可以使用 IB 即兴创作,这将在我的应用程序启动时有所帮助,会出现一个快速动画,然后我希望这个 youtube 链接在 viewDidLoad 完成后加载和显示。

.h 文件:

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame;

.m 文件

//view did load function...

[self embedYouTube:youtubestring frame:CGRectMake(69,72,184,138)];

//after the view did load is closed I have..

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}

任何帮助将不胜感激!谢谢

【问题讨论】:

    标签: iphone sdk uiwebview youtube


    【解决方案1】:

    嗯,iPhone 没有 Flash。它从来没有,也可能永远不会有。在 iPhone 上打开 youtube 视频的唯一方法是通过 youtube 应用程序,它以另一种格式播放它们。一个例子是 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com /v/oHg5SJYRHA0&amp;f=gdata_videos&amp;c=ytapi-my-clientID&amp;d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM"]];
    您可以在此处找到更多详细信息:http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

    【讨论】:

    • 实际上我现在工作的代码并没有打开 youtube 应用程序,并且实际上播放了 youtube 视频(从您的应用程序内部),只是说,它在应用程序商店中......它只是使用CGRect 而不是界面生成器....我知道 iPhone 不支持 Flash,但认为它们可能是一种解决方法...谢谢...
    • 此链接向您展示如何嵌入 YouTube 视频:apiblog.youtube.com/2009/02/…
    【解决方案2】:

    这可以使用在 IB 中创建的 UIWebViews:

    .h 文件:

    @property (nonatomic, retain) IBOutlet UIWebView *infoVideo1;
    
    -(void)embedYouTubeInWebView:(NSString*)url theWebView: (UIWebView *)aWebView;
    

    .m 文件:

    在viewDidLoad中:

    [self embedYouTubeInWebView:youTubeString theWebView:infoVideo1];
    

    方法:

    - (void)embedYouTubeInWebView:(NSString*)url theWebView:(UIWebView *)aWebView {     
    
    NSString *embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";
    
    NSString* html = [NSString stringWithFormat:embedHTML, url, aWebView.frame.size.width, aWebView.frame.size.height]; 
    
    [aWebView loadHTMLString:html baseURL:nil];
    }
    

    您甚至可以在一个屏幕上拥有多个 webView。希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      iOS 有一个 safari 插件,可以播放嵌入为 flash 的 youtube 视频。

      我整理的这个 uiwebview 类别将为您嵌入视频,而无需离开应用程序或教程 :-)

      https://github.com/enigmaticflare/UIWebView-YouTube--iOS-Category--ARC-compliant-code

      【讨论】:

        猜你喜欢
        • 2011-09-11
        • 1970-01-01
        • 2012-01-29
        • 2015-04-29
        • 2012-03-17
        • 1970-01-01
        • 1970-01-01
        • 2011-11-24
        • 1970-01-01
        相关资源
        最近更新 更多