我正在我的应用中播放m4v视频。它播放正常但我只是想加载视频而不播放它。只是预览。
我正在使用以下代码。
-(void)test
{
self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:@"YOUR_PATH"]];
//[self.player prepareToPlay];
[self.player setControlStyle:MPMovieControlStyleDefault];
[self.player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: self.player.view];
}
但如果我取消注释[self.player prepareToPlay];
,它就会开始播放。
如果我评论[self.player prepareToPlay];
,则视频未加载。
答案 0 :(得分:2)
试试这个
-(void)test
{
self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:@"YOUR_PATH"]];
[self.player prepareToPlay];
[self.player play];
[self performSelector:@selector(pausePlayer) withObject:nil afterDelay:0.1];
[self.player setControlStyle:MPMovieControlStyleDefault];
[self.player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: self.player.view];
}
-(void)pausePlayer
{
if (self.player)
{
[self.player pause];
}
}