

How To Make Your App Support Background Audio Playback
source link: https://sweettutos.com/2020/09/08/how-to-make-your-app-support-background-audio-playback/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How To Make Your App Support Background Audio Playback
This tutorial is tested with Swift 5 and Xcode 11.6.
In this quick tutorial, I will show you how to quickly add support for background audio playback.
Audio playback in background comes in handy in many use cases, Audiobooks are one famous case. You can play and listen to the audiobook while still being able to use other apps. Youtube also offer background playback as a premium feature in their iOS app.
To get started, I prepared a starter project, download it here.
Open ViewController.swift and make the following modifications:
Since loading an audio may fail, it’s important to load the file inside a do-catch block.
Build and run the project and make sure the audio track playback starts correctly.
So far, if you press the home button, the app will enter to background state and the audio file playback will stop.
Supporting the background mode..
In order for the app to support audio playback in background, you first need to add the background mode capability to the app.
To do so, select the project from the Project navigator, then select Signing & Capabilities, click on the ‘+’ button at the top left and select Background Modes from the list. Finally check the Audio, AirPlay, and Picture in Picture mode.

To finish up, select the ViewController.swift file and add the following code to the viewDidLoad method.
Here you go, build and run the project, enter the app to background state and notice how the audio file playback does not get interrupted :]
You can download the final project here.
See you in next article
If you enjoy this post, you can subscribe in the form below to get notified of all our upcoming tutorials, ebooks, apps and discounts.
Recommend
-
99
HDR Video Playback Support is coming to Chrome for Android The proliferation of High Dynamic Range (HDR) video is the next step in improving video quality for all. HDR significa...
-
14
Back to basics: adding a playback speed control to an audio playerSkip to content
-
6
May 6, 2021 — 14:27 CUT Deezer’s New HomePod Integration Supports Hi-Res Audio Playback
-
6
A fully-fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more! V2
-
7
Facebook Launches Live Audio Rooms and Podcast Playback In-Stream Published June 21, 2021 By A...
-
4
Still haunted by the ghost of Google Play Music — YouTube Music continues glacial development pace, adds background playback Five years after launch, YouTube Music is still working on basi...
-
6
Twitter Tests Variable Playback Speeds for Audio and Video Content in the App Published Feb. 8, 2022 By
-
7
Enjoy big bass and 20 hours of playback with Audio-Technica’s new earbuds
-
2
AudioCue-maven AudioCue is a Java audio-playback class, modeled on javax.sound.sampled.Clip, enhanced wit...
-
4
Vivaldi 5.7 for Android now supports YouTube background playback for non-Premium users February 23, 202...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK