システムバンドルでダウンロードしたビデオを再生する

StackOverflow https://stackoverflow.com/questions/1377892

  •  21-09-2019
  •  | 
  •  

質問

iPhoneにビデオ/オーディオをダウンロードしてiPhoneシステムバンドルに保存し、バンドルからビデオ/オーディオファイルを再生しようとしています。

NSURLConnectionを使用してビデオ/オーディオファイルを正常にダウンロードしました。そして私はそれを「sample.mov」として保存しました

しかし、バンドルからビデオを再生できませんでした。ファイルがバンドルに登録されていないからでしょうか?

コードは次のとおりです。

ダウンロード終了時にファイルに書き込む

- (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];
    }
}
役に立ちましたか?

解決

私の知る限りでは、あなたが成功したファイルの保存バンドルフォルダをリソースへのすることはできません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top