在系统包中播放下载的视频

时间:2009-09-04 08:16:09

标签: mpmovieplayer

我试图在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];
    }
}

1 个答案:

答案 0 :(得分:1)

据我所知,您无法将文件成功保存到资源包文件夹。