Get audio file size without export

醉酒当歌 提交于 2019-12-04 06:59:23

I have not tested but AVAssetExportSession can help you with this.

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.estimatedOutputFileLength will give you size in bytes.

I'm not sure, but i think you could use:

MPMediaItem *item = [[collection items] objectAtIndex:0];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
NSData *data = [NSData dataWithContentsOfURL:url];
NSLog(@"length %d",[data length]);

Regards,

Mariano

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!