开发者

Play video invoked from Javascript on a UINavigationController in iPhoneSDK

I have an application and on clicking a button, I want to create a UINavigationController on the fly. The current view on the navigationController would be a UIWebView rendering a JavaScri开发者_Python百科pt with an embedded video in it. When I click on the play button of the video, the video starts playing, but I'm not able to see the video on the foreground. I'm able to see the video only if I completely dismiss the UINavigationController.

How do I make sure that when I click on the "Play" button in the UIWebView inside the UINavigationController, renders the video in the native player in the foreground and when clicked on "Done" in the native player, I go back to the "UINavigationController" ?


How are you displaying initalizing the video view controller?

Are you creating an instance and presenting it as a modal view?

This also diffs depending on which version of iOS you are using:

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];


Below is the code snippet of how I create my UIViewController which needs to render the video:

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

"adHTML" is the URL which contains the javascript which has the video embedded in it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜