Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created April 21, 2021 07:01
Show Gist options
  • Save KrauserHuang/feb6d4b7d9a46f7d397715965a3f04c4 to your computer and use it in GitHub Desktop.
Save KrauserHuang/feb6d4b7d9a46f7d397715965a3f04c4 to your computer and use it in GitHub Desktop.
func repeatStateCheck() {
switch repeatType {
case .none:
playingIndex = songs.firstIndex(of: songPlayed!)
playingIndex += 1
if playingIndex == songs.count {
player.pause()
playNPause.setImage(UIImage(systemName: SystemName.playFill), for: .normal)
} else {
songPlayed = songs[playingIndex]
configurePlayer(song: songPlayed!)
playerItem = AVPlayerItem(url: songURL)
playerLooper = AVPlayerLooper(player: player, templateItem: playerItem!)
player.play()
}
case .whole:
playingIndex = songs.firstIndex(of: songPlayed!)
playingIndex += 1
if playingIndex == songs.count {
playingIndex = 0
}
songPlayed = songs[playingIndex]
configurePlayer(song: songPlayed!)
playerItem = AVPlayerItem(url: songURL)
playerLooper = AVPlayerLooper(player: player, templateItem: playerItem!)
player.play()
case .one:
playerItem = AVPlayerItem(url: songURL)
playerLooper = AVPlayerLooper(player: player, templateItem: playerItem!)
player.play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment