【发布时间】:2011-12-27 09:17:38
【问题描述】:
我正在尝试从服务器下载 mp4 文件,然后将其保存在文件中。将其保存在文件中后,我尝试播放它。当程序运行时,它会在下载文件时暂停,然后在我创建 MPMoviePlayerController 对象时屏幕变黑。 我做了以下。 1. 跟踪代码并查看 NSDAta 对象以确保正在加载正确的数据量。 2. 添加了 if ( [mFile fileExistsAtPath:filename]==true ) 以确保文件存在。 3. 检查所有返回值是否为零。 我现在被排除在想法之外!
// 设置文件名保存并播放 NSFileManager *mFile= [NSFileManager defaultManager]; NSString *filename=[ NSHomeDirectory() stringByAppendingPathComponent:@"ted10.dat"];
// load video
NSURL *movieUrl=[[NSURL alloc] initWithString:@"http://www.besttechsolutions.biz/projects/golfflix/ted.mp4"];
NSData *data = [NSData dataWithContentsOfURL:movieUrl];
[data writeToURL:movieUrl atomically:YES];
[mFile createFileAtPath:filename contents: data attributes:nil];
// makse sure file exist
if ( [mFile fileExistsAtPath:filename]==true )
{
// play it
NSURL *fileUrl=[ NSURL fileURLWithPath:filename];
mp=[[MPMoviePlayerController alloc] initWithContentURL: fileUrl];
[mp.view setFrame: self.view.bounds];
[self.view addSubview: mp.view];
if ([mp respondsToSelector:@selector(loadState)])
{
// Set movie player layout
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setFullscreen:YES];
// May help to reduce latency
[mp prepareToPlay];
// Register that the load state changed (movie is ready)
}//localhost/Dino/golflix2/Classes/videolist.h
else
{
}
[mp play];
}
【问题讨论】:
标签: iphone