2

I'm working on an app in which I need to stream a large collection of audio files ranging from 5 to 15 seconds each. I would like to reduce the load time between the files as much as possible.

Main Question: Is there a way to start buffering the next file (through HLS) while the current one is playing the last segment?

Is AVQueuePlayer an appropriate solution for this on the iOS side?

A detailed explanation will be much appreciated, since I am new both to HTTP Live Streaming and the AV Foundation.

Related Question: How do radio apps stream their audio with no lag between the songs?

Nelu
  • 16,644
  • 10
  • 80
  • 88

1 Answers1

1

Yes, AVQueuePlayer is an appropriate solution for playing a sequence of audio streamed from the internet via HTTP protocol.

I'm using AVQueuePlayer for quite a while now with excellent results and no lagging between songs. Here is a simple example on how to use AVQueuePlayer:

NSURL *url1 = [NSURL URLWithString:[urlsToPlay objectAtIndex:0]];
NSURL *url2 = [NSURL URLWithString:[urlsToPlay objectAtIndex:1]];
NSURL *url3 = [NSURL URLWithString:[urlsToPlay objectAtIndex:2]];

self.item1 = [[AVPlayerItem alloc] initWithURL:url1];
self.item2 = [[AVPlayerItem alloc] initWithURL:url2];
self.item3 = [[AVPlayerItem alloc] initWithURL:url3];

self.radioPlayerURLs = [[NSArray alloc] initWithObjects:self.item1,self.item2, self.item3, nil];
self.onDemandPlayer  = [AVQueuePlayer queuePlayerWithItems:self.radioPlayerURLs];
[self.onDemandPlayer play];

For more details, please consulte Apple documentation:

AVFoundation

AVQueuePlayer

neowinston
  • 7,584
  • 10
  • 52
  • 83