SlideShare a Scribd company logo
1 of 10
Download to read offline
iOS Background
Audio Playback
Korhan Bircan
@CocoaConf San Jose, 2015
Available Frameworks
• MediaPlayer
• AV Foundation
• Audio Toolbox
• Audio Unit
• OpenAL
Setupfunc setUpWithPath(path : NSURL) {
do {
player = try AVAudioPlayer(contentsOfURL: path)
if let player = player {
player.delegate = self
// Prepares the audio player for playback by preloading its buffers.
player.prepareToPlay()
// Communicate to the media services daemon our intent to use audio.
try AVAudioSession.sharedInstance().setActive(true)
}
} catch let error as NSError {
print(error.localizedDescription)
}
}
public class AVAudioPlayer : NSObject {
public func play() -> Bool
public func playAtTime(time: NSTimeInterval) -> Bool
public func pause()
public func stop()
public var playing: Bool { get }
public var numberOfChannels: Int { get }
public var duration: NSTimeInterval { get }
public var pan: Float
public var volume: Float
public var currentTime: NSTimeInterval
public var rate: Float
...
}
public protocol AVAudioPlayerDelegate : NSObjectProtocol {
optional public func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool)
optional public func audioPlayerDecodeErrorDidOccur(player: AVAudioPlayer, error: NSError?)
...
}
Lock screen controls
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [MPMediaItemPropertyTitle : title,
MPMediaItemPropertyAlbumTitle : subtitle,
MPMediaItemPropertyPlaybackDuration: duration!,
MPNowPlayingInfoPropertyPlaybackRate: NSNumber(integer: 1),
MPMediaItemPropertyArtwork: MPMediaItemArtwork(image: image)]
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.beginReceivingRemoteControlEvents()
...
}
override func remoteControlReceivedWithEvent(event: UIEvent?) {
super.remoteControlReceivedWithEvent(event)
let player = AudioPlayer.sharedInstance
if let event = event {
switch event.subtype {
case .RemoteControlPlay: ...
case .RemoteControlPause: ...
case .RemoteControlTogglePlayPause: ...
case .RemoteControlStop: ...
case .RemoteControlBeginSeekingForward: ...
case .RemoteControlEndSeekingForward: ...
case .RemoteControlEndSeekingBackward: ...
case .RemoteControlBeginSeekingBackward: ...
case .RemoteControlNextTrack: ...
case .RemoteControlPreviousTrack: ...
default:
break
}
}
}
Interruptions
var mode = AVAudioSessionModeDefault
/* AVAudioSessionModeVoiceChat
AVAudioSessionModeGameChat
AVAudioSessionModeVideoRecording
AVAudioSessionModeMoviePlayback
AVAudioSessionModeVideoChat
AVAudioSessionCategoryOptionDuckOthers ...
*/
if #available(iOS 9.0, *) {
mode = AVAudioSessionModeSpokenAudio
}
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
/* AVAudioSessionCategoryAmbient
AVAudioSessionCategoryRecord
AVAudioSessionCategoryPlayAndRecord ...
*/
try audioSession.setMode(mode)
// Registered listeners will be notified when the system has interrupted
// the audio session and when the interruption has ended.
NSString *const AVAudioSessionInterruptionNotification
Backgrounding
Data Protection
App Transport Security
Summary
• Choose the right technology
• Be ready to be interrupted
• Opt-in to backgrounding and don’t be hostile
• Understand capabilities you’re opting in
• Watch out for App Transport Security
Swifty Podcasts
Questions&Comments: korhanbircan@gmail.com

More Related Content

What's hot

Dev8d 2011-pipe2 py
Dev8d 2011-pipe2 pyDev8d 2011-pipe2 py
Dev8d 2011-pipe2 pyTony Hirst
 
Core audio
Core audioCore audio
Core audioscussen
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話dcubeio
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEThiago Rondon
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introductionthasso23
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)dantleech
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X ServerYasuhiro Asaka
 
Tonehammer Requiem Professional [KONTAKT] .rar
Tonehammer Requiem Professional [KONTAKT] .rarTonehammer Requiem Professional [KONTAKT] .rar
Tonehammer Requiem Professional [KONTAKT] .rarDeborahPadilla1
 
Cobbler Summit - Automated Xen VM Deployment
Cobbler Summit - Automated Xen VM DeploymentCobbler Summit - Automated Xen VM Deployment
Cobbler Summit - Automated Xen VM DeploymentAbhishek Singh
 
Puppet User Group Presentation - 15 March 2012
Puppet User Group Presentation - 15 March 2012Puppet User Group Presentation - 15 March 2012
Puppet User Group Presentation - 15 March 2012Walter Heck
 
Task 8 vst recording
Task 8   vst recordingTask 8   vst recording
Task 8 vst recordingNeilRogero
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 

What's hot (18)

Dev8d 2011-pipe2 py
Dev8d 2011-pipe2 pyDev8d 2011-pipe2 py
Dev8d 2011-pipe2 py
 
Core audio
Core audioCore audio
Core audio
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POE
 
DevOps Braga #6
DevOps Braga #6DevOps Braga #6
DevOps Braga #6
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introduction
 
Donetsk.py - fabric
Donetsk.py -  fabricDonetsk.py -  fabric
Donetsk.py - fabric
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
 
inotify
inotifyinotify
inotify
 
Solaris_quickref.pdf
Solaris_quickref.pdfSolaris_quickref.pdf
Solaris_quickref.pdf
 
Tonehammer Requiem Professional [KONTAKT] .rar
Tonehammer Requiem Professional [KONTAKT] .rarTonehammer Requiem Professional [KONTAKT] .rar
Tonehammer Requiem Professional [KONTAKT] .rar
 
Cobbler Summit - Automated Xen VM Deployment
Cobbler Summit - Automated Xen VM DeploymentCobbler Summit - Automated Xen VM Deployment
Cobbler Summit - Automated Xen VM Deployment
 
Puppet demo
Puppet demoPuppet demo
Puppet demo
 
Puppet User Group Presentation - 15 March 2012
Puppet User Group Presentation - 15 March 2012Puppet User Group Presentation - 15 March 2012
Puppet User Group Presentation - 15 March 2012
 
Fabric for fun_and_profit
Fabric for fun_and_profitFabric for fun_and_profit
Fabric for fun_and_profit
 
Task 8 vst recording
Task 8   vst recordingTask 8   vst recording
Task 8 vst recording
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 

Viewers also liked

Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Korhan Bircan
 
Useful Tools for Making Video Games - fmod (2008)
Useful Tools for Making Video Games - fmod (2008)Useful Tools for Making Video Games - fmod (2008)
Useful Tools for Making Video Games - fmod (2008)Korhan Bircan
 
Password Cracking with Rainbow Tables
Password Cracking with Rainbow TablesPassword Cracking with Rainbow Tables
Password Cracking with Rainbow TablesKorhan Bircan
 
Next-Gen shaders (2008)
Next-Gen shaders (2008)Next-Gen shaders (2008)
Next-Gen shaders (2008)Korhan Bircan
 
ios_summit_2016_korhan
ios_summit_2016_korhanios_summit_2016_korhan
ios_summit_2016_korhanKorhan Bircan
 
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0Korhan Bircan
 

Viewers also liked (7)

Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
Useful Tools for Making Video Games - fmod (2008)
Useful Tools for Making Video Games - fmod (2008)Useful Tools for Making Video Games - fmod (2008)
Useful Tools for Making Video Games - fmod (2008)
 
Korhan bircan
Korhan bircanKorhan bircan
Korhan bircan
 
Password Cracking with Rainbow Tables
Password Cracking with Rainbow TablesPassword Cracking with Rainbow Tables
Password Cracking with Rainbow Tables
 
Next-Gen shaders (2008)
Next-Gen shaders (2008)Next-Gen shaders (2008)
Next-Gen shaders (2008)
 
ios_summit_2016_korhan
ios_summit_2016_korhanios_summit_2016_korhan
ios_summit_2016_korhan
 
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0
 

Similar to Background Audio Playback

KKBOX WWDC17 Airplay 2 - Dolphin
KKBOX WWDC17 Airplay 2 - DolphinKKBOX WWDC17 Airplay 2 - Dolphin
KKBOX WWDC17 Airplay 2 - DolphinLiyao Chen
 
how to play .wav files in a java program on multiple devices!!! For .pdf
how to play .wav files in a java program on multiple devices!!! For .pdfhow to play .wav files in a java program on multiple devices!!! For .pdf
how to play .wav files in a java program on multiple devices!!! For .pdflakshmijewellery
 
제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEs
제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEs제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEs
제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEsdgmit2009
 
The sounds of Android (Android Makers 2018)
The sounds of Android (Android Makers 2018)The sounds of Android (Android Makers 2018)
The sounds of Android (Android Makers 2018)Yannick Lemin
 
Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)Bruno Delb
 
MOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with Brillo
MOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with BrilloMOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with Brillo
MOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with BrilloConstantin Musca
 
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)Chris Adamson
 
A (Mis-) Guided Tour of the Web Audio API
A (Mis-) Guided Tour of the Web Audio APIA (Mis-) Guided Tour of the Web Audio API
A (Mis-) Guided Tour of the Web Audio APIEdward B. Rockower
 
Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]
Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]
Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]Chris Adamson
 
openFrameworks 007 - sound
openFrameworks 007 - soundopenFrameworks 007 - sound
openFrameworks 007 - soundroxlu
 
iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)Chris Adamson
 
Flutter 에서 Native(iOS, Android) 코드와 통신하기
Flutter 에서 Native(iOS, Android) 코드와 통신하기Flutter 에서 Native(iOS, Android) 코드와 통신하기
Flutter 에서 Native(iOS, Android) 코드와 통신하기인수 장
 
watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話Kohki Miki
 
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)Chris Adamson
 
Deep dive into Android’s audio latency problem
Deep dive into Android’s audio latency problemDeep dive into Android’s audio latency problem
Deep dive into Android’s audio latency problemSirawat Pitaksarit
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with goHean Hong Leong
 
Building Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBuilding Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBob McCune
 

Similar to Background Audio Playback (17)

KKBOX WWDC17 Airplay 2 - Dolphin
KKBOX WWDC17 Airplay 2 - DolphinKKBOX WWDC17 Airplay 2 - Dolphin
KKBOX WWDC17 Airplay 2 - Dolphin
 
how to play .wav files in a java program on multiple devices!!! For .pdf
how to play .wav files in a java program on multiple devices!!! For .pdfhow to play .wav files in a java program on multiple devices!!! For .pdf
how to play .wav files in a java program on multiple devices!!! For .pdf
 
제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEs
제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEs제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEs
제 5회 DGMIT R&D 컨퍼런스: Sound Module With OperSLEs
 
The sounds of Android (Android Makers 2018)
The sounds of Android (Android Makers 2018)The sounds of Android (Android Makers 2018)
The sounds of Android (Android Makers 2018)
 
Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)
 
MOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with Brillo
MOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with BrilloMOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with Brillo
MOSS 2016, Bucharest, Romania - Designing the IoT Jukebox with Brillo
 
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
 
A (Mis-) Guided Tour of the Web Audio API
A (Mis-) Guided Tour of the Web Audio APIA (Mis-) Guided Tour of the Web Audio API
A (Mis-) Guided Tour of the Web Audio API
 
Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]
Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]
Core Audio: Don't Be Afraid to Play it LOUD! [360iDev, San Jose 2010]
 
openFrameworks 007 - sound
openFrameworks 007 - soundopenFrameworks 007 - sound
openFrameworks 007 - sound
 
iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)
 
Flutter 에서 Native(iOS, Android) 코드와 통신하기
Flutter 에서 Native(iOS, Android) 코드와 통신하기Flutter 에서 Native(iOS, Android) 코드와 통신하기
Flutter 에서 Native(iOS, Android) 코드와 통신하기
 
watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話
 
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
 
Deep dive into Android’s audio latency problem
Deep dive into Android’s audio latency problemDeep dive into Android’s audio latency problem
Deep dive into Android’s audio latency problem
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with go
 
Building Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBuilding Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngine
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Background Audio Playback

  • 1. iOS Background Audio Playback Korhan Bircan @CocoaConf San Jose, 2015
  • 2. Available Frameworks • MediaPlayer • AV Foundation • Audio Toolbox • Audio Unit • OpenAL
  • 3. Setupfunc setUpWithPath(path : NSURL) { do { player = try AVAudioPlayer(contentsOfURL: path) if let player = player { player.delegate = self // Prepares the audio player for playback by preloading its buffers. player.prepareToPlay() // Communicate to the media services daemon our intent to use audio. try AVAudioSession.sharedInstance().setActive(true) } } catch let error as NSError { print(error.localizedDescription) } } public class AVAudioPlayer : NSObject { public func play() -> Bool public func playAtTime(time: NSTimeInterval) -> Bool public func pause() public func stop() public var playing: Bool { get } public var numberOfChannels: Int { get } public var duration: NSTimeInterval { get } public var pan: Float public var volume: Float public var currentTime: NSTimeInterval public var rate: Float ... } public protocol AVAudioPlayerDelegate : NSObjectProtocol { optional public func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool) optional public func audioPlayerDecodeErrorDidOccur(player: AVAudioPlayer, error: NSError?) ... }
  • 4. Lock screen controls MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [MPMediaItemPropertyTitle : title, MPMediaItemPropertyAlbumTitle : subtitle, MPMediaItemPropertyPlaybackDuration: duration!, MPNowPlayingInfoPropertyPlaybackRate: NSNumber(integer: 1), MPMediaItemPropertyArtwork: MPMediaItemArtwork(image: image)] func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { application.beginReceivingRemoteControlEvents() ... } override func remoteControlReceivedWithEvent(event: UIEvent?) { super.remoteControlReceivedWithEvent(event) let player = AudioPlayer.sharedInstance if let event = event { switch event.subtype { case .RemoteControlPlay: ... case .RemoteControlPause: ... case .RemoteControlTogglePlayPause: ... case .RemoteControlStop: ... case .RemoteControlBeginSeekingForward: ... case .RemoteControlEndSeekingForward: ... case .RemoteControlEndSeekingBackward: ... case .RemoteControlBeginSeekingBackward: ... case .RemoteControlNextTrack: ... case .RemoteControlPreviousTrack: ... default: break } } }
  • 5. Interruptions var mode = AVAudioSessionModeDefault /* AVAudioSessionModeVoiceChat AVAudioSessionModeGameChat AVAudioSessionModeVideoRecording AVAudioSessionModeMoviePlayback AVAudioSessionModeVideoChat AVAudioSessionCategoryOptionDuckOthers ... */ if #available(iOS 9.0, *) { mode = AVAudioSessionModeSpokenAudio } let audioSession = AVAudioSession.sharedInstance() try audioSession.setCategory(AVAudioSessionCategoryPlayback) /* AVAudioSessionCategoryAmbient AVAudioSessionCategoryRecord AVAudioSessionCategoryPlayAndRecord ... */ try audioSession.setMode(mode) // Registered listeners will be notified when the system has interrupted // the audio session and when the interruption has ended. NSString *const AVAudioSessionInterruptionNotification
  • 9. Summary • Choose the right technology • Be ready to be interrupted • Opt-in to backgrounding and don’t be hostile • Understand capabilities you’re opting in • Watch out for App Transport Security