2 개의 절반으로 구성된 UIViewController가 있습니다 (실제로는 UIContainerViews에 있음). 1 1/2에는 PDF를 표시하는 데 사용되는 UIWebView가 있고 다른 절반에는 비디오를 스트리밍하는 데 사용되는 UIView가 포함되어 있습니다. 모달 전체 화면 iOS 8 이후 비디오가 mpmovieplayercontroller에서 재생되지 않습니다.
- (IBAction)pressedFullscreenButton:(id)sender
{
// pause the video view controller
self.videoViewController.videoPlayer pause];
// perform the segue - this is modal, full screen
[self performSegueWithIdentifier:@"FullscreenSegue" sender:self];
}
그래서 내가 전체 화면 버튼, 비디오 일시 정지, 그리고 내 PDF /있는 UIWebView를 누릅니다
누르면 전체 화면 모드에서 모달있는 UIWebView를 제시하는있는 UIButton과 함께있는 UIWebView와 탐색 모음은있다 모달, 전체 화면으로 표시됩니다. 이 전체 화면보기 컨트롤러를 닫아서 분할 화면으로 돌아갈 때, 비디오에서 재생을 누르면 오디오가 재생되지만 비디오는 재생되지 않으며 그 이유를 알 수 없습니다. 고맙습니다.
이것을 얻으려면 내 선호하는 솔루션이 아닙니다. 기본적으로 비디오의 현재 시간을 가져 와서 중지하고, 현재 시간을 설정하고, 비디오를 재생하고,보기 컨트롤러가 나타날 때 일시 중지합니다.
그래서 내가 StandardVideoPlayer라는 클래스에 랩 가지고 MPMoviePlayerController 사용 : 여기 내 코드입니다
@implementation StandardVideoPlayer
-(id)initWithParentView:(UIView *)parent andAutoPlay:(BOOL)autoPlay andFullScreen:(BOOL)fullScreen andAnimated:(BOOL)animated
{
// Call superclass's initializer
self = [super init];
if(!self || !parent)
{
return nil;
}
else
{
if (!_moviePlayerController)
{
_moviePlayerController = [[MPMoviePlayerController alloc] init];
}
_moviePlayerController.controlStyle = MPMovieControlStyleDefault;
[_moviePlayerController.view setFrame:parent.frame];
[_moviePlayerController.view setCenter:parent.center];
_moviePlayerController.allowsAirPlay = YES;
_moviePlayerController.shouldAutoplay = autoPlay;
[_moviePlayerController setFullscreen:fullScreen animated:animated];
[parent addSubview: [self videoView]];
}
return self;
}
-(void)loadFromFile: (NSString*) filePath;
{
if (_moviePlayerController)
{
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
[_moviePlayerController setContentURL:fileUrl];
[_moviePlayerController prepareToPlay];
}
}
- (void)loadFromURL: (NSString*) urlString
{
if ([[ConnectionManager sharedInstance] canConnect])
{
if (_moviePlayerController)
{
NSURL *url = [NSURL URLWithString:urlString];
[_moviePlayerController setContentURL:url];
[_moviePlayerController prepareToPlay];
}
}
else
{
[[ConnectionManager sharedInstance] displayConnectionWarningWithText:@"Ok" andDelegate:nil];
}
}
-(void)loadFromHTML:(NSString *)html
{
// NSString *h = [NSString stringWithFormat:html, ]
}
-(void)play
{
if (_moviePlayerController)
{
[_moviePlayerController prepareToPlay];
[_moviePlayerController play];
}
}
-(void)stop
{
if (_moviePlayerController)
{
[_moviePlayerController stop];
}
}
-(void)pause
{
if (_moviePlayerController)
{
[_moviePlayerController pause];
}
}
// use this to get the view form the moviePlayerController......
-(UIView*)videoView
{
UIView *view = nil;
if (_moviePlayerController)
{
view = _moviePlayerController.view;
}
return view;
}
@end
와 다음 뷰 컨트롤러에 내가있다 :
@implementation VideoViewController
// lazy initialiser
- (StandardVideoPlayer*) videoPlayer
{
if (!_videoPlayer)
{
_videoPlayer = [[StandardVideoPlayer alloc] initWithParentView:self.view andAutoPlay:NO andFullScreen:NO andAnimated:YES];
}
return _videoPlayer;
}
- (void) viewDidLoad
{
[super viewDidLoad];
self.initialised = NO;
self.wasPDFScreen = NO;
self.isFullScreen = NO;
[self.spinner stopAnimating];
self.spinner.hidesWhenStopped = YES;
[GlobalStore sharedInstance].videoViewController = self;
}
-(void) willEnterFullScreen
{
self.isFullScreen = YES;
}
-(void)loadStateChanged
{
MPMovieLoadState state = [self.videoPlayer.moviePlayerController loadState];
if (state & MPMovieLoadStatePlayable)
{
[self.spinner stopAnimating];
}
}
-(void) customInit
{
if (!self.initialised)
{
[self.view setBackgroundColor:[UIColor blackColor]];
[self.videoPlayer.videoView setBackgroundColor:[UIColor blackColor]];
// set a border
CGFloat borderWidth = 1.0f;
self.videoPlayer.videoView.frame = CGRectInset(self.videoPlayer.videoView.frame, -borderWidth, -borderWidth);
self.videoPlayer.videoView.layer.borderColor = BORDER_COLOUR;
self.videoPlayer.videoView.layer.borderWidth = borderWidth;
self.view.frame = CGRectInset(self.view.frame, -borderWidth, -borderWidth);
self.view.layer.borderColor = BORDER_COLOUR;
self.view.layer.borderWidth = borderWidth;
// set this to be able to exit the video player properly
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willEnterFullScreen)
name:MPMoviePlayerWillEnterFullscreenNotification
object:_videoPlayer.moviePlayerController];
// set this to be able to start/stop the spinner
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loadStateChanged)
name:MPMoviePlayerLoadStateDidChangeNotification
object:_videoPlayer.moviePlayerController];
// make sure the views are always at the front
[self.view bringSubviewToFront:self.videoPlayer.videoView];
[self.view bringSubviewToFront:self.spinner];
self.initialised = YES;
}
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self customInit];
}
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.spinner stopAnimating];
if (_videoPlayer && self.wasPDFScreen)
{
NSTimeInterval time = [self.videoPlayer.moviePlayerController currentPlaybackTime];
if (time != 0)
{
// So to ge the video to play properly, i have to uncommment the lines below, but this loses the cache and isn't quite as smooth as i would like.
//[self stopVideo];
//self.videoPlayer.moviePlayerController.currentPlaybackTime = time;
//[self.videoPlayer.moviePlayerController prepareToPlay];
//[self.videoPlayer.moviePlayerController play];
//[self.videoPlayer.moviePlayerController pause];
}
}
self.isFullScreen = NO;
self.wasPDFScreen = NO;
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
// only stop the video when we mean to - not when we go into full screen mode
if (!self.isFullScreen && !self.wasPDFScreen)
[self stopVideo];
}
- (void)playVideo
{
[self.spinner startAnimating];
[self.videoPlayer loadFromURL:@"someurl"];
// and play!!
[self.videoPlayer play];
}
-(void)stopVideo
{
[self.videoPlayer stop];
}
@end