[英]MPMoviePlayerController scaling mode issues after exit full screen
[英]After exit full screen MPMoviePlayerController set scaling mode to MPMovieScalingModeFill in ios
在我的應用程序中,我使用mpmovieplayercontroller播放視頻
首先將縮放模式設置為MPmovieScalingmodefill並將視頻顯示為scalingmode。
然后在我全屏觀看視頻並退出全屏后,不將縮放模式設置為MPmovieScalingmodeFill並以defualt模式顯示視頻。
低於我的視頻播放代碼
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(ExitFullScreen:)
name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[appDelegate.moviePlayerController setContentURL:fileURL];
if ([appDelegate checkDevice])
{
[appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,463)];
}
else
{
[appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,375)];
}
[appDelegate.moviePlayerController prepareToPlay];
appDelegate.moviePlayerController.scalingMode=MPMovieScalingModeFill;
appDelegate.moviePlayerController.controlStyle=MPMovieControlStyleDefault;
appDelegate.moviePlayerController.shouldAutoplay=NO;
[appDelegate.moviePlayerController setFullscreen:YES animated:YES];
[appDelegate.moviePlayerController play];
[self.view addSubview:appDelegate.moviePlayerController.view];
- (void)ExitFullScreen:(NSNotification *)notification{
NSLog(@"Exit full Screen");
[appDelegate.moviePlayerController setControlStyle:MPMovieControlStyleEmbedded];
[appDelegate.moviePlayerController setScalingMode:MPMovieScalingModeFill];}
所以我的問題是退出全屏后如何設置縮放模式或退出屏幕后不改變縮放模式?
請幫幫我。
謝謝。
我相信這會生成MPMoviePlayerScalingModeDidChangeNotification
。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieScalingModeDidChange:)
name:MPMoviePlayerScalingModeDidChangeNotification
object:nil];
MPMoviePlayerScalingModeDidChangeNotification
在電影播放器的縮放模式發生變化時發布。 沒有userInfo字典。 縮放模式可以通過編程或用戶交互進行更改。 要設置或檢索影片播放器的縮放模式,請訪問其scalingMode屬性。 狀態已更改的電影播放器可用作與通知關聯的對象。
這不是“理想”的解決方案,但它有效! 基本上,一旦你退出全屏幕,MPMoviePlayerController實例全部搞砸了,並且將縮放屬性重置為MPMovieScalingModeFill無論在何時何地你都沒有幫助(我已經嘗試了各種各樣的東西,一小時后放棄了)。 最簡單的解決方案是刪除MPMoviePlayerController並在每次退出全屏時簡單地分配一個新的MPMoviePlayerController實例(不理想,但完全有效):
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:NO];
if (self.moviePlayer != nil)
[self.moviePlayer.view removeFromSuperview];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
self.moviePlayer.view.frame = CGRectMake(#, #, #, #);
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.shouldAutoplay = NO;
[self.moviePlayer setContentURL:self.videoURL];
[self.moviePlayer prepareToPlay];
[self.moviePlayer setScalingMode:MPMovieScalingModeFill];
[self.view addSubview:self.moviePlayer.view];
}
PS:不要忘記打電話給super的viewDidAppear或遭受各種不可預見的混亂(iOS開發中一個非常常見的錯誤)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.