All Projects → dimitris-c → AudioStreaming

dimitris-c / AudioStreaming

Licence: MIT License
An AudioPlayer/Streaming library for iOS written in Swift using AVAudioEngine.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to AudioStreaming

Eqmac
macOS System-wide Audio Equalizer & Volume Mixer 🎧
Stars: ✭ 3,947 (+6589.83%)
Mutual labels:  coreaudio, avaudioengine
Musikcube
a cross-platform, terminal-based music player, audio engine, metadata indexer, and server in c++
Stars: ✭ 2,663 (+4413.56%)
Mutual labels:  audio-player, coreaudio
Snapcast
Synchronous multiroom audio player
Stars: ✭ 4,028 (+6727.12%)
Mutual labels:  audio-player, audio-streaming
shairport-sync
AirPlay audio player. Shairport Sync adds multi-room capability with Audio Synchronisation
Stars: ✭ 5,532 (+9276.27%)
Mutual labels:  audio-player, audio-streaming
Nymphcast
Audio and video casting system with support for custom applications.
Stars: ✭ 2,010 (+3306.78%)
Mutual labels:  audio-player, audio-streaming
amplyfm
A free and open-source web app for streaming music.
Stars: ✭ 46 (-22.03%)
Mutual labels:  audio-player, audio-streaming
SETabView
SETabView is a TabBar with simple yet beautiful animations that makes your apps look cool!
Stars: ✭ 53 (-10.17%)
Mutual labels:  swift-package-manager
catbird
Mock server for UI tests
Stars: ✭ 32 (-45.76%)
Mutual labels:  swift-package-manager
audio manager
A flutter plugin for music playback, including notification handling.
Stars: ✭ 94 (+59.32%)
Mutual labels:  audio-player
mini-swift
Minimal Flux architecture written in Swift.
Stars: ✭ 40 (-32.2%)
Mutual labels:  swift-package-manager
concurrency-kit
🚄 Concurrency abstractions framework for Apple Platforms [Task, Atomic, Lock, Operation, etc.].
Stars: ✭ 17 (-71.19%)
Mutual labels:  swift-package-manager
mpz
Music player for big local collections
Stars: ✭ 50 (-15.25%)
Mutual labels:  audio-player
react-aplayer
🍭 A React wrapper component of APlayer
Stars: ✭ 32 (-45.76%)
Mutual labels:  audio-player
Laden
SwiftUI loading indicator view
Stars: ✭ 23 (-61.02%)
Mutual labels:  swift-package-manager
react-aplayer
🍭 A React wrapper component of APlayer
Stars: ✭ 25 (-57.63%)
Mutual labels:  audio-player
lplayer
lplayer is a simple audio player for simply listening
Stars: ✭ 40 (-32.2%)
Mutual labels:  audio-player
BetterMappable
Better Mappable through Property Wrappers using ObjectMapper
Stars: ✭ 26 (-55.93%)
Mutual labels:  swift-package-manager
tangerine
A work-in-progress music player for the Nintendo 3DS and Nintendo Switch
Stars: ✭ 20 (-66.1%)
Mutual labels:  audio-player
sepia-stt-server
SEPIA server to support open-source speech recognition via WebSocket connection.
Stars: ✭ 45 (-23.73%)
Mutual labels:  audio-streaming
FitDataProtocol
Swift Implementation the Garmin Flexible and Interoperable Data Transfer Protocol.
Stars: ✭ 32 (-45.76%)
Mutual labels:  swift-package-manager

AudioStreaming CI

AudioStreaming

An AudioPlayer/Streaming library for iOS written in Swift, allows playback of online audio streaming, local file as well as gapless queueing.

Under the hood AudioStreaming uses AVAudioEngine and CoreAudio for playback and provides an easy way of applying real-time audio enhancements.

Supported audio

  • Online streaming (Shoutcast/ICY streams) with metadata parsing
  • AIFF, AIFC, WAVE, CAF, NeXT, ADTS, MPEG Audio Layer 3, AAC audio formats
  • M4A (Optimized files only)

Known limitations:

Requirements

  • iOS 12.0+
  • Swift 5.x

Using AudioStreaming

Playing an audio source over HTTP

Note: You need to keep a reference to the AudioPlayer object

let player = AudioPlayer()
player.play(url: URL(string: "https://your-remote-url/to/audio-file.mp3")!)

Playing a local file

let player = AudioPlayer()
player.play(url: URL(fileURLWithPath: "your-local-path/to/audio-file.mp3")!)

Queueing audio files

let player = AudioPlayer()
// when you want to queue a single url
player.queue(url: URL(string: "https://your-remote-url/to/audio-file.mp3")!)

// or if you want to queue a list of urls use
player.queue(urls: [
    URL(fileURLWithPath: "your-local-path/to/audio-file.mp3")!,
    URL(fileURLWithPath: "your-local-path/to/audio-file-2.mp3")!
])

Adjusting playback properties

let player = AudioPlayer()
player.play(url: URL(fileURLWithPath: "your-local-path/to/audio-file.mp3")!)
// adjust the playback rate
player.rate = 2.0

// adjusting the volume
player.volume = 0.5

// mute/unmute the audio
player.mute = true

// pause the playback
player.pause()

// resume the playback
player.resume()

// stop the playback
player.stop()

// seeking to to a time (in seconds)
player.seek(to: 10)

Audio playback properties

let player = AudioPlayer()
player.play(url: URL(fileURLWithPath: "your-local-path/to/audio-file.mp3")!)

// To get the audio file duration
let duration = player.duration

// To get the progress of the player
let progress = player.progress

// To get the state of the player, for possible values view the `AudioPlayerState` enum
let state = player.state

// To get the stop reason of the player, for possible values view the `AudioPlayerStopReason` enum
let state = player.stopReason

AudioPlayer Delegate

You can inspect various callbacks by using the delegate property of the AudioPlayer to get informed about the player state, errors etc. View the AudioPlayerDelegate for more details

let player = AudioPlayer()
player.play(url: URL(fileURLWithPath: "your-local-path/to/audio-file.mp3")!)

player.delegate = self // an object conforming to AudioPlayerDelegate

// observing the audio player state, provides the new and previous state of the player.
func audioPlayerStateChanged(player: AudioPlayer, with newState: AudioPlayerState, previous: AudioPlayerState) {}

Adding custom audio nodes to AudioPlayer

AudioStreaming provides an easy way to attach/remove AVAudioNode(s). This provides a powerful way of adjusting the playback audio with various enchncements

let reverbNode = AVAudioUnitReverb()
reverbNode.wetDryMix = 50 

let player = AudioPlayer()
// attach a single node
player.attach(node: reverbNode)

// detach a single node
player.detach(node: reverbNode)

// detach all custom added nodes
player.detachCustomAttachedNodes()

The example project shows an example of adding a custom AVAudioUnitEQ node for adding equaliser to the AudioPlayer

Adding custom frame filter for recording and observation of audio data

AudioStreaming allow for custom frame fliters to be added so that recording or other observation for audio that's playing.

You add a frame filter by using the AudioPlayer's property frameFiltering.

let player = AudioPlayer()
let format = player.mainMixerNode.outputFormat(forBus: 0)

let settings = [
    AVFormatIDKey: kAudioFormatMPEG4AAC,
    AVSampleRateKey: format.sampleRate,
    AVNumberOfChannelsKey: format.channelCount
] as [String : Any]

var audioFile = try? AVAudioFile(
        forWriting: outputUrl,
        settings: settings,
        commonFormat: format.commonFormat,
        interleaved: format.isInterleaved)

let record = FilterEntry(name: "record") { buffer, when in
    try? audioFile?.write(from: buffer)
}

player.frameFiltering.add(entry: record)

See the FrameFiltering protocol for more ways of adding and removing frame filters. The callback in which you observe a filter will be run on a thread other than the main thread.

Under the hood the concrete class for frame filters, FrameFilterProcessor installs a tap on the mainMixerNode of AVAudioEngine in which all the added fitler will be called from.

Note since the mainMixerNode is publicly exposed extra care should be taken to not install a tap directly and also use frame filters, this result in an exception because only one tap can be installed on an output node, as per Apple's documention.

Installation

Cocoapods

Cocoapods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To intergrate AudioStreaming with Cocoapods to your Xcode project add the following to your Podfile:

pod 'AudioStreaming'

Swift Package Manager

On Xcode 11.0+ you can add a new dependency by going to File / Swift Packages / Add Package Dependency... and enter package repository URL https://github.com/dimitris-c/AudioStreaming.git, then follow the instructions.

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate AudioStreaming into your Xcode project using Carthage, add the following to your Cartfile:

github "dimitris-c/AudioStreaming"

Visit installation instructions on Carthage to install the framework

Licence

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

Attributions

This librabry takes inspiration on the already battled-tested streaming library, StreamingKit. Big 🙏 to Thong Nguyen (@tumtumtum) and Matt Gallagher (@mattgallagher) for AudioStreamer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].