Playing video in custom size screen - view in iPhone

前端 未结 5 517
死守一世寂寞
死守一世寂寞 2020-12-18 13:24

Suppose user taps on a button and video begins to play. Now when video plays, it always in full screen mode.

Video should be played in a portrait mode (but normally

5条回答
  •  攒了一身酷
    2020-12-18 13:43

    Here's what I did. Add NSNotification to notify you when preloading of the video finishes.

    - (void)playVideoUrl:(NSString *)videoUrl {
        NSURL *url = [NSURL URLWithString:videoUrl];
        MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc]   
                 initWithContentURL:url]; 
        [[NSNotificationCenter defaultCenter] addObserver:self 
    
        //MPMoviePlayerContentPreloadDidFinishNotification
        [[NSNotificationCenter defaultCenter] addObserver:self                           
                           selector:@selector(myMovieFinishedPreloading:)                                            
                               name:MPMoviePlayerContentPreloadDidFinishNotification                                                
                             object:theMovie]; 
    
    
        // Movie playback is asynchronous, so this method returns immediately. 
        [theMovie play]; 
         }
    

    Callback selector:

    -(void)myMovieFinishedPreloading:(NSNotification*)aNotification  {
        NSArray *windows = [[UIApplication sharedApplication] windows];
    
        UIWindow *moviePlayerWindow = nil;
        if ([windows count] > 1) 
        {
            moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
        }
    
        CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
        transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
        [moviePlayerWindow setTransform:transform];
    
     }
    

提交回复
热议问题