gpt4 book ai didi

ios - 使用 Cocoa-Touch 播放从文档目录下载的视频

转载 作者:可可西里 更新时间:2023-11-01 04:19:13 25 4
gpt4 key购买 nike

我正在尝试让我的应用程序播放已下载到文档目录的视频文件。我知道文件正在下载,但我似乎无法播放该文件,这是我的代码:

-(IBAction)play{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/piggy.m4v"];

NSURL *movieURL = [NSURL fileURLWithPath:path];


_player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[self.view addSubview:_player.view];

_player.controlStyle = MPMovieControlStyleDefault;
_player.shouldAutoplay = YES;


[_player setFullscreen:YES animated:YES];


[_player play];

}

最佳答案

这看起来像是某种错误,但你必须这样设置你的路径:

 NSString *vidPath = [[NSBundle mainBundle] pathForResource:@"promo" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:vidPath isDirectory:NO]; //THIS IS THE KEY TO GET THIS RUN :)
[introPlayer setContentURL:url];

关于ios - 使用 Cocoa-Touch 播放从文档目录下载的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11549143/

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