Search Unity

Sound issues when coming back form background

Discussion in 'iOS and tvOS' started by DannyB, Sep 25, 2013.

  1. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    There are a couple of issues with sound I am experiencing on iOS 7 when my game returns from the background:

    1. When returning, music sometimes stutters for a second or two before proceeding with normal play. This also happened in previous iOS

    2. This is the more severe issue (iOS 7 only) - sometimes when coming back from background, the sound is not playing at all. I need to send it back to background and open it again for it to be restored.

    At first I suspected my code, as I used to mute sounds when going to background, but this happens after I have removed this code completely.

    Is anyone else experiencing this?
     
  2. andykscott

    andykscott

    Joined:
    Nov 14, 2012
    Posts:
    2
    Hi! We had the same problem, and resolved it by upgrading to the latest version of Xcode.
     
  3. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    I am using the latest (5.0)...

    Can you tell me what are the settings in your audio source? I mean, is it Stream from Disk / Load to Memory? Is the source MP3? Is "Hardware Acceleration" ticked? Maybe one combination works better then others...
     
  4. andykscott

    andykscott

    Joined:
    Nov 14, 2012
    Posts:
    2
    We using both streaming and in-memory; all MP3's; no hardware decoding.
     
  5. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Well, thanks, but I guess its not the Xcode that solved it but something else. Are you using Unity 4.2.1?
     
  6. DavidJNels

    DavidJNels

    Joined:
    Aug 10, 2012
    Posts:
    34
    We have also experienced this using the new Xcode, iOS 7 and Unity 4.3

    I also had this happen to me on the new Deer Hunter game too, so it's definitely something that has recently happening and is affecting a number of games.
     
  7. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    David, it would be great if you can also send a bug report to Unity, as this is quite a serious bug and the more they see it, the better the chances for a quicker fix.
     
  8. ottolb

    ottolb

    Joined:
    Jul 1, 2009
    Posts:
    42
    Hi Danny, one of the beta testers is having this issue, but I'm gathering more info (iOS version, device...) to better know the problem.
    I can't reproduce it playing with a iPad2 with iOS 7.0, I'm using Unity 4.2.1
     
  9. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    I guess it depends on several parameters, but I can tell you these are the points to keep in mind when trying to reproduce:

    ( I have reproduced my problem with the same hardware/os/unity configuration )

    1. Create a scene with a music track
    2. The music track should be long enough
    3. Set the sound file to Stream from Disk (it happens in other scenarios also, but this is better)
    4. When the music plays, press the Home button to send it to background
    5. Then, open it again.
    6. If you dont hear the sound disappear or stutter, try opening another app before reopening your game.
    7. If all the above still doesnt reproduce, open several more apps for increased memory consumption

    Even with this list, I admit it is sometimes harder to reproduce, but the bug is definitely there (either iOS7 or Unity) even in Unity games that are already out.
     
  10. markofjohnson

    markofjohnson

    Joined:
    Oct 12, 2010
    Posts:
    68
    We have always had a problem where the game goes mute upon forgrounding reported by customers. Its very hard to repro. I've only personally seen it once, toggling iPad mute switch to mute then unmute the sound back. Its hard to separate the problem from people just muting their device, because some apps are able to ignore the mute switch so users get confused about whether their device is muted or not.
     
  11. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    I think what we have now is a different problem.
    It only started happening on iOS 7, and it does not mute (meaning, you cannot unmute it from within the game) - the sound is completely killed, and you need to minimize the app and open it again for it to get back.
     
  12. juggernate

    juggernate

    Joined:
    Mar 16, 2011
    Posts:
    18
    DannyB on which devices are you seeing this? I am seeing it on my iPhone5, but not on iPads2 and 3 (yet?) Hard to repro, if I restart my phone it stops happening for a while.
     
  13. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    iPad 2 and iPad Mini.
    A few days ago I got some encouraging news I hope from Unity support, saying they received a couple more reports like this. So I hope a fix is in the oven.

    For now, I have no choice but to release games with this problem, hoping it will not happen to frequently.
     
  14. juggernate

    juggernate

    Joined:
    Mar 16, 2011
    Posts:
    18
    I was hoping today's 4.2.2 update would fix this but I am still seeing, or rather, hearing it.
     
  15. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Oh man....
    Yeah, I see no mention of it in the release log

    But at least Build and Run is now supposed to work.
    At this point I would settle for a confirmation from Unity that they can reproduce and are aware of the bug. I am still not sure if it is on their radar.
     
  16. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Because of this, I created own plaugin to play MP3 files using Xcode Player to stream all musics and it just worked fine.
     
  17. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Hey guys - good news.

    I have just received an email from Unity QA, saying they can reproduce the issue and it is passed on to development.
    Wanted to share, in case anyone else is bothered by this bug.
     
  18. juggernate

    juggernate

    Joined:
    Mar 16, 2011
    Posts:
    18
    Oh good. Thanks for the update! I filed a bug too but haven't heard back yet
     
  19. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    Just for the record, my game, Krashlander. Which I just recently released an update for is having this exact same problem. Yikes. Hope it's fixed soon!
     
  20. LoTekK

    LoTekK

    Joined:
    Jul 19, 2010
    Posts:
    136
    DannyB: Out of curiosity, did QA tell you the actual cause of the audio dropout? We're experiencing this in our game right now, with no concrete clue as to whether it's possible to bandaid it until an official fix is released. We're trying a few things, but they're all just shots in the dark since we have no idea *why* it's happening.
     
  21. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    No, I'm afraid not.

    I can probably save you some trouble - I spent several days trying different things with no concrete or significant result.
    I have tested sound that is streamed from disk, loaded to memory, with and without hardware decoder, stereo vs mono, long vs short audio clips and some more variations.

    I even tried stopping/muting my sounds OnApplicationPause.

    As far as I could tell, streamed from disk sounds were more fragile (but it still happens with memory sounds), and longer clips (music) were more fragile - but all in all, I was able to reproduce the problem with all variations of the test case.
     
  22. LoTekK

    LoTekK

    Joined:
    Jul 19, 2010
    Posts:
    136
    Thanks for the reply, and for detailing what you've already tried! Have you tried disabling/re-enabling all audio sources on resume? I'm attempting that at the moment, but we won't know for sure if it helps until we've done more tests. It's a long shot in the dark, but that's about as good as it gets now, I guess.

    [update]

    Nope! That didn't work.

    [/update]
     
    Last edited: Oct 30, 2013
  23. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    No I haven't tried that. One reason I usually steer clear of messing with OnApplicationPause is that it also behaves differently between iOS versions. There is some inconsistency about the order of execution there and I remember I had a pretty big headache with this callback.
     
  24. LoTekK

    LoTekK

    Joined:
    Jul 19, 2010
    Posts:
    136
    Thanks, and fingers crossed a next Unity update comes soon, with this fix in place.
     
  25. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    ++++ on the fingers crossed...

    Got this 3 star review for Krashlander today:

    -Jeff
     
  26. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Sorry to hear Jeff.... if everybody that has this problem can send their own bug report (possibly with a repro case) to Unity, I think it will improve the chances of this getting a priority status.
     
  27. mansiva2000

    mansiva2000

    Joined:
    Jul 2, 2013
    Posts:
    9
    I just tried this and it seems to fix the issue:

    void OnApplicationPause(bool pauseStatus)
    {
    _musicSource.enabled = !pauseStatus;
    }


    Obviously it restarts the music automatically if you have "Play On Awake" set, otherwise you need to "Play" it yourself. Not ideal but I can live with that until a fix from Unity.

    I'm on Unity 4.3.1 using "Stream from disc"
     
  28. damiant

    damiant

    Joined:
    Mar 3, 2013
    Posts:
    1
    Is this still unsolved? I'm having this issue with the latest unity version (4.3.4)
     
  29. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Unsolved as far as I know, but I admit I am seeing it much less recently. Not sure if its because my Unity update or iOS update.
     
  30. HoMeBoYErik

    HoMeBoYErik

    Joined:
    Mar 12, 2014
    Posts:
    23
    Yes I confirm it's still unsolved. I'm developing a game with latest version of Xcode (that support ios 7.1) and latest Unity (4.3.4f1).
    I'm using Master Audio plugin from Dark Tonic. I control the pause and mute myself with the plugin.
    Every time a user on iOS send the game to background and comes back in the music playlist that was muted or paused starts to play again.
    I also reproduced the issue in Editor. Just pause the player, go to another application, comes back to unity and hit play and the muted music will play loudly.
    I also checked the OnApplicationPause() callback but it seems to be called quite randomly and doesn't reflect the actual pause of the game.

    Hope it'll fix soon.
     
  31. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    I think you may be experiencing a different issue.
    The issue I was referring to is that sound gets completely disabled when coming back from background, and it was never reproducible in the editor for me.

    I suggest you try without the audio plugin, maybe it is the culprit.
     
  32. TimK.Disney

    TimK.Disney

    Joined:
    Apr 12, 2013
    Posts:
    5
    So, is this still an issue in 4.3.4? I just got a bug today from our QA stating that this is happening with our game. Curious whether I should attempt to find some kind of workaround, or if it's purely an issue that has to be solved in the runtime.
     
  33. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    TimK - can you report which iOS version your QA guys are seeing the problem with?
     
  34. TimK.Disney

    TimK.Disney

    Joined:
    Apr 12, 2013
    Posts:
    5
    The latest version, I believe. I'll double check that.
     
  35. TimK.Disney

    TimK.Disney

    Joined:
    Apr 12, 2013
    Posts:
    5
    Yup, our QA are seeing it on iOS 7.0.4. Only on newer hardware, apparently, which is a bit weird.
     
  36. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Then I suggest you also send a bug report to Unity. If you have a repro case for them, even better, but I would submit even if not.

    If I recall correctly, when I submitted, I did send a very small project that reproduced it, and I believe the response was that they were able to reproduce it.
     
  37. sebastiansgames

    sebastiansgames

    Joined:
    Mar 25, 2014
    Posts:
    114
    wow-- still no resolution on this issue? same thing happening here. anyone know if maybe there's a flag in Xcode we could check so we could at least manually hack the sound back on? Very annoying
     
  38. mhalttu

    mhalttu

    Joined:
    Mar 13, 2013
    Posts:
    30
    Any updates or workarounds for this issue? It still isn't fixed at least in Unity 4.6.4. Has anybody tried it on Unity 5.0?
     
  39. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    I am still getting the no audio on resume issue. Using Unity 5. Takes about 5 mins in the background. Most prevalent on iPhone.
     
  40. Rod-Green

    Rod-Green

    Joined:
    Apr 19, 2010
    Posts:
    51
    We're getting the same issue - replying here in case someone comes up with a solution
     
  41. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    I have had this issue for awhile too. Currently using 4.6.4.

    iPad 2 running 8.x has the problem
    iPhone 5 running ios 6 does not
    Haven't noticed it with the iPad 2 on 8.x but I don't test with it a lot. Far as I can recall it has not happened.

    It happens on the iPad 3 when I put the game in the background, OR when I turn off the device with the game still running, then back on. Sometimes putting it in the background again works, sometimes no matter how many other apps I open it does not return, requiring an app restart.

    None of my testers have this problem, it happens all the time for me.

    I use no audio plugins.

    This is a big problem as I am submitting my app to Apple tomorrow, possibly tonight. So two years with no fix, according to this thread.
     
    Last edited: Dec 5, 2015
  42. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hello. Could anyone using recent Unity 5 release and seeing this issue on iOS 8.x or newer submit a bug report with reproduction project attached?

    The bugs we have in our database are all either fixed either by us or by Apply in iOS upgrade (e.g. 7.0.2->7.0.3). Without a proper reproduction project is unlikely Unity developers will ever be able to reproduce and fix the exact bug you are seeing.
     
  43. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    Wish I could do that, but I'm using Unity 4.6.4. Too late for me to upgrade for my release.
     
  44. itayganor

    itayganor

    Joined:
    Sep 24, 2018
    Posts:
    14
    This still happens in my game.