0

I want to be able to make a music player that will keep on playing if the song finishes.

I am trying to make the first view controller show the name of the songs on a table view and if I click one of the cells in the view controller, it will play the music.

And for the second view controller, it will show the basic information about the music being played and also the pause, play, next previous, volume controller etc.

Can somebody help me with how to make my music keep on running if the song being played is finished? I am using UIkit and AVFoundation.

The part where the didSelect is defined in the tableview. thisSong is a variable meaning the current music played.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    do
    {
        let audioPath = Bundle.main.path(forResource: songs[indexPath.row], ofType: ".mp3")
        try audioPlayer = AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath!) as URL)
        audioPlayer.play()
        thisSong = indexPath.row
        audioStuffed = true
        if audioPlayer.isPlaying == false {
            playThis(thisOne: songs[thisSong+1])
            thisSong += 1
        }

    }
    catch
    {
        print(error)
    }
}

0 Answers0