unable to play video in iOS 4

扶醉桌前 提交于 2019-12-10 11:25:55

问题


I have written code to play video in iPhone OS 3.1.3 and video is playing fine.

but when i am trying to play video with the same code then video is not playing in iOS 4.

I know that Media player framework is changed for iOS 4. Is there any way i can play the video on different OS without preparing separate binary??


回答1:


First check if you are on OS 3.2 or above. If yes, create a movie player the new way:

if (NSClassFromString(@"UISplitViewController") != nil) {
  MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:yourURL];
  [[mp moviePlayer] prepareToPlay];
  [[mp moviePlayer] setShouldAutoplay:YES];
  [[mp moviePlayer] setControlStyle:2];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
  [self presentMoviePlayerViewControllerAnimated:mp];
} else {
  moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:yourURL];
  [self playMovieTheOldWay:moviePlayer];
}

You can close the new movie player like this:

-(void)videoPlayBackDidFinish:(NSNotification*)notification
{       
  [self dismissMoviePlayerViewControllerAnimated];
}


来源:https://stackoverflow.com/questions/3341782/unable-to-play-video-in-ios-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!