gpt4 book ai didi

ios - MPMoviePlayerController 不从 Documents 文件夹播放

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

绝望。大家好!我在使用 MPMoviePlayerController 时遇到了一些问题。我已经让它与来自 NSBundle 的视频一起工作。但这不是我需要的。我需要从 Documents 目录播放它,因为那是我存储录制视频的地方,URL 存储在 CoreData 中。但是让我们把这个放在一边,将代码简化到最低限度。如果使用 contentURL,这段代码实际上是有效的,这会导致 NSBundle。之后,我要做什么才能到达文档位置。我的工作:

    NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"Oct_08_2012_10_00_51" withExtension:@"mp4"]; // this works
NSString* docPath = [NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * docaPathFull = [NSString stringWithFormat:@"%@%@", docPath, @"/Oct_08_2012_10_00_51.mp4"];
NSURL * docUrl= [NSURL URLWithString: docaPathFull];
BOOL ex = [[NSFileManager defaultManager] fileExistsAtPath:docaPathFull];
NSLog(@"file exists: %d, path using docPath: %@",ex, docaPathFull);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:docUrl];
player.shouldAutoplay = YES;
player.controlStyle = MPMovieControlStyleEmbedded;
[player.view setFrame: self.thumbButton.bounds];
[player prepareToPlay];
[self.view addSubview: player.view];
[player play];

我们有什么:

2012-10-08 13:14:43.532 Voto[11968:907] file exists: 1, path using docPath: /var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Documents/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:43.907 Voto[11968:907] content URL: file://localhost/var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Voto.app/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:44.265 Voto[11968:907] doc URL: /var/mobile/Applications/07B8574A-A3BA-4B23-BB3F-995B33A01B95/Documents/Oct_08_2012_10_00_51.mp4
2012-10-08 13:14:45.343 Voto[11968:907] [MPAVController] Autoplay: Disabling autoplay for pause
2012-10-08 13:14:45.344 Voto[11968:907] [MPAVController] Autoplay: Disabling autoplay
2012-10-08 13:14:46.518 Voto[11968:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-10-08 13:14:46.540 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay
2012-10-08 13:14:46.554 Voto[11968:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2012-10-08 13:14:46.555 Voto[11968:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2012-10-08 13:14:46.557 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay
2012-10-08 13:14:46.567 Voto[11968:907] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2012-10-08 13:14:46.871 Voto[11968:907] [MPAVController] Autoplay: Enabling autoplay

所以,文件存在...我看过的问题:

MPMoviePlayer load and play movie saved in app documents

MPMoviePlayerController does not work with movie in documents folder

MPMoviePlayerViewController play movie from Documents directory - objective-c

我还检查了类引用,没有关于从文档播放的具体信息。我的项目设置:使用最新的 iOS 6,部署目标 5.0在 iOS6 iPhone 模拟器和装有 iOS 6 的 iPad 上进行测试。如果我忘了添加什么,请提醒我,我会立即添加。

请帮忙! :)

最佳答案

好吧,您没有以正确的方式构建文件 URL,您应该这样做:

NSString *docPath = [NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *docaPathFull = [docPath stringByAppendingPathComponent:@"/Oct_08_2012_10_00_51.mp4"];
NSURL *docUrl= [NSURL fileURLWithPath:docaPathFull];

您应该使用 NSStringstringByAppendingPathComponent 方法将目录和文件添加到路径;此外,在创建文件 URL 时,在 NSURL 上使用 fileURLWithPath:,这将为给定路径创建正确的 NSURL。

关于ios - MPMoviePlayerController 不从 Documents 文件夹播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12779683/

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