问题描述
我想将mp3从手机上传到服务器,为此我使用 MPMediaPickerController
。
I want to upload mp3 from my phone to server, for this i am using MPMediaPickerController
.
获取 MPMediaItem
的网址后,我想获取此网址的NSData,但我在NSData中获取null 。
After getting URL of MPMediaItem
, i want to get NSData of this url , but i am getting null in NSData.
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissViewControllerAnimated:YES completion:nil];
MPMediaItem *item=[[mediaItemCollection items] objectAtIndex:0];
NSURL *url = [item valueForProperty: MPMediaItemPropertyAssetURL];
NSString *path = [NSString stringWithFormat:@"%@",url];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
}
我也试过
NSData *data = [NSData dataWithContentsOfURL:url];
但数据为空,为什么?
我也试过但没有得到结果。
I also tried NOt able to convert from MPMediaItem(mp3 song) to NSData But not getting result.
任何人都可以指导我获取mp3的NSData。
Can any one guide me to get NSData of mp3.
提前致谢。
推荐答案
看看这个库:它可以将非DRM项目从iPod音乐库转换为mp3文件,然后您可以将它们保存或用作NSData进一步处理。
Take a look at this library: https://github.com/tapsquare/TSLibraryImport It can convert non-DRM items from iPod music library to mp3 files and then you can save them or use as NSData for further processing.
这篇关于如何使用MPMediaPickerController获取mp3的NSData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!