gpt4 book ai didi

iphone - 播放保存在应用程序文档目录中的视频文件

转载 作者:可可西里 更新时间:2023-11-01 05:01:17 26 4
gpt4 key购买 nike

我有一个视频文件保存在我的应用程序的文档文件夹的本地目录中。当用户单击我创建的嵌入式表格 View 中的项目时,我想播放文件。我的视频播放代码如下:

NSString* documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* path = [documentPath stringByAppendingPathComponent:@"DemoRecording.mp4"];
NSURL* movieURL = [NSURL fileURLWithPath: path];
[player.view setFrame: self.view.bounds];
[self.view addSubView: player.view];
[player play];
MPMoviePlayerViewController* moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL: movieURL];
[self presentMoviePlayerViewControllerAnimated: moviePlayer];

视频无法播放。路径正确并且文件存在于那里。
我知道这是一个重复的问题。我引用了这些链接:
Playing a Downloaded Video from the Documents Directory with Cocoa-Touch
MPMoviePlayer load and play movie saved in app documents
却找不到确切的答案。
请帮我解决这个问题。我使用的是 iOS 5.1.1,如果有任何变化的话。

编辑:

它确实有效。我忘了将 URL 传递给电影播放器​​。

最佳答案

您可以像这样从文档目录播放视频:-

-(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];
}

注意

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

关于iphone - 播放保存在应用程序文档目录中的视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14234822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com