Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. queuePlayer = [[AVQueuePlayer alloc] init];
  2. [queuePlayer insertItem: [AVPlayerItem playerItemWithURL:url] afterItem: nil]; // etc.
  3. [queuePlayer play]
  4.  
  5. NSArray* tracks = [NSArray arrayWithObjects:@"http://example.com/song1.mp3", @"http://example.com/song2.mp3", @"http://example.com/song3.mp3", nil];
  6.  
  7. for (NSString* trackName in tracks)
  8. {
  9. AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:[NSURL URLWithString:trackName]
  10. options:nil];
  11.  
  12. AVMutableCompositionTrack* audioTrack = [_composition addMutableTrackWithMediaType:AVMediaTypeAudio
  13. preferredTrackID:kCMPersistentTrackID_Invalid];
  14.  
  15. NSError* error;
  16. [audioTrack insertTimeRange:CMTimeRangeMake([_composition duration], audioAsset.duration)
  17. ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio]objectAtIndex:0]
  18. atTime:kCMTimeZero
  19. error:&error];
  20.  
  21. if (error)
  22. {
  23. NSLog(@"%@", [error localizedDescription]);
  24. }
  25.  
  26. // Store the track IDs as track name -> track ID
  27. [_audioMixTrackIDs setValue:[NSNumber numberWithInteger:audioTrack.trackID]
  28. forKey:trackName];
  29.  
  30. }
  31.  
  32. _player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
  33.  
  34. [_player play];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement