I’ve come across a rather strange problem. What I’m trying to do right now is only obtain the audio of a YouTube video for a given link. I’ve tried a couple of things but it either didn’t work or wasn’t efficient.
Thus I’ve decided to ask more experienced iOS developers in here. Thanks in advance.
@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)];
}
just play the video with your media player, but dont give it a frame, this will play the audio, but not load the image