我已准备好在我的服务器上播放一些视频文件。这是我试图用来在iOS应用程序中播放它们的代码:
Video *vid = [videos objectAtIndex:index];
NSURL *vidUrl = [NSURL URLWithString:vid.videoUrl];
NSLog(@"%@",vid.videoUrl);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:vidUrl];
player.controlStyle=MPMovieControlStyleEmbedded;
[player.view setFrame:self.view.bounds];
[self.view addSubview:player.view];
[player play];
如果我复制并粘贴NSLog向Safari吐出的URL,则视频播放正常。所以我知道网址很好。但在我的应用程序中,我只是得到一个黑屏。我的代码出了什么问题?
答案 0 :(得分:4)
MPMoviePlayerController
需要是声明为@property (strong, nonatomic) MPMoviePlayerController *mvpc;
然后,只要你想播放一部电影,你就会写:
self.mvpc = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"movieURL"]];
self.mvpc.shouldAutoplay = YES; //Optional
self.mvpc.controlStyle = MPMovieControlStyleEmbedded;
[self.mvpc prepareToPlay];
[self.mvpc.view setFrame:self.view.bounds];
[self.view addSubview:self.mvpc.view];
[self.mvpc play];