Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get audio file size without export

i'm developing an app that export audio file stored in the iPod library, but i should verify the file size before export and upload (server has a fixed max upload size):

  • i know that after exporting file, the size will not be the same: is there any method to estimate the new size ?
  • main question : can i know the original file size before export (using MPMediaItem or something else), so i can tell user that this file can't be uploaded (the export can take a while). thanks.
like image 831
Red Mak Avatar asked Nov 24 '22 07:11

Red Mak


1 Answers

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.

like image 78
cjd Avatar answered Jan 06 '23 11:01

cjd