3

I am trying to override the sound that plays when a focus change is made on tvOS, but I cannot seem to find anything indicating if this is possible. I have looked through the Apple documentation a bit, and looked at some of the sound API's but none seemed to fit. Does anybody know if this is even possible? If this is possible how can this be achieved?

Bryce Meyer
  • 249
  • 5
  • 9
  • I would be much interested in a solution whenever you find one. So far (tvOS 9.1) I can only imagine to implement a custom focus engine that plays your own sounds. :-( – bio Dec 13 '15 at 20:06
  • I spent a decent amount of time researching this, and it seems to just be unavailable API at the moment. I did open a bug report with apple for an enhancement, so you should too! If enough people request it they will probably add it. – Bryce Meyer Dec 14 '15 at 23:07

1 Answers1

1

This can be achieved with soundIdentifierForFocusUpdate, which was added to the SDK in tvOS 11

Using this method, 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 insted, you must include the new sound file in your target, and to load as shown here below:

let myPing = UIFocusSoundIdentifier.init(rawValue: "customPing")
let soundURL = Bundle.main.url(forResource: "ping", withExtension: "aif")!
UIFocusSystem.register(_: soundURL, forSoundIdentifier: myPing)

Then you have to return that sound new from soundIdentifierForFocusUpdate:

override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? {    
    return myPing
}

Everything is documented by Apple in the following link: Using Custom Sounds for Focus Movement

David Cordero
  • 770
  • 6
  • 16