Search code examples
videompmovieplayercontroller

Replacing a 480x640 mp4 with a 640x1136 mp4 won't play


I'm a beginner at coding.

I made an app that plays a 480x640 mp4 upon start up. Decided to replace with a larger video so it would look better on larger iPhone. Imported the new 640x 1136 mp4, replaced the name in the code, changed the size of the setFrame:CGRectMake. Upon start up it plays in black- as if the moviePlayer is in the wrong position.

Interestingly, I have the exact same code later in the program ("press a button to replay the Open Video") and that works fine.

What is wrong with the size, or position of my initial moviePlayer?


Just figured out that if I 1/2 the size of my viewer from (0, 0, 640, 1136) to (o, 0, 320, 568) it will play fine. Again, later in the program I have the viewer at (0, 0, 640, 1136). Why does the same mp4 play at two different viewer sizes?


Thanks

- (void)viewDidLoad
{
    //
    // backGround image
    //
    UIImage *backGround1 = [UIImage imageNamed:@"TableWButtons6401136.png"];
    [backGround setImage:backGround1];


    //
    // This code plays the video at start up
    //
    NSString *videoFile = [[NSBundle mainBundle] pathForResource:@"WFBD4" ofType:@"mp4"];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoFile]];
    [moviePlayer.view setFrame:CGRectMake(0, 0, 640, 1136)];
    [self.view addSubview:moviePlayer.view];

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

    moviePlayer.fullscreen = YES;
    moviePlayer.allowsAirPlay  = YES;
    moviePlayer.controlStyle = MPMovieControlStyleNone;
    [moviePlayer play] ;
    NSLog(@"Playback Finished");





    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

Solution

  • The coordinates passed to setFrame are in Points, not device pixels. These Points are logical pixels; the same sizes and positions will work on both Retina and non-Retina devices. The iPhone 5+ has 320x568 points, but 640x1136 device pixels.

    Therefore, calling setFrame with 320x568 is the correct thing to do. While you haven't shown the code for the replay button, I would guess that, in that instance, the player view is being resized by some auto-layout logic.