Swiftpack.co - Package - crashoverride777/swifty-music


Swift 5.0 Platform CocoaPods Compatible

A Swift helper to handle music playback using AVFoundation.


  • iOS 10.3+
  • Swift 5.0+


Cocoa Pods

CocoaPods is a dependency manager for Cocoa projects. Simply install the pod by adding the following line to your pod file

pod 'SwiftyMusic'

There is now an app which makes handling pods much easier

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

To add a swift package to your project simple open your project in xCode and click File > Swift Packages > Add Package Dependency. Than enter https://github.com/crashoverride777/swifty-music as the repository URL and finish the setup wizard.

Alternatively if you have a Framwork that requires adding SwiftyMusic as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
.package(url: "https://github.com/crashoverride777/swifty-music.git", from: "4.4.0")


Altenatively you can drag the SwiftyMusic.swift file into your project.


  • Add your music tracks to your project.

SwiftyMusic supports the following file formats: mp3, wav, aac, ac3, m4a, caf

  • Add the import statements to your .swift file(s) if you installed via cocoa pods or swift package manager.
import SwiftyMusic 
  • Anywhere in your project create an extension of SwiftyMusicFileName to add the file names of the music tracks that you will use. These must be the same as the actual filename of the music file.
extension SwiftyMusicFileName {
    static let menu = SwiftyMusicFileName("MenuMusic")
    static let game = SwiftyMusicFileName("GameMusic")
    static var all: [SwiftyMusicFileName] = [.menu, .game]
  • Than setup the helper as soon as your app launches.
SwiftyMusic.shared.setup(withFileNames: SwiftyMusicFileName.all)
  • To play music call the play method with the corresponding Music URL you created above. This will automatically pause (not stop and reset) any previously playing music
  • To pause music manually, eg game paused, advertising etc
  • To resume paused music
  • To adjust volume (e.g game paused)
SwiftyMusic.shared.setVolume(to: 0.5)
  • To stop and reset all music players, eg gameover
  • Mute

if SwiftyMusic.shared.isMuted {
    // music is muted, show unmute button
} else {
    // music not muted, show mute button


Stars: 7


Used By

Total: 0


Deployment target - 2020-04-03 17:47:46

  • Update min deployment target to iOS 11.4
  • Add tvOS support to swift package

Cleanup - 2020-02-23 14:24:48

Project cleanup

Swift Package Manager - 2020-02-08 14:39:12

Add swift package manager support

Bugfixes - 2019-09-13 21:39:25

Bugfixes - 2019-09-13 21:11:05

Swift 5 - 2019-03-27 18:59:48

  • Updated to Swift 5
  • Set min deployment target to iOS 10.3

SwiftyMusic - 2018-09-16 14:01:00

  • Updated to Swift 4.2

SwiftyMusic - 2018-03-05 21:42:24


SwiftyMusic - 2018-03-04 12:17:27

Made FileName equatable


SwiftyMusic - 2018-03-03 15:24:46


SwiftyMusic - 2017-09-24 14:30:53

Swift 4 update

SwiftyMusic - 2017-05-08 17:34:53

Fixed mute bug

SwiftyMusic - 2017-05-05 12:54:04

Print statements will now only print in DEBUG mode


SwiftyMusic - 2017-05-01 11:08:35


SwiftyMusic - 2017-04-12 11:17:30

Nested enumerations to closer follow Swift API design guidelines.

SwiftyMusic - 2017-03-08 20:27:06

Added ability to adjust volume

SwiftyMusic - 2017-02-23 20:50:53


SwiftMusic - 2017-02-18 12:28:43

Updated play method to only play when not paused.

SwiftyMusic - 2017-02-12 23:24:24

Play method will not fire if its calling the same file thats already playing


SwiftyMusic - 2017-02-01 22:45:32


SwiftyMusic - 2016-12-02 17:05:33


SwiftyMusic - 2016-10-03 17:49:28

Project has been renamed to SwiftyMusic.

No more source breaking changes after this update. All future changes will be handled with deprecated messages.

Swift-MusicManager - 2016-10-01 11:19:14

Added support for the following file formats: aac, ac3, m4a, caf

Swift-MusicManager - 2016-09-25 14:17:43

Cleanup and documentation fixes

Stop method is now called


Swift-MusicManager - 2016-09-14 11:20:49

Revert project back into a singleton class to make the API easier to use and understand.

Documentation and other improvements.

Swift-MusicManager - 2016-09-08 03:31:38

Updated to Swift 3

Swift-MusicManager - 2016-07-27 20:39:13

Small changes to the set up method.

Swift-Music-Helper - 2016-07-19 13:14:01

Redesign using protocol extension. Please read the instructions

Swift-Music-Helper - 2016-07-10 13:32:33

Clean-up and improvements

Swift-Music-Helper - 2016-05-10 17:03:14

Clean-up and improvements