Get audio file size without export

I am developing an application that exports an audio file stored in the iPod library, but I have to check the file size before exporting and downloading (the server has a fixed maximum upload size):

  • I know that after exporting the file, the size will not be the same: is there any method for estimating the new size?
  • The main question is: can I find out the original file size before exporting (using MPMediaItem or something else), so I can tell the user that this file cannot be downloaded (exporting can take some time). thanks.
+4
source share
2 answers

, AVAssetExportSession .

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 .

+3

, , :

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

,

-2

All Articles