tags:

views:

36

answers:

2

Hi , 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(myMovieFinishedCallback:)

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

}
A: 

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

Engin Kurutepe
how to do this ? i triedself.view = theMovie.view;and it worked , but i think it is not what you meanti tried: [self.view addSubView:theMovie.view] but also resulted to sound only
belhaouary
did you set the frame property of theMovie.view correctly before adding it as a subview?
Engin Kurutepe
A: 

Exact same question earlier today: http://stackoverflow.com/questions/3750412/mpmovieplayercontroller-worked-fine-up-to-ios-4-0-now-just-plays-sound-no-video/3750497#3750497

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

Larsaronen
this results in the following warning incompatible Objective-C types 'struct MPMoviePlayerController *', expected 'struct MPMoviePlayerViewController *' when passing argument 1 of 'presentMoviePlayerViewControllerAnimated:' from distinct Objective-C typeand also i hear the sound but no video appears on screen
belhaouary
Ohh sorry did'nt see that. Change youre MPMoviePlayerController to MPMoviePLayerViewController
Larsaronen