3
我想使用MPMoviePlayerController在UIView內播放視頻。 按下UIButton後,視頻出現並開始播放。 不幸的是,在3-4秒後,視頻變黑,音頻仍在播放。 任何想法? 感謝您的所有時間。幾秒鐘後視頻播放消失
(使用的Xcode 4.2.1)
-(void) playMovieButtonPressed:(UIButton*) button{
NSString* video = @"testmovie.m4v";
NSString *filepath = [[NSBundle mainBundle] pathForResource:[video stringByDeletingPathExtension] ofType:[video pathExtension]];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController* player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
player.movieSourceType = MPMovieSourceTypeFile;
[player.view setFrame:CGRectMake(20, 400, 300, 200)];
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
}
- (void) moviePlaybackComplete:(NSNotification*) notification {
NSLog(@"videoviewcontroller complete: %@", notification);
MPMoviePlayerController *mymoviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:mymoviePlayerController];
}
這聽起來很可笑,你有沒有試過另一個視頻。我的工作代碼幾乎完全相同..我所有的擴展類型都是mp4,但我沒有使用player.movieSourceType – DJPlayer 2012-02-24 14:13:52
Thx進行回覆。好,當然。我測試了其他視頻,其他格式和其他來源類型 - 沒有運氣。我也用一個按鈕在一個新的項目中測試了它 - 完全一樣的問題。你安裝了哪個Xcode版本? – geforce 2012-02-24 15:04:18
同一版本4.2.1 – DJPlayer 2012-02-24 15:27:09