使用 MPMoviePlayerController 播放视频
play video with MPMoviePlayerController
我试图让视频在我打开视图时单独启动,但只有它的声音有效。视图是空白的。我正在使用 MPMoviePlayerController 来执行此操作。
我的代码是这样的:
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
- (void)viewDidLoad {
[super viewDidLoad];
[self playVideo];
}
-(void)playVideo {
NSString *videoFile = [[NSBundle mainBundle] pathForResource:@"fds" ofType:@"mp4"];
self.moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:videoFile]];
[self.playerView addSubview:self.moviePlayer.view];
self.moviePlayer.fullscreen = YES;
self.moviePlayer.allowsAirPlay = YES;
[self.moviePlayer play];
}
尝试将您的 playVideo 通话移至 viewWillAppear
我试图让视频在我打开视图时单独启动,但只有它的声音有效。视图是空白的。我正在使用 MPMoviePlayerController 来执行此操作。
我的代码是这样的:
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
- (void)viewDidLoad {
[super viewDidLoad];
[self playVideo];
}
-(void)playVideo {
NSString *videoFile = [[NSBundle mainBundle] pathForResource:@"fds" ofType:@"mp4"];
self.moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:videoFile]];
[self.playerView addSubview:self.moviePlayer.view];
self.moviePlayer.fullscreen = YES;
self.moviePlayer.allowsAirPlay = YES;
[self.moviePlayer play];
}
尝试将您的 playVideo 通话移至 viewWillAppear