gpt4 book ai didi

iOS ,NSDocumentDirectory 获取 nsurl 或路径文件

转载 作者:可可西里 更新时间:2023-11-01 06:25:00 24 4
gpt4 key购买 nike

我有保存 mp3 文件的代码

NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [documentPath objectAtIndex:0];

NSString *fileName = [[NSString alloc] initWithFormat:@"%@%@.mp3", dateString ,timeString ];


NSURL* fileURL = [NSURL URLWithString:myString];
NSError* error = nil;
NSData* data = [NSData dataWithContentsOfURL:fileURL options:0 error:&error];

NSString *savePath = [docDirectory stringByAppendingPathComponent:fileName];

[data writeToFile:savePath atomically:YES];

现在我想通过 MPMoviePlayerController 读取这个文件

如何获取路径或nsurl文件

--- 与此相同的代码

 NSURL * urlv = [[NSURL alloc] initWithString:myString];
avPlayer = [[MPMoviePlayerController alloc] initWithContentURL:urlv];
[avPlayer prepareToPlay];
[avPlayer play];

请帮助搜索 mystrig 或 nsurl 源

最佳答案

NSString *filename = @"whatever you've saved your filename as";
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [pathArray objectAtIndex:0];
NSString *yourSoundPath = [documentsDirectory stringByAppendingPathComponent:filename];

if ([[NSFileManager defaultManager] fileExistsAtPath:soundPath])
{
NSURL *soundURL = [NSURL fileURLWithPath:soundPath isDirectory:NO];
}

//Then just init your player with the contents of that URL

关于iOS ,NSDocumentDirectory 获取 nsurl 或路径文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16089957/

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