priore

Get duration of streaming

Nov 23rd, 2015
610
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // #import <AVFoundation/AVFoundation.h>
  2. NSTimeInterval duration = 0;
  3. NSURL url = [NSURL URLWithString:@"http://your-streaming-media-url";
  4. dispatch_queue_t queue = dispatch_queue_create("streaming.duration", NULL);
  5. dispatch_async(queue, ^{
  6.     AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:@{AVURLAssetPreferPreciseDurationAndTimingKey : @(YES)}];
  7.     if (asset) duration = CMTimeGetSeconds(asset.duration);
  8. });
RAW Paste Data