我想知道如何访问MPMediaItem的原始数据。

有任何想法吗?

最佳答案

您可以通过以下方式获取媒体项目的数据:

-(void)mediaItemToData
{
    // Implement in your project the media item picker

    MPMediaItem *curItem = musicPlayer.nowPlayingItem;

    NSURL *url = [curItem valueForProperty: MPMediaItemPropertyAssetURL];

    AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil];

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset
                                       presetName: AVAssetExportPresetPassthrough];

    exporter.outputFileType = @"public.mpeg-4";

    NSString *exportFile = [[self myDocumentsDirectory] stringByAppendingPathComponent:
                                                               @"exported.mp4"];

    NSURL *exportURL = [[NSURL fileURLWithPath:exportFile] retain];
    exporter.outputURL = exportURL;

    // do the export
    // (completion handler block omitted)
    [exporter exportAsynchronouslyWithCompletionHandler:
    ^{
    NSData *data = [NSData dataWithContentsOfFile: [[self myDocumentsDirectory]
                                     stringByAppendingPathComponent: @"exported.mp4"]];

    // Do with data something

    }];
}


此代码仅适用于ios 4.0和更高版本

祝好运!

关于iphone - MPMediaItems原始歌曲数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1656124/

10-13 03:49