简体   繁体   中英

MPMoviePlayerController doesn't play video frame ios7

I am porting app from iOS6 to iOS7. There is a weird problem that makes the screen go black after the call from a button is being done. I have tried out this , this and this .

There is no apt answer and I don't feel theoretically there should be any problem in using the previous methods.

Kindly provide me some thread to why this problem is occuring.

Thanks

This can help Import MediaPlayer in your .h file

#import <MediaPlayer/MediaPlayer.h>

Make a property

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

After that you can play video by this

-(void)playMovie:(id)sender
{
  NSURL *url = [NSURL URLWithString:
  @"http://www.xyz.com/ios_book/movie/movie.mov"];

_moviePlayer =  [[MPMoviePlayerController alloc]
             initWithContentURL:url];

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

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}

After that for removing the video view add this

   - (void) moviePlayBackDidFinish:(NSNotification*)notification {
   MPMoviePlayerController *player = [notification object];
   [[NSNotificationCenter defaultCenter]
    removeObserver:self
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:player];

  if ([player
    respondsToSelector:@selector(setFullscreen:animated:)])
 {
    [player.view removeFromSuperview];
 }
 }

Add your movie player controller view on main windows like:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:@"map.mp4"]]; 

[player prepareToPlay]; 

[player.view setFrame: self.view.bounds];

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[appDelegate.window addSubview: player.view];

[player play];

Hope so it will work for you!

Try this way..

ViewController.m

MPMoviePlayerViewController *mp=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[arr_videos objectAtIndex:indexPath.row]valueForKey:@"Video_path"]]];

MPMoviePlayerController *pc=[mp moviePlayer];

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

[self presentViewController:mp animated:YES completion:nil];
[pc prepareToPlay];
[pc play];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM