这是我的代码。我想播放一个存在于设备内存中的视频。视频格式为.mov。但我只有黑屏。
NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *tileDirectory = [documentdir stringByAppendingPathComponent:urlpath];
self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:tileDirectory]];
[self.videoPlayer.view setFrame:CGRectMake(0, 0, 320, 420)];
[self.videoPlayer prepareToPlay];
[self.view addSubview:self.videoPlayer.view];
[self.videoPlayer play];
答案 0 :(得分:0)
我得到了我的输出。我引用此链接:How to play video stream with MPMoviePlayerController in iOS来解决我的问题。
我修改后的代码..
self.videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:urlpath]];
self.videoPlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self.videoPlayer.view setFrame:CGRectMake(0, 0, 320, 420)];
[self.view addSubview: self.videoPlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self.videoPlayer.backgroundView setBackgroundColor:[UIColor blackColor]];
[self.videoPlayer play];
此行是关键.. self.videoPlayer.movieSourceType = MPMovieSourceTypeStreaming;