這次為了處理有些影片無法播放
卻看不到player造成無法回到上一頁問題
之前因為使用MPMoviePlayerLoadStateDidChangeNotification來處理預載完畢後才加上player.view造成上面的情況
所以就改成先呈現player.View
但是必須要使用 MPMoviePlayerViewController
因為 MPMoviePlayerController 在還沒可以播放前會是一片黑色
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
player=playerViewController.moviePlayer;
//旋轉90度
// player.view.transform = CGAffineTransformMakeRotation(1.5707964);
//設定影片比例的縮放、重複、控制列等參數
player.fullscreen=YES;
player.scalingMode = MPMovieScalingModeAspectFit;
player.repeatMode = MPMovieRepeatModeNone;
player.controlStyle =MPMovieControlStyleFullscreen;
//使用Observer製作完成播放時要執行的動作
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
//自動縮放符合畫面比例
// player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
//將影片加至主畫面上
//因為要橫轉所以高和寬對調
[player.view setFrame:CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width)];
// NSLog(@"%f,%f",self.view.bounds.size.height,self.view.bounds.size.width);
[self.view addSubview:player.view];
[player play];
沒有留言:
張貼留言