您好我在framworks下面使用,
#import <MediaPlayer/MediaPlayer.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
Run Code Online (Sandbox Code Playgroud)
在其中一个按钮事件中,我已经实现了以下代码来打开库.
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES; // this is the default
[self presentModalViewController:mediaPicker animated:YES];
[mediaPicker release];
Run Code Online (Sandbox Code Playgroud)
并且在MPMediaPickerController的委托方法中实现了如下代码
#pragma mark MPMediaPickerController delegate methods
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
// We need to dismiss the picker
[self dismissModalViewControllerAnimated:YES];
// Assign the selected item(s) to the music player and start playback.
counterIpod = [mediaItemCollection.items count];
totalcollection = counterIpod;
if (totalcollection > 10) {
NSString *str = [NSString …Run Code Online (Sandbox Code Playgroud) 我使用AVAssetExportSession导出ipod库中的mp3/m4a文件.此方法适用于iOS 5.0及更早版本.但是在将iOS升级到5.1之后,此方法不再适用于mp3,但仍适用于m4a.
这是源代码.
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: [mediaItem assetUrl] options:nil];
NSLog (@"compatible presets for songAsset: %@",[AVAssetExportSession exportPresetsCompatibleWithAsset:songAsset]);
AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
initWithAsset: songAsset
presetName: AVAssetExportPresetPassthrough];
NSLog (@"created exporter. supportedFileTypes: %@", exporter.supportedFileTypes);
NSLog(@"output file type=%@",[mediaItem fileType]);
NSLog(@"export file path=%@",exportPath);
exporter.outputFileType =[mediaItem fileType];
NSError *error1;
error1=0;
if([[NSFileManager defaultManager] fileExistsAtPath:exportPath])
{
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:&error1];
if(error1)
NSLog(@"%@",error1);
}
NSURL* exportURL = [NSURL fileURLWithPath:exportPath];
exporter.outputURL = exportURL;
// do the export
[exporter exportAsynchronouslyWithCompletionHandler:^{
int exportStatus = exporter.status;
switch (exportStatus) {
case AVAssetExportSessionStatusFailed: …Run Code Online (Sandbox Code Playgroud)