在的iOS4的iPhone 4/3GS,我有一個tableview中和細胞的一個播放電影文件。如果電影完成播放並且控件已經消失,則視圖會在狀態欄下返回。就像在這張圖片中那樣...我太新了,無法發佈。看到這裏...MPMoviePlayerViewController問題結束
http://www.dezignwright.com/ios4_movie.png
如果控件當電影結束,然後是沒有問題的。
獎金:如何強制電影播放到景觀開始播放時。我不希望它在肖像中播放。
謝謝。
在的iOS4的iPhone 4/3GS,我有一個tableview中和細胞的一個播放電影文件。如果電影完成播放並且控件已經消失,則視圖會在狀態欄下返回。就像在這張圖片中那樣...我太新了,無法發佈。看到這裏...MPMoviePlayerViewController問題結束
http://www.dezignwright.com/ios4_movie.png
如果控件當電影結束,然後是沒有問題的。
獎金:如何強制電影播放到景觀開始播放時。我不希望它在肖像中播放。
謝謝。
這似乎是一個錯誤在4.0,使用「完成」按鈕退出時它工作正常。
我使用的解決方法是手動存儲幀然後接收MPMoviePlayerPlaybackDidFinishNotification
時恢復它。
終於得到它在橫向模式下,用在這裏你覆蓋的MPMoviePlayerViewController
子類shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
即是這樣的:
@interface CustomMoviePlayerViewController : MPMoviePlayerViewController
@end
@implementation CustomMoviePlayerViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
@end
而在你的控制器來解決的bug:
- (void)playbackEnded:(NSNotification *)notification
{
[[self view] setFrame:[self originalFrame]];
}
- (void)playMovie:(NSString *)movieURLString
{
MPMoviePlayerViewController *controller = [[CustomMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movieURLString]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackEnded:) name:MPMoviePlayerPlaybackDidFinishNotification object:[controller moviePlayer]];
[self presentMoviePlayerViewControllerAnimated:controller];
}
我工作圍繞這一問題的明確聲明,我不只是之前我原來的視圖中使用全屏佈局我開始在電影播放:
-(IBAction)playMovieButtonPressed:(id)sender {
MPMoviePlayerViewController* playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[self localMovieURL]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerViewController.moviePlayer];
[self setWantsFullScreenLayout:NO];
// this ensures that the original frame is restored correctly
// if the movie ends and the player is closed automatically
[self presentMoviePlayerViewControllerAnimated:playerViewController];
[playerViewController release];
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}
這不適用於複雜的視圖層次結構。檢查出來 - http://stackoverflow.com/questions/3310909/mpmovieplayerviewcontroller-issue-after-movie-finishes/5738038#5738038 – Sid 2011-04-21 00:07:06
我有同樣的問題,我用這個workaroud解決這個問題:
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
CGRect frame = CGRectMake(0, 20, 768, 1004);
self.view.frame = frame;
}else {
CGRect frame = CGRectMake(0, 20, 1004, 768);
self.view.frame = frame;
}
}
調整矩形的屏幕尺寸,我的代碼應該作品爲iPad。
@Nuoji接近正確的答案。當關閉MPMoviePlayerViewController時,iOS中的視圖框架正在進行動畫處理。由於iOS中的一個錯誤,當播放自動結束時(電影結束時),動畫會假定有問題的視圖在不可能的情況下佔用全屏幕。
步驟1.保存包含將啓動MPMoviePlayerViewController視圖的上海華的框架上。
步驟2.將偵聽器playbackDidFinishNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
步驟3.在通知處理程序重置幀回原始但在延遲之後,允許動畫完成。如果在動畫期間修改了框架,則不起作用。
[self performSelector:@selector(resetFrame)
withObject:nil
afterDelay:kResetFrameDelay];
- (void)resetFrame {
self.view.frame = kApplicationFrame;
}
此問題已被解決,不再是iOS 4.3以上的問題。
感謝您的每一個輸入。
謝謝!我會試一試。 – 2010-07-28 19:02:21
它適合你嗎? – Nuoji 2010-09-01 15:25:18
如果您仍有問題,請查看我的解決方案 – Sid 2011-04-21 00:06:26