Latest 4.3.0
License MIT
Platforms ios 10.3, requires ARC

Swift 5.0
CocoaPods Compatible

A Swift helper to handle music playback using AVFoundation.


  • iOS 10.3+
  • Swift 5.0+


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

Altenatively you can drag the swift file(s) manually 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.
import SwiftyMusic 
  • Anywhere in your project create an extension of FileName 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 SwiftyMusic.FileName {
    static let menu = SwiftyMusic.FileName("MenuMusic")
    static let game = SwiftyMusic.FileName("GameMusic")

    static var all: [SwiftyMusic.FileName] = [.menu, .game]
  • Than setup the helper as soon as your app launches.
SwiftyMusic.shared.setup(withFileNames: SwiftyMusic.FileName.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 reset volume (e.g game resumed)

  • To stop and reset all music players, eg gameover

  • To mute music

    SwiftyMusic.shared.isMuted = true
  • To unmute music

    SwiftyMusic.shared.isMuted = false
  • To check if music is muted, eg when setting up your mute music button
    if SwiftyMusic.shared.isMuted {
    // music is muted, show unmute button
    } else {
    // music not muted, show mute button

Latest podspec

    "name": "SwiftyMusic",
    "version": "4.3.0",
    "license": "MIT",
    "summary": "A swift helper to play music with AVFoundation.",
    "homepage": "",
    "social_media_url": "",
    "authors": {
        "Dominik": "[email protected]"
    "requires_arc": true,
    "platforms": {
        "ios": "10.3"
    "source": {
        "git": "",
        "tag": "4.3.0"
    "source_files": "SwiftyMusic/**/*.{swift}"

Pin It on Pinterest

Share This