Giter Site home page Giter Site logo

ipbackgroundaudio's Introduction

Summary

IPBackgroundAudioManger is meant to ease implementation of background audio in iOS5+ applications. It is ideal for applications that play audio tracks and need to handle remote control events as well as audio route change events (e.g. when the user unplugs their headphones). It also assists in setting up an AVAudioSession for music playback, and includes convenience methods for setting the "now playing" info on the lock screen.

Setup

Include the 2 IPBackgroundAudioManager source files in your project, and also add these frameworks:

  • AVFoundation.framework
  • AudioToolbox.framework
  • MediaPlayer.framework

Xcode Project

Next, add the UIBackgroundModes key to your info.plist

Info.plist

Start the audio session before your app begins playing audio:

[[IPBackgroundAudioManager sharedManager] startSessionWithCategory:AVAudioSessionCategoryPlayback error:nil];

(Optional) Handle notifications for remote control and audio route change events. The background audio manager will post the following NSNotifications:

  • IPBackgroundAudioNotificationRouteChanged: Posted when the default route changes for any reason.
  • IPBackgroundAudioNotificationRouteUnavailable: Posted when the default route changes because the previous route has become unavailable (e.g. headphones were unplugged). It's usually good form to stop playing audio when this happens.
  • IPBackgroundAudioNotificationRemoteControl: Posted when the app receives a remote control event. The relevant UIEvent object will be in the notification's userInfo dictionary, under the key IPBackgroundAudioRemoteControlEventKey

(Optional) Set the now playing info when playing tracks. When a track changes, you can set the lock screen's "now playing" info with a convenience method on IPBackgroundManager:

- (void) setNowPlayingInfoWithArtist:(NSString *)artist
                           album:(NSString *)album
                           title:(NSString *)title
                         artwork:(UIImage *)artwork
                        duration:(NSNumber *)duration

Demo

A sample project can be found in the "Demo" folder.

ipbackgroundaudio's People

Contributors

intrepidmatt avatar

Stargazers

Patrick Butkiewicz avatar SuperFancy avatar

Watchers

Glenn R. Martin avatar James Cloos avatar Evan Denerley avatar Maximilian Litteral avatar Tim Morrill avatar Justin Fyles avatar Kelvin Long avatar David Brooks avatar xchuang avatar Colin Tan avatar John McCormack avatar Peter Farlow avatar Jalil Kennedy avatar S. Wingchi Wong avatar Christopher Shea avatar Ricky Chen avatar Ankit Sharma avatar Kiley avatar Justine Kay avatar Leo Espinal avatar  avatar Anna Kassaraba avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.