-1

我想使用 uiwebview 播放你的视频,我使用以下代码播放视频

[self playVideo:@"http://www.youtube.com/watch?v=WL2l_Q1AR_Q" frame:CGRectMake(20, 70, 280, 250)];

- (void)playVideo:(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];
    NSLog(@"%@",html);
}

但我无法在我的模拟器中观看视频。

谁能说我在哪里犯了错误?提前谢谢...

4

3 回答 3

0

您的代码在真实设备上运行良好。我在我的 iPhone 4 iOS 5.0 上对其进行了测试。我认为问题在于模拟器,而不是您的代码。

于 2012-09-22T12:01:06.070 回答
0

值得注意的是,这段代码只能在设备上运行,不能在模拟器中运行。

- (void)playVideo
    {
        float width = 200.0f;
            float height = 200.0f;

            NSString *youTubeURL = @"http://www.youtube.com/watch?v=ZiIcqZoQQwg";

            UIWebView *wv = [[[UIWebView alloc] init] autorelease];
            wv.frame = CGRectMake(60, 60, width, height);

            NSMutableString *html = [[[NSMutableString alloc] initWithCapacity:1] autorelease];
            [html appendString:@"<html><head>"];
            [html appendString:@"<style type=\"text/css\">"];
            [html appendString:@"body {"];
            [html appendString:@"background-color: transparent;"];
            [html appendString:@"color: white;"];
            [html appendString:@"}"];
            [html appendString:@"</style>"];
            [html appendString:@"</head><body style=\"margin:0\">"];
            [html appendFormat:@"<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\"", youTubeURL];
            [html appendFormat:@"width=\"%0.0f\" height=\"%0.0f\"></embed>", width, height];
            [html appendString:@"</body></html>"];

            [wv loadHTMLString:html baseURL:nil];

            [self.view addSubview:wv];
于 2012-09-22T11:09:37.230 回答
0

只需使用此代码向您展示Tube 视频:!!//首先IBOutlet UIWebView *webView在(.h)文件中初始化和合成

   [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=ZiIcqZoQQwg"]]];
于 2012-09-22T11:14:10.867 回答