Playing a video file saved in the app's documents directory

前端 未结 2 1444
悲&欢浪女
悲&欢浪女 2021-01-06 09:06

I have a video file saved in my app\'s local directory in the documents folder. I want to playback the file when the user clicks on the item in an embedded table view I crea

相关标签:
2条回答
  • 2021-01-06 09:23

    you can play Video from Document Directory like this way:-

    -(IBAction)playVideo
    {
        NSURL *vedioURL;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
    
        NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:nil];
        NSLog(@"files array %@", filePathsArray);        
    
        NSString *fullpath;
    
        for ( NSString *apath in filePathsArray )
        {
            fullpath = [documentsDirectory stringByAppendingPathComponent:apath];       
            vedioURL =[NSURL fileURLWithPath:fullpath];
        }
        NSLog(@"vurl %@",vedioURL);
        MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:vedioURL];
        [self presentMoviePlayerViewControllerAnimated:videoPlayerView];
        [videoPlayerView.moviePlayer play];     
    }
    

    NOTE

    Please note that don't Forget to include requested Framework or connect Delegate

    0 讨论(0)
  • 2021-01-06 09:39

    The mistake in you was you missed / before DemoRecording.mp4

    It should be

    NSString* path = [documentPath stringByAppendingPathComponent:@"/DemoRecording.mp4"];
    

    Also you are writing player statements before declaring it.

    0 讨论(0)
提交回复
热议问题