【发布时间】:2012-01-04 12:57:34
【问题描述】:
我在使用网络应用程序和 phonegap 播放视频时遇到问题。我的网络应用程序中有一个链接直接链接到 mp4 文件。我在 phonegap 的 AppDelegate 类中为这种类型的 URL 添加了一个处理程序。
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:
(NSURLRequest *)request navigationType:
(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
NSLog(@"redirect detected");
if ([[[url path] pathExtension] isEqualToString:@"mp4" ] || [[[url path] pathExtension] isEqualToString:@"m4v" ] || [[[url path] pathExtension] isEqualToString:@"m3u8" ]) {
//video files are .mp4 or m4v, stream indexes are m3u8
//it's a movie, go play!
NSLog(@"Movie detected - playing");
NSLog([url path]);
[self playMovieAtURL:url];
return NO;
} else {
return [ super webView:theWebView shouldStartLoadWithRequest:request
navigationType:navigationType ];
}
}
这很好,并且调用了电影播放的方法。方法是这样实现的(一):
-(void) playMovieAtURL: (NSURL*) theURL {
NSLog(@"PlayMovieAtUrl");
MPMoviePlayerController* theMovie =
[[MPMoviePlayerController alloc] initWithContentURL: theURL];
[self presentMoviePlayerViewControllerAnimated:theMovie];
}
也试过这个(2):
-(void) playMovieAtURL: (NSURL*) theURL {
NSLog(@"PlayMovieAtUrl");
MPMoviePlayerController* theMovie =
[[MPMoviePlayerController alloc] initWithContentURL: theURL];
[theMovie setControlStyle:MPMovieControlStyleFullscreen];
[theMovie setFullscreen:YES];
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
NSLog(@"About to play");
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
但在这两种情况下,播放器都是创建并播放的。唯一的问题是,它是隐藏的。可以听到声音,但没有图像。 webView 仍然显示。 (1)应该根据其他地方的帖子在没有任何设置的情况下工作。问题(我猜)是,它是在 AppDelegate 类中调用的,而不是在 Controller 类中。但我不知道如何使用 phonegap 实现这一点 :( 有什么想法吗?
【问题讨论】:
-
如果您需要更多信息,请告诉我