Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 在iOS中嵌入Youtube视频_Cocoa Touch_Ios_Uiwebview_Uiviewcontroller_Youtube - Fatal编程技术网

Cocoa touch 在iOS中嵌入Youtube视频

Cocoa touch 在iOS中嵌入Youtube视频,cocoa-touch,ios,uiwebview,uiviewcontroller,youtube,Cocoa Touch,Ios,Uiwebview,Uiviewcontroller,Youtube,可能重复: 我正在尝试在iOS上嵌入youtube视频,这样当用户单击按钮时,youtube视频将在不显示应用程序的情况下显示,视频播放完毕后,用户将返回应用程序。我在网上找到了一个教程,展示了如何做到这一点,我遵循了它。我创建了一个YouTubeView: #import "YouTubeView.h" @implementation YouTubeView - (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame

可能重复:

我正在尝试在iOS上嵌入youtube视频,这样当用户单击按钮时,youtube视频将在不显示应用程序的情况下显示,视频播放完毕后,用户将返回应用程序。我在网上找到了一个教程,展示了如何做到这一点,我遵循了它。我创建了一个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>";

        // 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
但这会带来一个空白的白色屏幕。我做错了什么? 以下是截图:


谢谢

尝试在设备上测试。我认为模拟器不支持这种方法


请参见此处:

谢谢,我在设备上试用过,效果很好!您好,我有同样的问题,现在我成功地在设备中播放视频,但还有一个问题,即视频仅在ios版本5.1.1中播放,如果我想在ios版本5.1.1以下的版本中播放视频,我该怎么办?
- (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;
    }
}