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 linesNote: replace "song" and "mp3" with the name and extension of your audio file.
main.swift80 chars4 linesFor a pause button:
main.swift82 chars4 linesFor a stop button:
main.swift113 chars5 linesThat's it! You now have a simple music player in Swift using AVFoundation.
gistlibby LogSnag