【问题标题】:Play a downloaded Video in System bundle在系统包中播放下载的视频
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-10-09
      • 1970-01-01
      • 2019-02-22
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      • 2016-09-28
      相关资源
      最近更新 更多