首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >MPMediaItems原始歌曲数据

MPMediaItems原始歌曲数据
EN

Stack Overflow用户
提问于 2009-11-01 09:41:38
回答 1查看 17.6K关注 0票数 17

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

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-10 17:53:47

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

-(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及更高版本

祝好运!

票数 30
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1656124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档