[object Object] Icon

Learn how to create, start, manage and modify Encodings

[object Object] Icon

Learn how to create, start, manage and modify Players

[object Object] Icon

Learn how to create, start, manage and modify Analyticss

Docs Home
User shortcuts for search
Focus by pressing f
Hide results by pressing Esc
Navigate via   keys

Thu Dec 30 2021

How to let audio play when the iOS device is in Silent mode ?

By default, audio only plays if the iOS device is unmuted (mute side switcher on iOS devices).

In order for audio to work by default, the app must declare that audio playback as a core feature of the app, and thus it should not be muted in “Silent Mode”.

This can be done by configuring the AVAudioSessionCategoryPlayback category: Apple Developer Documentation

You can choose from several audio session categories and settings to customize your app's audio behavior.

Bellow an example on how to modify the "AppDelegate.swift" file to change the default behavior:

1import AVFoundation
2import UIKit
5class AppDelegate: UIResponder, UIApplicationDelegate {
7func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
9 var categoryError :NSError?
10 var success: Bool
11 do {
12 // see https://developer.apple.com/documentation/avfoundation/avaudiosessioncategoryplayback
13 // and https://developer.apple.com/documentation/avfoundation/avaudiosessionmodemovieplayback
14 try AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback, options: .duckOthers)
15 success = true
16 } catch let error as NSError {
17 categoryError = error
18 success = false
19 }
21 if !success {
22 print("AppDelegate Debug - Error setting AVAudioSession category. Because of this, there may be no sound. \(categoryError!)")
23 }
25 // Override point for customization after application launch.
26 return true
29// MARK: UISceneSession Lifecycle
30func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
31 // Called when a new scene session is being created.
32 // Use this method to select a configuration to create the new scene with.
33 return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
36func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
37 // Called when the user discards a scene session.
38 // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
39 // Use this method to release any resources that were specific to the discarded scenes, as they will not return.

Give us feedback