Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bug Streaming Audio to Apple HomePods Through AirPlay

Discussion in 'iOS and tvOS' started by DylanWalker1320, May 25, 2023.

  1. DylanWalker1320

    DylanWalker1320

    Joined:
    May 29, 2022
    Posts:
    3
    Hello, I am currently trying to get the audio for my game to play through a pair of Apple HomePods but whenever I try to pair the build device (iPad Air) to the speakers the audio will just continue to play out of either the iPad speakers or the most recently connected bluetooth device. The Mac that I am developing on is able to connect to the HomePods and play the game audio through them with no problems, the issue only occurs when I build the game and test it on the iPad. I've also confirmed that the iPad is able to play other audio through the speakers, but only seems to play music or audio from web browsers (things like YouTube or Apple Music).

    I'm really not sure where to go from here, so I figured I'd ask on this forum to see if anyone else has previously encountered this problem.

    Here's some information about the game:
    • The audio components are replaced by FMOD's studio emitters for spatialized sound
    • The Unity version is 2020.3.25f1
    • It is an AR game, using AR Foundation and iOS's ARKit.
    • The iPad is running iOS 16.4.1 and is an 5th Generation iPad Air
    Please let me know if you need more information about the game, thanks in advance.
     
  2. DylanWalker1320

    DylanWalker1320

    Joined:
    May 29, 2022
    Posts:
    3
    I've done a significant amount of research on this topic now and have been able to get it to partially work by manually modifying the generated Xcode project from Unity. What worked is the following:
    1. Open the Xcode project generated on build from Unity
    2. Search for "UnityAppController"
    3. Find the "startUnity" function
    4. Find that line that starts with AVAudioSession* audioSession =...
    5. Replace the next line (that should start with [audioSession setCategory: ... ]; with the following code
      [audioSession
      setCategory: AVAudioSessionCategoryPlayback
      mode: AVAudioSessionModeDefault
      routeSharingPolicy: AVAudioSessionRouteSharingPolicyLongFormAudio
      options: 0
      error: nil
      ];
    This solution works as a temporary fix, but ideally I want this line of code to either be there on compile or be replaced by some kind of script when the game is compiled. Is there an easy way of doing this? I looked into the iOS Native Pro plugin on the asset store but I don't think it offers the ability to change the routeSharingPolicy to long form audio which is what I need for this to work. If anyone has done this before or knows how to, your input would be greatly appreciated.