1

私のアプリケーションでは、私のビデオをドキュメント ディレクトリに保存し、名前を付け'video2.MOV'て再生したいと考えています。

ここでの問題は、ドキュメント ディレクトリからこのビデオ(名前は'video2.MOV')を取得できないことです。

私のコード:

-(void)playVideo:(NSTimer *)theTimer
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"video2.MOV"];
    NSLog(@"filePath - %@",filePath);

    NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
    NSLog(@"contentPath - %@",content);

    MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:content]];
    [[CCDirector sharedDirector] presentMoviePlayerViewControllerAnimated:videoPlayerView];
    [videoPlayerView.moviePlayer play];
}

contentPathコンソールでは、取得するたびにNULLが表示されるため、ビデオを再生できない可能性があります。

ここで、私の間違いは何ですか。この問題に関する提案をお願いします。

4

2 に答える 2

1

これを試して:

- (NSString*)GetDocumentFilePath:(NSString*)filename
{
    NSLog(@"%@",filename);
    // NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    NSString *documentsDirectory = [paths objectAtIndex:0]; //2
    NSString* file = [[NSString alloc]initWithFormat:@"%@",filename];
    NSString* path = [documentsDirectory stringByAppendingPathComponent:file];
    NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath: path]) //4
    {
        //NSString *bundle = [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"]; //5

        //[fileManager copyItemAtPath:bundle toPath:path error:&error]; //6
    }  

    return path;
}

次のようにファイルパスを取得します。

 NSURL *URL = [NSURL fileURLWithPath:[self GetDoucmentPath:path]];


MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:pptURL];
    theMovie.scalingMode=MPMovieScalingModeAspectFill;

    theMovie.view.frame = CGRectMake(60, 20, 700, 500);
    theMovie.view.center = self.view.center;

    //[self.view addSubview:theMovie.view];

    // Register for the playback finished notification. 

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(onStop) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:theMovie];

    // Movie playback is asynchronous, so this method returns immediately. 

    [self.view addSubview:theMovie.view];
    [theMovie play];

それが役に立てば幸い!!

于 2013-08-01T05:27:16.297 に答える
0

contentuse insteadを使用filePathしてムービー ファイルにアクセスする代わりに、次のようにします。

 MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
于 2013-08-01T05:28:55.117 に答える