ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - tbaranes/AudioPlayerSwift: AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.
AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps. - tbaranes/AudioPlayerSwift
Visit Site

GitHub - tbaranes/AudioPlayerSwift: AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

GitHub - tbaranes/AudioPlayerSwift: AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

AudioPlayer

Travis Language CocoaPods Carthage compatible Platform

AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

Usage

// Initialize
let audioPlayer = AudioPlayer("sound.mp3")

// Start playing
audioPlayer.play()

// Stop playing with a fade out
audioPlayer.fadeOut()

See the samples project to see advanced usage

Installation

CocoaPods

Add the following to your Podfile:

pod 'AudioPlayerSwift'

Carthage

Add the following to your Cartfile:

github 'tbaranes/AudioPlayerSwift'

Swift Package Manager

AudioPlayer is available on SPM. Just add the following to your Package file:

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/tbaranes/AudioPlayerSwift.git", majorVersion: 1)
    ]
)

Manual Installation

Just drag the Source/*.swift files into your project.

AudioPlayer properties

name

The name of the sound. This is either the name that was passed to the init, or the last path component of the audio file.

url

The absolute URL of the audio file.

completionHandler

A callback closure that will be called when the audio finishes playing, or is stopped.

isPlaying

Is it playing or not?

duration

The duration of the sound.

currentTime

The current time offset into the sound of the current playback position.

volume

The volume for the sound. The nominal range is from 0.0 to 1.0.

numberOfLoops

Number of times that the sound will return to the beginning upon reaching the end.

  • A value of zero means to play the sound just once.

  • A value of one will result in playing the sound twice, and so on..

  • Any negative number will loop indefinitely until stopped.

pan

The left/right stereo pan of the file. -1.0 is left, 0.0 is center, 1.0 is right.

AudioPlayer methods

init(fileName: String) throws
init(contentsOfPath path: String) throws
init(contentsOf url: URL) throws

These methods create a new AudioPlayer instance from a file name or file path.

func play()

Plays the sound. Has no effect if the sound is already playing.

func stop()

Stops the sound. Has no effect if the sound is not already playing.

func fadeTo(volume: Float, duration: TimeInterval = 1.0)

This method fades a sound from it's current volume to the specified volume over the specified time period.

func fadeIn(duration: TimeInterval = 1.0)

Fades the sound volume from 0.0 to 1.0 over the specified duration.

func fadeOut(duration: TimeInterval = 1.0)

Fades the sound from it's current volume to 0.0 over the specified duration.

Notifications

SoundDidFinishPlayingNotification

This notification is fired (via NSNotificationCenter) whenever a sound finishes playing, either due to it ending naturally, or because the stop method was called. The notification object is an instance of the AudioPlayer class. You can access the AudioPlayer class's name property to find out which sound has finished.

What's next

  • AudioPlayerManager
  • Your features!

Contribution

  • If you found a bug, open an issue
  • If you have a feature request, open an issue
  • If you want to contribute, submit a pull request

Licence

AudioPlayerSwift is available under the MIT license. See the LICENSE file for more info.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory