开发者

playing video on iphone

i have a weird problem in my application. I am trying to play video on iphone after pressing a button in the UI.My problem is that it is played as audio only . and media player doesn't show up , i just hear the sound. Below is the code of the methods i use to play video.

-(void) playMovieAtURL: (NSURL*) theURL {

MPMoviePlayerController* theMovie =

[[MPMoviePlayerController alloc] initWithContentURL: theURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;

theMovie.movieControlMode = MPMovieControlModeDefault;

// Register for the playback finished notification

[[NSNotificationCenter defaultCenter]

 addObserver: self

 selector: @selector(myMovieFi开发者_如何转开发nishedCallback:)

 name: MPMoviePlayerPlaybackDidFinishNotification

 object: theMovie];

[theMovie play];
}   



-(void) myMovieFinishedCallback: (NSNotification*) aNotification

{

MPMoviePlayerController* theMovie = [aNotification object];

[[NSNotificationCenter defaultCenter]

 removeObserver: self

 name: MPMoviePlayerPlaybackDidFinishNotification

 object: theMovie];

[theMovie release];

}

and this is how i call the previous functions to play a video located in my resources

-(IBAction)play:(id)sender
{
NSString * url;
NSURL *theUrl;

NSBundle *bundle = [NSBundle mainBundle];
if (bundle) 
{
    NSString *moviePath = [bundle pathForResource:@"240_320_p" ofType:@"mp4"];
    if (moviePath)
    {
        theUrl = [NSURL fileURLWithPath:moviePath];
    }
}

[self playMovieAtURL:theUrl];

}


You should add theMovie.view to your view hierarchy when you start playback and remove it again after the playback is done.


Exact same question earlier today: MPMoviePlayerController worked fine up to iOS 4.0 now just plays sound, no video

You need to add [self presentMoviePlayerViewControllerAnimated:theMovie];..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜