当我在我的应用程序中使用MPMoviePlayerController时,它不播放视频,只显示黑色矩形。
我的代码如下:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = nil;
//filePath =[NSString stringWithFormat:@"%@/%@.mp4", documentsDirectory, fileName];
filePath=[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",fileName]];
NSLog(@"%@",filePath);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
if (fileExists){
NSLog(@"exist!");
}else{
NSLog(@"no exist!");
}
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:filePath]];
[moviePlayer.view setFrame:self.view.frame];
[self.view addSubview:moviePlayer.view];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.movieSourceType= MPMovieSourceTypeStreaming;
moviePlayer.fullscreen = YES;
[moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playMovie:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];
-(void)playMovie:(NSNotification *)notification {
MPMoviePlayerController *player = notification.object;
if (player.loadState & MPMovieLoadStatePlayable)
{
NSLog(@"Movie is Ready to Play");
[player play];
}
}
输出结果为:
iBeaconCollection[10320:60b] /var/mobile/Applications/107F6DE4-AE31-40E0-BAA0- 76A956B72116/Documents/101A ~ Hallway to 101-103.mp4
2014-06-11 14:13:27.302 iBeaconCollection[10320:60b] exist!
希望有人能帮助我!感谢。
答案 0 :(得分:0)
使用MPMoviePlayerViewController,然后尝试确保该文件实际上是MP4,因为您要附加该扩展名。