David Cordero
How to override focus sound in tvOS
Published on 08 Jan 2025
By default, every focus update in tvOS triggers a sound. This is very useful, specially in terms of accessibility since it adds additional feedback to the UX while using the remote control.
However, sometimes this useful feature can become a problem, for example when creating a game with custom sounds, or when it mixes with the audio of our video content.
Fortunately, you can override this sound using soundIdentifierForFocusUpdate, introduced in tvOS 11.
Using soundIdentifierForFocusUpdate, you can customize or remove the default sound of tvOS played on focus updates.
To remove the sound you can return UIFocusSoundIdentifier.none
override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? {
return UIFocusSoundIdentifier.none
}
To use a different sound instead, you must include the new sound file in your target, and to load as shown here below:
let superMarioSound = UIFocusSoundIdentifier.init(rawValue: "mario")
let marioURL = Bundle.main.url(forResource: "mario", withExtension: "aiff")!
UIFocusSystem.register(_: marioURL, forSoundIdentifier: superMarioSound)
Then you have to return that sound new from soundIdentifierForFocusUpdate:
override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? {
return superMarioSound
}