开发者

Video not showing in iPhone Simulator (but I can hear audio from the video)

I am new to xcode, interface builder, and the iphone simulator. I am trying to play a movie/video in xcode on the click of a button (which is very straightforward). I am using xcode 3.2.4 and iphone simulator 4.1.

When I launch the iPhone simulator and click the button to launch the video, the audio plays, but the video is hidden. It's as if the video is behind the tab bar (this is part of a tab bar application). I am not sure how to make the video play in front.

Here's the code:

    -(IBAction)launchVideo2:(id)sender{

 NSString *movieFile;
 MPMoviePlayerController *moviePlayer;

 movieFile = [[NSBundle mainBundle] 
     pathForResource:@"IGDIs_Video_Picture_Naming_iPhone" ofType:@"mp4"];
 moviePlayer = [[MPMoviePlayerController alloc] 
       initWithContentURL: [NSURL fileURLWithPath: movieFile]];

 [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(playMediaFinished:)
             name:MPMoviePlayerPlaybackDidFinishNotification
              object:moviePlayer];
 moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
 [moviePlayer play];
}

-(void)playMediaFinished:(NSNotification*)theNotification
{
 MPMoviePlayerController *moviePlayer=[theNotification object];

    [[NSN开发者_高级运维otificationCenter defaultCenter] removeObserver:self
             name:MPMoviePlayerPlaybackDidFinishNotification
              object:moviePlayer];

    [moviePlayer release];
}

Any suggestions would be great!


should be using the MPMoviePlayerViewcontroller

see apple documentation

http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html


It doesn't look like you have added the movie view to your main view. You'll need to add something like:

    ...
    [[moviePlayer view] setFrame:[self view] bounds]];
    [[self view] addSubview:[moviePlayer view]]; 
    [moviePlayer play];
}

before playing it. I'm assuming that the a launchVideo2 method is in a UIViewController that owns the main view. You might have to change [self view] to suit your code to correspond to the view where you want the movie to play.


In my experience, video won't display in the sim. However, audio will. (Which is an improvement, since previously neither would play.)

Try running the app on the device. If the video doesn't display there, post here and we'll work through the issue.


You have a probably unrelated memory issue there:

  • In your first method, you don't release the player, which is a local variable.
  • In your second method, you release the player, that you don't own.

Proper memory management (ie best practice), you would do this with an ivar.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜