你好!我正在編寫一個iPad應用程序,當UIView加載時我需要能夠播放視頻。然而,如果我在初始化它的任何地方嘗試向我的MPMoviePlayerController發送消息,我正在獲得BAD_EXC_ACCESS。我從我的* .h文件中刪除了MPMediaPlayerController,然後完全在實現文件中聲明瞭它,現在我在代碼下方的底部得到消息。在構建和分析內存泄漏(或任何問題)方面,沒有任何問題,並且我找不到任何關於此的帖子。這裏是我的代碼:當UIView加載時立即播放視頻
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
NSString *url = [[NSBundle mainBundle] pathForResource:@"p0600c0100cmpintro" ofType:@"m4v"];
MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
NSLog(@"%@", movie);
movie.view.frame = CGRectMake(5, 0, 1035, 768);
movie.view.contentMode = UIViewContentModeScaleToFill;
[[movie view] setCenter:CGPointMake(movie.view.center.x-10, movie.view.center.y)];
[movie setControlStyle:MPMovieControlStyleNone];
[movie setShouldAutoplay:YES];
[[self view] addSubview:[movie view]];
return self;
}
的 「電影」 的NSLog賦予 「的MPMoviePlayerController:0x1b77f0」,但隨後在碰撞時的錯誤消息是 「* - [的MPMoviePlayerController playbackState]:消息發送到釋放實例0x1473a0」。幫幫我?
不行。我仍然收到錯誤消息「發送到解除分配的實例
」。但現在我得到一個不錯的空白頁面,而不是應用程序崩潰。這是因爲我將代碼移到了viewDidLoad方法中。 – Jacob 2010-12-20 22:40:46