您好我已经为ipad创建了应用程序,它在资源文件夹中有一个视频文件,并在用户点击播放按钮时播放。 它适用于第一次用户点击播放按钮,但是当用户播放视频文件的后续时间时。出现的问题是视频不播放只播放音频。这些问题不是随机发生的,而是会发生更多次。
发行时还有一件事(视频没有播放),当我点击播放器右下角的卤素箭头图标时,电影会全屏显示,并显示视频。当时视频正在播放。
任何人都可以帮助我吗?
这是我的示例代码
MPMoviePlayerController *moviePlayer;
} @property(readwrite,retain)MPMoviePlayerController * moviePlayer; @synthesize moviePlayer;
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
[super viewDidLoad];
}
-(IBAction)PlayBtnPressed:(id)sender
{
NSURL *movieURL;
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"title" ofType:@"mp4"];
movieURL = [NSURL fileURLWithPath:moviePath];
// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
// save the movie player object
self.moviePlayer = mp;
[mp release];
UIInterfaceOrientation orientation = [[UIDevice currentDevice]orientation];
[self shouldAutorotateToInterfaceOrientation:orientation];
// Play the movie!
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer play];
}
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(@"movieFinishedCallback aNotification");
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[player.view removeFromSuperview];
}
提前致谢........
答案 0 :(得分:1)
看起来直到你在同一个电影文件中分配第二个电影播放器之后才会发布电影播放器:
self.moviePlayer = mp;
保留它,但电影完成部分没有做到
self.moviePlayer = nil;
可能会导致你出现问题。