Para cada canción que desea hacer, haga una sola AVPlayer
.
NSURL *url = [NSURL URLWithString:pathToYourFile];
AVPlayer *audioPlayer = [[AVPlayer alloc] initWithURL:url];
[audioPlayer play];
Puede obtener una notificación cuando termina el jugador. Compruebe AVPlayerItemDidPlayToEndTimeNotification
al configurar el reproductor:
audioPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[audioPlayer currentItem]];
esto evitará que el jugador para hacer una pausa al final.
en la notificación:
- (void)playerItemDidReachEnd:(NSNotification *)notification
{
// start your next song here
}
Usted puede comenzar su siguiente canción tan pronto como se obtiene una notificación de que se realiza la canción que se está reproduciendo. Mantenga algún contador que sea persistente entre llamadas de selector. De esta forma, al usar counter % [songs count]
, obtendrá una lista de reproducción de bucles infinitos :)
No olvide anular el registro de la notificación al soltar el reproductor.
Es muy difícil encontrar información sobre esto ... – dot