views:

72

answers:

2

Now I think I know about the differences between 3.X and 4 with regards the MPMoviePlaybackController and the need to set the view and have it fully working in a child view controller. But despite the following code seeming correct (to me) I still just get a blank screen for the duration of the movie. I know it plays successfully as moviePlayBackDidFinish fires.

Do I need to add it to a modal or similar at this point?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];

     player.fullscreen = YES;
     player.controlStyle = MPMovieControlStyleNone;
     [[player view] setFrame:window.bounds];
     [window addSubview: [player view]];

     [[NSNotificationCenter defaultCenter] addObserver:self 
                selector:@selector(moviePlayBackDidFinish:) 
                 name:MPMoviePlayerPlaybackDidFinishNotification 
                  object:player]; 
}
+1  A: 

the MPMoviePlayerController does NOT have a view property. you should/must use MPMoviePlayerViewController instead.

here's what I do:

        moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:currentChannel.StreamURI]];

    [moviePlayerViewController.moviePlayer setControlStyle:MPMovieControlStyleNone];
    moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    moviePlayerViewController.moviePlayer.shouldAutoplay = YES;
    [moviePlayerViewController.moviePlayer setScalingMode: MPMovieScalingModeAspectFit];
    moviePlayerViewController.view.frame = CGRectMake(0, 0, 480, 320); 


    [self.view addSubview:moviePlayerViewController.view];  

note that you might want to change movieSourceType to MPMovieSourceTypeFile or MPMovieSourceTypeUnknown. The above code is 100% of what I need to play a Movie (in my case a streaming channel)

samsam
Yes it does?!?! Im using it on another View controller, and its referenced in http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html#//apple_ref/doc/uid/TP40006953-CH3-SW49
tigermain
But maybe I should be using that, I'll have a go......
tigermain
Oh' I'm terribly sorry to have provided you with misleading information..
samsam
Still no joy :(
tigermain
So I created a test project and managed to solve the problem. both yours and my code is perfectly correct, all I'd done was put [window makeKeyAndVisible]; in my movieDidFinish when adding my main tabcontroller instead of when adding the splash video!
tigermain
A: 

In my case I had moved the

[window makeKeyAndVisible];

Out from

didFinishLaunchingWithOptions

and into my

movieDidFinish

By putting it back it worked

tigermain