播放系统包中下载的视频
我正在尝试在 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];
}
}
Im trying to download a video/audio on iphone and store in iPhone system bundle, and play the video/audio file from bundle.
I have successfully downloaded the video/audio file using NSURLConnection.
and i have store it as "sample.mov"
but i wasn't able to play the video from bundle. is it because the file was not registered in bundle?!
Here is the code:
write to file when finish downloading
- (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];
}
then i play the video from bundle
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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您无法成功将文件保存到资源包文件夹中。
To my knowledge you cannot successfully save files to resource bundle folder.