开发者

Embedding Youtube videos in iOS [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Embedding YouTube videos on iOS

I am trying to embed youtube videos on iOS, so that when a user clicks a button, youtube video is shown without leavign the app, and once the video is done, the user is returned to the app. I found a tutorial online showing how to do this, and i followed it. I create a YouTubeView:

#import "YouTubeView.h"


@implementation YouTubeView

- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame {
    self = [super init];
    if (self) 
    {
        // Create webview with requested frame size
        self = [[UIWebView alloc] initWithFrame:frame];

        // HTML to embed YouTube video
        NSString *youTubeVideoHTML = @"<html><head>\
        <body style=\"margin:0\">\
        <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
        width=\"%0.0f\" height=\"%0.0f\"></embed>\
        </body></html>";

    开发者_StackOverflow社区    // Populate HTML with the URL and requested frame size
        NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];

        // Load the html into the webview
        [self loadHTMLString:html baseURL:nil];
    }
    return self;  
}

#pragma mark -
#pragma mark Cleanup

- (void)dealloc 
{
    [super dealloc];
}

@end

and I am instantiating it like this: (case 2)

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    SongInfoTableVC *infoVC;
    YouTubeView *youTubeView;
    switch (buttonIndex) {
        case 0:
            NSLog(@"hello");
            [self setLyrics];
            break;
        case 1:
            infoVC = [[SongInfoTableVC alloc] initWithStyle:UITableViewStyleGrouped];
            [infoVC setBook:data];
            [infoVC setTitle:@"Song Info"];
            [[self navigationController] pushViewController:infoVC animated:YES];
            [infoVC release];
            break;
        case 2:
            youTubeView = [[YouTubeView alloc] 
                                        initWithStringAsURL:@"http://www.youtube.com/watch?v=xli2E2i8GZ4" 
                                        frame:CGRectMake(0, 0, 320, 480)];

            [[[self navigationController] view] addSubview:youTubeView];
            break;
        default:
            break;
    }
}

but this bring up a blank white screen. What am I doing wrong? Here's the screenshot:

Embedding Youtube videos in iOS [duplicate]

Thanks


Try testing on a device. I don't think this method is supported in the simulator.

See here: Embedding YouTube videos on

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜