在iPhoneSDK中的UINavigationController上播放从Javascript调用的视频

在iPhoneSDK中的UINavigationController上播放从Javascript调用的视频,javascript,iphone,video,uiwebview,uinavigationcontroller,Javascript,Iphone,Video,Uiwebview,Uinavigationcontroller,我有一个应用程序,单击一个按钮,我想动态创建一个UINavigationController。navigationController上的当前视图将是一个UIWebView视图,呈现一个JavaScript,其中包含一个嵌入式视频。当我点击视频的播放按钮时,视频开始播放,但我无法看到前景上的视频。只有完全关闭UINavigationController,我才能看到视频 如何确保当我在UINavigationController中单击UIWebView中的“播放”按钮时,在前台的本机播放器中呈现视

我有一个应用程序,单击一个按钮,我想动态创建一个
UINavigationController
navigationController
上的当前视图将是一个
UIWebView
视图,呈现一个
JavaScript
,其中包含一个嵌入式视频。当我点击视频的播放按钮时,视频开始播放,但我无法看到前景上的视频。只有完全关闭
UINavigationController
,我才能看到视频


如何确保当我在
UINavigationController
中单击
UIWebView
中的“播放”按钮时,在前台的本机播放器中呈现视频,当我在本机播放器中单击“完成”时,我返回到“
UINavigationController
”?

初始化视频视图控制器时如何显示

您是否正在创建实例并将其显示为模态视图

这也因您使用的iOS版本而异:

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];

if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
    NSLog(@"> 3.2");

    MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

    self.playerController = player;

    [player release]; player = nil;

    [self presentMoviePlayerViewControllerAnimated: self.playerController];
    self.playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:self.playerController.moviePlayer];


    [self.playerController.moviePlayer play];

} 
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
    NSLog(@"< 3.2");

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: videoURL];

    player.scalingMode = MPMovieScalingModeAspectFill;

    // Register for the playback finished notification
    [[NSNotificationCenter defaultCenter]
     addObserver: self
     selector: @selector(playbackFinished:)
     name: MPMoviePlayerPlaybackDidFinishNotification
     object: player];

    // Movie playback is asynchronous, so this method returns immediately.
    [player play];
NSString*videoPath=[[NSBundle mainBundle]pathForResource:@“mp4”类型的“video”;
NSURL*videoURL=[NSURL fileURLWithPath:videoPath];
如果([[[UIDevice currentDevice]systemVersion]doubleValue]>=3.2){
NSLog(@“>3.2”);
mpmovieplayervewcontroller*player=[[mpmovieplayervewcontroller alloc]initWithContentURL:videoURL];
self.playerController=玩家;
[玩家释放];玩家=零;
[self-PresentMoviePlayerController激活:self.playerController];
self.playerController.moviePlayer.movieSourceType=mpmoviesourcetype文件;
[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(PlaySufficFinish:)名称:@“MPMoviePlayerPlaybackDidFinishNotification”对象:self.playerController.moviePlayer];
[self.playerController.moviePlayer play];
} 
如果([[[UIDevice currentDevice]systemVersion]doubleValue]<3.2),则为else{
NSLog(@“<3.2”);
MPMoviePlayerController*player=[[MPMoviePlayerController alloc]initWithContentURL:videoURL];
player.scalingMode=MPMovieScalingModeAspectFill;
//注册播放完成通知
[[NSNotificationCenter defaultCenter]
addObserver:self
选择器:@选择器(已完成播放:)
名称:MPMoviePlayerPlaybackDidFinishNotification
对象:玩家];
//电影播放是异步的,因此此方法立即返回。
[玩家游戏];

下面是我如何创建需要渲染视频的UIViewController的代码片段:

UIViewController *adViewController = [[UIViewController alloc] init];
UIWebView *adView = [[UIWebView alloc] initWithFrame:r];
[adView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:adHTML]]];
adViewController.view = adView;

“adHTML”是包含javascript的URL,javascript中嵌入了视频。

关键是,只有当javascript中包含视频标记时,我才需要渲染视频!我认为只有在我们确实知道视频链接的情况下,上面的代码才能工作。你有javascript字符串的示例吗?