【问题标题】:How to load a video in webView other than youtube [duplicate]如何在 youtube 以外的 webView 中加载视频 [重复]
【发布时间】:2012-12-20 12:09:42
【问题描述】:

我正在尝试在我的 webview 中从网络加载一个视频,这个视频不是来自 youtube 我不知道如何加载它除了这段代码之外任何人都可以帮助我

- (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)];
    [vebview loadHTMLString:html baseURL:nil];
    [self.view addSubview:vebview];
}
- (void)viewDidLoad
{
    [self embedYouTube:@"http://player.vimeo.com/video/32983838" frame:CGRectMake(0, 0, 320, 449)];
    [super viewDidLoad];
}

【问题讨论】:

    标签: iphone ios xcode video webview


    【解决方案1】:

    您可以使用 MPMoviePlayerController 控件播放视频。

    &lt;MediaPlayer/MediaPlayer.h&gt; 框架导入应用程序。

    .h 文件

    #import <MediaPlayer/MediaPlayer.h>
    
    MPMoviePlayerController *moviePlayerController;
    

    .m 文件

    -(void)startVideo:(NSString*)fileURL
    {
       UIWebView *w = [[UIWebView alloc] init];
       w.frame = CGRectMake(10, 0, 300, 340);
       w.backgroundColor = [UIColor clearColor];
    
       moviePlayerController = nil;
       CGRect rect = CGRectMake(10, 0, 300, 400);
    
       moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
       [moviePlayerController.view setFrame:rect];
       moviePlayerController.fullscreen = YES;
    
    
       [moviePlayerController play];
    
       [w addSubview:moviePlayerController.view];
    }
    

    在这里,我使用了动态网络视图内视图。你可以直接被XIB使用。

    希望对你有所帮助。

    谢谢。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-18
    • 2017-12-30
    • 2012-10-06
    • 2011-06-23
    • 2012-12-18
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多