iOS4 MPMoviePlayerController Embedding

2019-04-11 02:55发布

问题:

I am using MPMoviePlayerController currently to play a video inside IPhone and now I wish to play this video in a small area of the view (not the full screen). I think there is a frame way of doing it but I couldn't find the required tutorial somewhere. Have you been across any? That would be great.

UPDATED


I have reached to this point but still it doesn't show the player to play on screen.

-(IBAction)startVideo {
    //start video here
    NSURL *path = [[NSURL alloc] initWithString:[self localVideoPath:NO]];

    // Create custom movie player   
    MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:path] autorelease];

    [moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
    [moviePlayer setControlStyle:MPMovieControlStyleNone];
    [moviePlayer setFullscreen:FALSE];

    // May help to reduce latency
    [moviePlayer prepareToPlay];

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


    //---play partial screen---
    //moviePlayer.view.frame = CGRectMake(0, 0, 200, 300);
    moviePlayer.view.frame = image.frame;
    //[[moviePlayer view] setFrame: [image bounds]];

    [image removeFromSuperview];

    [self.view addSubview:moviePlayer.view];

    // Show the movie player as modal
    //[self presentModalViewController:moviePlayer animated:YES];

    // Prep and play the movie
    [moviePlayer play]; 
}

回答1:

Here is 'windowed' code...

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

[player setControlStyle:MPMovieControlStyleNone];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(movieFinishedCallback:)
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];
[player setScalingMode:MPMovieScalingModeAspectFill];
[player setFullscreen:FALSE];

//---play partial screen---
player.view.frame = CGRectMake(0, 0, 200, 300);
[self.view addSubview:player.view];