Swiftpack.co - Package - crashoverride777/swifty-music

SwiftyMusic

Swift 5.0 Platform CocoaPods Compatible

A Swift helper to handle music playback using AVFoundation.

Requirements

  • iOS 10.3+
  • Swift 5.0+

Installation

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")
]

Manually

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

Usage

  • 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 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
SwiftyMusic.shared.play(.menu)
SwiftyMusic.shared.play(.game)
  • To pause music manually, eg game paused, advertising etc
SwiftyMusic.shared.pause()
  • To resume paused music
SwiftyMusic.shared.resume()
  • To adjust volume (e.g game paused)
SwiftyMusic.shared.setVolume(to: 0.5)
  • To reset volume (e.g game resumed)
SwiftyMusic.shared.resetVolume()
  • To stop and reset all music players, eg gameover
SwiftyMusic.shared.stopAndResetAll()
  • 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
}

Github

link
Stars: 5

Dependencies

Used By

Total: 0

Releases

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

Cleanup

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

Made FileName equatable

Cleanup

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

Cleanup

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

Cleanup

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

Cleanup

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

Cleanup

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

Cleanup

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

Cleanup

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

Cleanup

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

Music.shared.stopAndResetAll()

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

Swift-Music-Helper - 2016-05-06 20:27:56

Small improvements

Swift-Music-Helper - 2016-04-19 19:27:44

Clean-up