开发者

How do I display video from AppDelegate in iOS4

开发者 https://www.devze.com 2023-01-07 18:04 出处:网络
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

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 {    

    MPMovieP开发者_开发百科layerController *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]; 
}


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)


In my case I had moved the

[window makeKeyAndVisible];

Out from

didFinishLaunchingWithOptions

and into my

movieDidFinish

By putting it back it worked

0

精彩评论

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

关注公众号