To create a music player in Swift, follow these steps:
First, add the AVFoundation framework to your project by clicking on your project target, selecting "Build Phases", and then adding "AVFoundation.framework" to "Link Binary With Libraries".
Next, import AVFoundation in your view controller file:
main.swift20 chars2 lines
main.swift51 chars3 lines
main.swift184 chars7 lines
Note: replace "song" and "mp3" with the name and extension of your audio file.
main.swift80 chars4 lines
For a pause button:
main.swift82 chars4 lines
For a stop button:
main.swift113 chars5 lines
That's it! You now have a simple music player in Swift using AVFoundation.
gistlibby LogSnag