MUSIC PLAYER - PLAY, PAUSE, NEXT, BACK #Swift5 #XCode


 MUSIC PLAYER



Totally functional Music Player With Next Song, Previews Song and play pause button.


As AVAudioPlayer is the functionality in the AVFoundation framework, so import AVFoudation in your ViewController class.


i have created fully functional app which given in this link you can use it as study purpose.


#Swift5 #XCode #AVAudioPlayer #AVFoundation #MusicPlayer 



Click Here For Demo Project... 



  • import UIKit
    import AVFoundation
    class ViewController: UIViewController {
    var audioPlayer = AVAudioPlayer()
    override func viewDidLoad() {
    super.viewDidLoad()
    }
    func soundFiles() {
    let bundle = Bundle.main
    guard let sound = bundle.path(forResource: "song1", ofType: "mp3") else { return }
    do {
    print("sound found\n")
    audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: sound))
    } catch {
    print("sound not found\n")
    }
    }
    @IBAction func playButtonClicked(_ sender: UIButton) {
    soundFiles()
    audioPlayer.play()
    }
    }


  •  

Comments

Popular posts from this blog

Learn Swift Programming in 1 Day

Firebase Demo Code with Swift5