iOS:保存 iTunes 库中可见的音频文件
我正在尝试将 mp3 文件保存到 iTunes 库中可以看到该文件的文件夹中。我在某处读到,如果我将其保存在 NSDocumentDirectory 上,它就会起作用,但我没有尝试这样做。
我还尝试了 NSMusicDirectory 和 NSLibraryDirectory。
这就是我保存它的方式:
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [documentPath objectAtIndex:0];
NSString *savePath = [docDirectory stringByAppendingPathComponent:@"file.mp3"];
[_oneNSDataFile writeToFile:savePath atomically:YES];
感谢您的时间!
I am trying to save a mp3 file into a folder where the file could be visible in iTunes Library. I read somewhere that if I save it on NSDocumentDirectory, it would work, but I had no luck on trying that.
I also tried NSMusicDirectory and NSLibraryDirectory.
this is how I'm saving it:
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [documentPath objectAtIndex:0];
NSString *savePath = [docDirectory stringByAppendingPathComponent:@"file.mp3"];
[_oneNSDataFile writeToFile:savePath atomically:YES];
thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,坏消息:) iOS 中的 iPod Library Access API 不允许第三方应用程序修改用户音乐库的内容。除此之外,将媒体文件添加到库目录中将不起作用,因为库使用(二进制)索引文件来确定库的内容以及媒体资产的位置。
Sorry, bad news :) The iPod Library Access API in iOS doesn't allow third party apps to modify the contents of the user's music library. In addition to that, adding a media file into the library directory won't work, because the library uses a (binary) index file to determine the contents of the library, and the locations of the media assets.
尝试将文件保存到 NSMusicDirectory 。
try saving files to NSMusicDirectory .