2

currently i am using following codes to play song

playerItem = [AVPlayerItem playerItemWithURL:[song valueForProperty:MPMediaItemPropertyAssetURL]];
    [_avPlayer replaceCurrentItemWithPlayerItem:playerItem];

here i am using AVPlayer for playing audio files, but my requirement is need to play group (NSArray) of song continuously(currently player stop after playing one song).I heared about AVQueuePlayer but don't know how to use is it with avplayer if anyone know this please help me

rmaddy
  • 314,917
  • 42
  • 532
  • 579
abymathew
  • 115
  • 1
  • 1
  • 11

1 Answers1

5

Look at The following Apple documentation: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVQueuePlayer_Class/Reference/Reference.html

The basics of AVQueuePlayer are not much different than AVPlayer. You can initialize your player with a list of AVPlayerItems, and the continuous playback will be handled for you.

AVPlayerItem *item1 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://www.playeritemurl.com/item1.aac"]];
AVPlayerItem *item2 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://www.playeritemurl.com/item2.aac"]];
AVPlayerItem *item3 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://www.playeritemurl.com/item3.aac"]];
AVQueuePlayer *player = [[AVQueuePlayer alloc] initWithItems:@[item1, item2, item3]];

You can post a more specific question, if you have one, but the documentation should be fairly clear on how to get started.

dzl
  • 908
  • 11
  • 32
  • I've created the queue and added playerItems in it. I called queue.play(), but don't know how to set the frame and unable to see any thing on screen (Play method is called without any error) Guide me please – Fayza Nawaz Nov 17 '15 at 06:34
  • I tried to do it using AVPlayerLayer and added queue in that. then set the frame of that layer and added that as sublayer of my view. but now it doesn't have any player control + the frame of the layer is not set properly. – Fayza Nawaz Nov 17 '15 at 07:05
  • i will try to find the code. i'm afraid, it's been 4 years. i'm not sure if i have that code atm – Fayza Nawaz Jun 18 '19 at 11:17