2
\$\begingroup\$

I use www.GetAudioClip() to get a song and play it when my Android mobile game starts.

My issue is that it takes a 3-second delay to play the song.

My idea is to add some loading screen before starting the game, and the game starts after www.GetAudioClip() finishes getting the song and I begin to play it. But I don't know how to control the loading screen so it disappears after the right delay.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Your suggestion sounds great, why don't you add a loading screen? What exactly do you need help for? \$\endgroup\$ Commented Sep 7, 2018 at 8:53
  • 1
    \$\begingroup\$ @TomTsagk good sir i don't no how to add loading screen that stop after www.GetAudioClip() complete \$\endgroup\$
    – 1323254365
    Commented Sep 7, 2018 at 9:51

1 Answer 1

2
\$\begingroup\$

This can be done with a coroutine you start by calling StartCoroutine(LoadSongWithLoadingScreen(songURL));

IEnumerator LoadSongWithLoadingScreen(string url) {

    // Show your loading screen.
    loadingVisuals.SetActive(true);

    // Start the download.
    var request = new WWW(url);

    // Wait for the download to finish,
    // letting the game continue running
    // and animating in the meantime.
    yield return request;

    // TODO: check for & handle network errors.

    // Hide loading screen.
    loadingVisuals.SetActive(false);

    // Use your song.
    song = www.GetAudioClip();
    PlaySong(song);
}
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .