我是iOS新手,我选择音频文件,如mp3,mp4等。
与UIImagePickerControlle
r相同,下面给出的代码工作正常,但它只获得视频文件而不是音频文件我只选择音频文件:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePickerController.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:imagePickerController animated:YES completion:nil];
当我替换
imagePickerController.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeAudio, nil];
带有kUTTypeMovie
应用程序的 kUTTypeAudio
将崩溃...
提前致谢..
答案 0 :(得分:1)
您无法使用Audio
r获取UIImagePickerControlle
个文件,而应使用MPMediaPickerController
MPMediaPickerController *pickerController = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
pickerController.prompt = @"Select Song";
pickerController.delegate = self;
[self presentViewController:pickerController animated:YES completion:nil];
选择后,您将在MpMediaPicker委托方法中收到回电:
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
MPMediaItem *theChosenSong = [[mediaItemCollection items]objectAtIndex:0];
NSString *songTitle = [theChosenSong valueForProperty:MPMediaItemPropertyTitle];
NSURL *assetURL = [theChosenSong valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
}
答案 1 :(得分:-1)
无法从库中添加或获取mp3文件。您只能从照片库中获取图像和视频。 kUTTypeMovie
是包含视频和音频的媒体格式的抽象类型标识符。 1}}不受支持。