A framework for streaming audio between Apple devices using AirPlay.

Overview

Airstream

An iOS / macOS framework for streaming audio between Apple devices using AirPlay.

An example gif

You can use Airstream to start an AirPlay server in your iOS or macOS applications. Then, any Apple device can stream audio to your application via AirPlay, with no extra software required.

Table of contents

Installation

Airstream can be installed by using either Carthage or just simply cloning this repository and its submodules in your project.

Carthage

Carthage is a decentralized dependency manager for Cocoa.

You can install it using Homebrew with the following commands:

$ brew update
$ brew install carthage

Then, to include Airstream in your project, specify it in your Cartfile (make sure it's in the same directory as your .xcodeproj):

github "qasim/Airstream" ~> 0.1

Now you can install Airstream:

$ carthage update

You should now see a Carthage/Builds directory. From there, you can drag the built Airstream.framework for your platform of choice into your Xcode project, and then add it as an embedded binary in your project's settings.

Basic usage

First, initialize and start Airstream somewhere (make sure that it's retained). You'll also want to set its delegate.

let airstream = Airstream(name: "My Airstream")

airstream.delegate = self
airstream.startServer()

That's it! Your own AirPlay server is now up and running. You can gracefully shut it down as well:

airstream.stopServer()

Implement any of the delegate methods to actually make use of Airstream's features, like retrieving a song's album artwork:

func airstream(airstream: Airstream, didSetCoverart coverart: NSData) {
  // Coverart for the item that's currently streaming
  let image = NSImage(data: coverart)
}

For a more detailed example on how to use Airstream, you can refer to the example projects which implement Airstream with the streamed audio output going directly to speakers via CoreAudio:

API reference

Airstream

This is the main class, from which you can start and stop the AirPlay server.

func init()
func init(name: String?)
func init(name: String?, password: String?)
func init(name: String?, password: String?, port: UInt)

Basic initializers for the Airstream.

func startServer()

Starts the AirPlay server and begins broadcasting.

func stopServer()

Gracefully shuts down the AirPlay server.

var name: String

The AirPlay server's receiver name. This is what is shown to devices when they go to connect to your AirPlay server. "My Airstream" by default.

var password: String?

The AirPlay server's receiver password. You can set this to prompt any Apple devices that wish to connect to your AirPlay server with a password challenge.

var port: UInt

The port where the AirPlay server should broadcast to. 5000 by default.

var running: Bool

Determines whether the server is currently running or not.

var remote: AirstreamRemote?

The reference to this Airstream's remote control object, which can be used to send commands to the connected device. This variable may not be set until the delegate has called airstream:didGainAccessToRemote:.

var volume: Float?

The connected Apple device's volume, between 0.0 (no volume) and 1.0 (maximum volume).

var metadata: [String: String]?

The metadata for the current item being streamed.

var coverart: Data?

The JPEG artwork (in binary) for the current item being streamed.

var position: UInt

The position (in seconds) of the current item being streamed.

var duration: UInt

The total duration (in seconds) of the current item being streamed.

AirstreamDelegate

This is the delegate class for Airstream. By conforming to this protocol, you can listen for changes in AirPlay server status and be notified when data changes.

optional func airstream(_ airstream: Airstream, willStartStreamingWithStreamFormat streamFormat: AudioStreamBasicDescription)

Called right after a device has connected and is about to stream audio. AudioStreamBasicDescription is a struct outlining the details of the audio output.

optional func airstreamDidStopStreaming(_ airstream: Airstream)

Called right after a device has disconnected.

optional func airstream(_ airstream: Airstream, didGainAccessToRemote remote: AirstreamRemote)

Called right after the remote control connection has been setup.

optional func airstream(_ airstream: Airstream, processAudio buffer: UnsafeMutablePointer<Int8>, length: Int32)

Process linear PCM audio streamed from a device. buffer is a pointer to the audio data, and length is the number of bytes stored there.

optional func airstreamFlushAudio(_ airstream: Airstream)

Reset any audio output buffers you may be using, as the source has either changed or been disrupted.

optional func airstream(_ airstream: Airstream, didSetVolume volume: Float)

Called when a device's volume was changed.

optional func airstream(_ airstream: Airstream, didSetMetadata metadata: [String: String])

Called when a device's metadata for the current item being streamed was changed.

optional func airstream(_ airstream: Airstream, didSetCoverart coverart: Data)

Called when a device's artwork for the current item being streamed was changed.

optional func airstream(_ airstream: Airstream, didSetPosition position: UInt, duration: UInt)

Called when a device's current position or duration for the current item being streamed was changed.

AirstreamRemote

This is the remote control object. If this is present on the Airstream object, then you will be able to send commands to the device connected to your AirPlay server.

func play()

Start playback.

func pause()

Pause playback.

func stop()

Stop playback.

func playPause()

Toggle between starting and pausing playback.

func playResume()

Play after fast forwarding or rewinding.

func forward()

Begin fast forward.

func rewind()

Begin rewind.

func nextItem()

Play next item in playlist.

func previousItem()

Play previous item in playlist.

func shuffle()

Shuffle items in playlist.

func increaseVolume()

Turn audio volume up.

func decreaseVolume()

Turn audio volume down.

func toggleMute()

Toggle mute status.

Shairplay

Airstream works by depending on a C library called shairplay, which is a free portable AirPlay server implementation. You can also visit qasim/shairplay for the fork of shairplay that is used by Airstream, which compiles on both iOS and macOS.

Disclaimer

This framework is really meant for educational purposes only. I hold no guarantee that integrating this framework into your application will allow you to pass Apple's app review process.

License

Airstream is released under the MIT license. See LICENSE for details.

You might also like...
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

MultiPeer-Progress-iOS - Swift project to demo the use of the MultiPeer framework to send files between iOS devices and show the progress
BluetoothKit Easily communicate between iOS devices using BLE.

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

Easily communicate between iOS/OSX devices using BLE

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

NWReachability - a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

NWReachability is a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

A Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness and flexibility.
A Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness and flexibility.

Keychain Manager Keychain Manager is a Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness

Zero-setup P2P file transfer between Macs and iOS devices
Zero-setup P2P file transfer between Macs and iOS devices

🚀 Ares Zero-setup* P2P file transfer between Macs and iOS devices Ares is a service that I built in under 24 hours, winning first place at HackED 201

OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.
OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.

Text Chat Accelerator Pack iOS This project is deprecated The OpenTok Text Chat Accelerator Pack for iOS project is now a part of Accelerator Core iOS

Bonjour networking for discovery and connection between iOS, macOS and tvOS devices.
Bonjour networking for discovery and connection between iOS, macOS and tvOS devices.

Merhaba Bonjour networking for discovery and connection between iOS, macOS and tvOS devices. Features Creating Service Start & Stop Service Stop Brows

NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS
NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS

NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS. Integration can optionally leverage AVFoundation or ARKit.

Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS.
Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS.

HaishinKit (formerly lf) Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS. Issuesの言語は、日本語が分かる方は日本語でお願いします! Sponsored with 💖

Swifty360Player - iOS 360-degree video player streaming from an AVPlayer.
Swifty360Player - iOS 360-degree video player streaming from an AVPlayer.

Swifty360Player iOS 360-degree video player streaming from an AVPlayer. Demo Requirements Swifty360Player Version Minimum iOS Target Swift Version 0.2

Radio & Podcast Streaming App For WPRK
Radio & Podcast Streaming App For WPRK

WPRK(iOS & iPadOS) Radio & Podcast Streaming App For WPRK, a licensed FCC broadcast station, The app allows users to connect to live music streams and

A camera designed in Swift for easily integrating CoreML models - as well as image streaming, QR/Barcode detection, and many other features
A camera designed in Swift for easily integrating CoreML models - as well as image streaming, QR/Barcode detection, and many other features

Would you like to use a fully-functional camera in an iOS application in seconds? Would you like to do CoreML image recognition in just a few more sec

Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS.
Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS.

HaishinKit Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS. Issuesの言語は、日本語が分かる方は日本語でお願いします! Sponsored with 💖 by Enterprise

A simple demo app to showcase streaming HLS with SwiftUI Videoplayer

HLS Streaming with SwiftUI Basic implementation of VideoPlayer for SwiftUI to play remote media files using HTTP Live Streaming (HLS). Multiple views

iOS 360-degree video player streaming from an AVPlayer.
iOS 360-degree video player streaming from an AVPlayer.

Swifty360Player iOS 360-degree video player streaming from an AVPlayer. Demo Requirements Swifty360Player Version Minimum iOS Target Swift Version 0.2

Comments
  • Audio stuttering

    Audio stuttering

    I've been playing around with the framework for the last few days and I've noticed a lot of stuttering when streaming audio. I've tried it on two different networks with the same issue, so I don't think it's network related. Pausing/Playing doesn't seem to do anything.

    Does this have something to do with the buffer size being used? I frequently use Airplay on my Apple TV without any issues.

    opened by stephengilroy 3
  • Name / Password / Running Multiple Servers

    Name / Password / Running Multiple Servers

    I've set the delegate for initWithName password, but I'm able to connect to the server without entering credentials. Also, how do we run multiple servers? I have three rooms, each with a computer and speakers, but only one server shows in the portable. So I have to turn off the others to use a particular set of speakers.

    Thanks!

    opened by doriansgithub 0
  • Add support for AirPlay video streaming / mirroring

    Add support for AirPlay video streaming / mirroring

    The bottleneck for adding additional AirPlay features defined in this unofficial specification is the dependency on shairplay.

    I think the right tools are available in Swift to write the RAOP server + use NSNetService for publishing the AirPlay service to the local network, to accomplish the same thing shairplay does.

    Then, we can build on the implementation to add support for non-Apple platforms and additional features like AirPlay mirroring.

    opened by qasim 1
  • Add CocoaPods support and installation steps

    Add CocoaPods support and installation steps

    Because of this project's interesting dependencies, I don't have an Airstream.podspec yet, nor can this build on its own with something like Carthage. You can, however, just drag this project into your own Xcode project and add it as an embedded binary.

    The challenges to get this to work with CocoaPods:

    • Build libshairplay.a and its dependencies alac.a + crypto.a
    • Build Airstream.framework
    opened by qasim 1
Releases(0.1.0)
Owner
Qasim Iqbal
Software, experiments, and having fun.
Qasim Iqbal
Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS.

HaishinKit Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS. Issuesの言語は、日本語が分かる方は日本語でお願いします! Sponsored with ?? by Enterprise

shogo4405 2.4k Jan 2, 2023
Syntax sugar of OpenTok iOS SDK with Audio/Video communication including screen sharing

Accelerator Core iOS The Accelerator Core is a solution to integrate audio/video communication to any iOS applications via OpenTok platform. Accelerat

OpenTok 30 Nov 8, 2022
An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.

A simple, intuitive audio framework for iOS and OSX. Deprecated EZAudio has recently been deprecated in favor of AudioKit. However, since some people

Syed Haris Ali 4.9k Jan 2, 2023
Muxer used on top of Feed iOS SDK for airplay

FeedAirplayMuxer Muxer used on top of Feed iOS SDK for airplay purposes. Demo Project --> https://github.com/feedfm/AirplayDemo Feed Airplay Muxer is

Feed Media 0 May 6, 2022
Player for streaming local and remote audio files. Written in Swift.

Jukebox is an iOS audio player written in Swift. Contents Features Installation Supported OS & SDK versions Usage Handling remote events Public interf

Teo 545 Nov 11, 2022
The Amazing Audio Engine is a sophisticated framework for iOS audio applications, built so you don't have to.

Important Notice: The Amazing Audio Engine has been retired. See the announcement here The Amazing Audio Engine The Amazing Audio Engine is a sophisti

null 523 Nov 12, 2022
Automated Apple Music Lossless Sample Rate Switching for Audio Devices on Macs.

LosslessSwitcher switches your current audio device's sample rate to match the currently playing lossless song on your Apple Music app, automatically.

Vincent Neo 371 Dec 27, 2022
iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.

iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.While the cost of storage seems expensive in comparison to other online storage services, its advantage is that it works natively across all your devices.

MindInventory 12 Jul 29, 2022
Audio player demo based on Swift and SwiftUI, which can play local or network audio.

SwiftAudioDemo Audio player demo based on Swift and SwiftUI, which can play local or network audio. In this demo, I have made a radio player to play n

Jensen Zhang 6 Mar 13, 2022
AudiosPlugin is a Godot iOS Audio Plugin that resolves the audio recording issue in iOS for Godot Engine.

This plugin solves the Godot game engine audio recording and playback issue in iOS devices. Please open the Audios Plugin XCode Project and compile the project. You can also use the libaudios_plugin.a binary in your project.

null 3 Dec 22, 2022