Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Streaming Music Hitch - iOS - Unity 4.5.5

Discussion in 'Audio & Video' started by davekalina, Jan 29, 2015.

  1. davekalina

    davekalina

    Joined:
    Apr 2, 2013
    Posts:
    39
    (Perhaps I posted this in the wrong forum previously)

    Whenever we start playing a new 'stream from disc' audio clip, our game "hitches" for about half a second right as playback of the new track begins.

    All of our AudioClips are set as follows:

    - Load type: Stream from disc
    - Hardware decoding: yes
    - 3D sound: no

    Our music player class references a bunch of GameObjects which contain AudioSources that point at all of our individual songs. The Music Player calls Stop() on the previous song and waits a second and then calls Start() on the new song, and it's in that frame -- where we call Start() on the new song -- that the game hitches.

    While it's not exactly a fatal error, our game is fast-paced and performance hitches like this are very noticeable. Would obviously like to know what we're doing wrong!
     
  2. davekalina

    davekalina

    Joined:
    Apr 2, 2013
    Posts:
    39
    Pinging this 6 weeks later.

    Would really appreciate some feedback / suggestions.
     
  3. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    Just a guess, but have you tried loading/playing from within a coroutine? It sounds to me like Unity is trying to load the stream and play it in one frame but isn't fast enough. Maybe a coroutine could be able to do this work across several frames?
     
  4. davekalina

    davekalina

    Joined:
    Apr 2, 2013
    Posts:
    39
    Thanks for the reply, aihodge! You're the first person to even attempt to answer this question in over 2 months of me pinging the forums :)

    Putting the music playback code in a coroutine did not help, though I appreciate the idea. Not sure how it would since coroutines don't spawn separate threads. I'm wondering if I can somehow offload music playback to another thread ...?

    I finally attached the Unity profiler to my iPhone 6 and the spike is over 300msec and can be isolated to the call to AudioSource.Play().