【发布时间】:2009-09-04 08:16:09
【问题描述】:
我正在尝试在 iPhone 上下载视频/音频并存储在 iPhone 系统捆绑包中,然后播放捆绑包中的视频/音频文件。
我已经使用 NSURLConnection 成功下载了视频/音频文件。 我已将其存储为“sample.mov”
但我无法播放捆绑包中的视频。是不是因为文件没有在bundle中注册?!
代码如下:
下载完成后写入文件
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"sample.mov"];
[VideoData writeToFile:path atomically:YES];
}
然后我播放捆绑包中的视频
MoviePlayerAppDelegate *appDelegate = (MoviePlayerAppDelegate *)[[UIApplication sharedApplication] delegate];
// play the movie
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"a" ofType:@"mov"];
NSURL *movURL = [NSURL fileURLWithPath:moviePath];
[appDelegate initAndPlayMovie:movURL];
-(void)initAndPlayMovie:(NSURL *)movieURL
{
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
// save the movie player object
self.moviePlayer = mp;
[mp release];
// Apply the user specified settings to the movie player object
[self setMoviePlayerUserSettings];
// Play the movie!
[self.moviePlayer play];
}
}
【问题讨论】:
标签: mpmovieplayer