views:

1678

answers:

1

Hello all,

Till yesterday My MPMovieController was wokring fine in iPhone SDK 3 . But yesterday when I upgraded the SDK ti iphone SDK 4 my movieplayer stops working it is giving me a deprecation warning on the following line (They have deprecated lots of methods )

moviePlayer.movieControlMode = MPMovieControlModeDefault;

My full code is as follows :

NSURL *fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/videos/%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"SERVICE_URL"]
                                           ,customObject.movieURL]];

    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    if (mp)
    {
        // save the movie player object
        self.moviePlayer = mp;

        moviePlayer.movieControlMode = MPMovieControlModeDefault;
        [mp release];

        // Apply the user specified settings to the movie player object


        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(myMovieFinishedCallback:) 
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:moviePlayer];


        // Play the movie!
        [self.moviePlayer play];
    }

please Tell me which method to replace instead of the deprecated method or should do something different ?

Thanks ,

+2  A: 

I used the MPMoviePlayerController just this morning and this code works good (tested on iPad simulator only)

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"video.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(50, 50, 200, 200);  
[moviePlayer play];
Cesar
So we have to manully add the view now adn later remove also ?
hib
@hib: Apparently yes
Cesar
I am not adding any tmpView so It is not working . Is it necessary . because previously it was working without any of the tweaks .
hib
@Ceaser:are you using iphone sdk 4 ?
hib
@hib: Yes, I'm using iOS4 and no, you don't need any tmpView. Just set the frame of the view and addSubview:
Cesar
It is working fine now with your code . just two problem other then that the movieplayer appears after a thread is created (It takes some time ) . The previous one was howing immediately ( in ios 3.2 ). Statur bar change is bug already identified .If you have solution to this can you tell me please .
hib
The only reference to this delay it's here: http://developer.apple.com/iphone/library/qa/qa2009/qa1656.html but it's about remote streaming.Anyway, I didn't try yet, but you can try to pre-play the video and pause it on MPMoviePlayerLoadStateDidChangeNotification (just after the validation) and then when the user hit "play button" play it again. It's an hack, i know...
Cesar