如何只播放YouTube视频的音频?

时间:2012-04-25 23:31:05

标签: ios performance cocoa-touch youtube video-streaming

我遇到了一个相当奇怪的问题。我现在要做的只是获取给定链接的YouTube视频的音频。我尝试了几件事,但它要么不起作用,要么效率不高。

因此,我决定在这里询问更有经验的iOS开发人员。提前谢谢。

@implementation ViewController
@synthesize web;

- (void)embedYouTube:(NSString*)url 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, url, frame.size.width, frame.size.height];

        UIWebView *webView =[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        [webView loadHTMLString:html baseURL:nil];
        [self.view addSubview:webView];
}

-(IBAction)play{

    [self embedYouTube:@"http://www.youtube.com/watch?v=iw1aT5c1Lus" frame:CGRectMake(0, 0, 320, 480)];

}

1 个答案:

答案 0 :(得分:4)

只是用您的媒体播放器播放视频,但不要给它一个帧,这将播放音频,但不加载图像