3

我想使用 UIWebview 播放下载的视频。我得到 webkiterrordomain code=204 错误。但如果我从资源文件夹播放视频,它运行完美。//从资源文件夹运行完美

NSString *tempurl = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"video.mp4"];
   //from downloaded file
 NSString *tempurl = downloaded path;
NSURL* urlLocation = [NSURL fileURLWithPath:tempurl];
[webView loadRequest:[NSURLRequest requestWithURL:urlLocation]];

谢谢你。

4

4 回答 4

4

解决方案就在这里,你可以在 Embedded UIWebView 中播放视频。

- (void)viewDidLoad {

[super viewDidLoad];

NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"http://www.businessfactors.de/bfcms/images/stories/videos/defaultscreenvideos.mp4\" type=\"application/x-shockwave-mp4\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 412.0)];

[webView setOpaque:NO];
NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];

[self.view addSubview:webView];

}

于 2011-02-02T11:59:19.037 回答
3

WebkitErrorDomain 204只是意味着它将在MPInlinePlayerController. 所以你只需要忽略错误,视频就会播放。

于 2012-09-11T11:39:38.680 回答
0

生成一个html。将您的视频嵌入其中。在项目资源中包含 html 和视频文件。然后从 webview 加载 html。

于 2010-03-05T13:56:48.253 回答
-1

要播放本地视频文件,您可以使用 MPMoviePlayerController。

- (void) playVideo:(NSString *) videoName {
if ([self.fileManager fileExistsAtPath:videoName]) {
    [self stopVideo];
    self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoName]];
    [self.videoPlayer.view setFrame:CGRectMake(0, 0, 480, 360)];
    CGAffineTransform t1;
    t1 = CGAffineTransformMakeScale(-1.0,1.0);
    self.videoPlayer.view.layer.transform = CATransform3DMakeAffineTransform(t1);
    [self.view addSubview:self.videoPlayer.view];
    [self.videoPlayer setControlStyle:MPMovieControlStyleNone];
    [self.videoPlayer setScalingMode:MPMovieScalingModeAspectFit];
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(movieFinishedCallback:)
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:self.videoPlayer];
    [self.videoPlayer play];
}

}

- (void)stopVideo {
if (self.videoPlayer) {
    if ([self.videoPlayer playbackState] == MPMoviePlaybackStatePlaying) {
        [self.videoPlayer stop];
    }
    [self.videoPlayer.view removeFromSuperview];
    self.videoPlayer = nil;
}

}

- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];
[self.videoPlayer.view removeFromSuperview];

}

于 2014-11-18T11:58:50.860 回答