Audio clip information is wrong in WebGL player when downloaded from a remote server

Hi guys,

We’re facing an issue when we try to access the AudioClip information after downloading it from a remote server.
It works on Unity Editor but the same code fails on WebGL.

using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, audioType))
{
    yield return www.Send();

    if (www.isNetworkError || www.isHttpError)
    {
        Debug.Log("Error Downloading audio: " + www.error);
    }
    else
    {
        AudioClip audio = DownloadHandlerAudioClip.GetContent(www);
        if (audio)
        {
            var result = audio.LoadAudioData();
            Debug.Log("LOAD AUDIO DATA RESULT: " + result);
            Debug.Log("AUDIO CLIP LENGTH: " + audio.length);
            Debug.Log("AUDIO CLIP STATE: " + audio.loadState);
            this.audioSource.clip = audio;
        }
        else
        {
            Debug.Log("Problem loading audio");
        }
    }
}

The logs on WebGL are:
LOAD AUDIO DATA RESULT: true
AUDIO CLIP LENGTH: 0 (expected 120 seconds)
AUDIO CLIP STATE: Unloaded (expected Loaded or Failed)

Are we missing some step or doing something wrong?

Thank you very much in advance!

1 Like

bump…

Anyway to get the length of an AudioClip on WebGL build on Unity 5.6 ?
I tried with UnityWebRequest.GetAudioClip and www.GetAudioClip, both return length 0.
I found that the issue was fixed in Unity 5.3 here : Unity Issue Tracker - [WebGL] Audio Clip length and sample count are both returned as 0 when using WWW.audioClip or WWW.GetAudioClip in WebGL builds
but it is not fixed at all :confused:

Anyway to get it to work ?

I will revive this old thread as I’m facing the same problem with Unity 2018.2.18f1 using .wav files from a TTS file. I need the duration to coordinate some stuff and I’m getting 0 from GetComponent().clip.length when in Unity Editor I get the correct value.

There’s any solution to this? clip.length work with some type of audio? which?

Thanks,

1 Like

Bump… I’m facing the same issue but when playing clip it plays but length returned is 0.

Same. Length is still 0 (and the sound plays !)

It’s 2021 and this problem is still present.
And the crazy thing is that it WON’T be fixed.

1 Like

Running into a similar issue at the moment: we’re downloading some audio from a remote server using UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG) and DownloadHandlerAudioClip.GetContent(request), and are noticing some differences in the file the moment we’ve downloaded it between the editor and WebGL.

When downloaded in the editor, the audio clip has a length of 7.176:
9378041--1311578--upload_2023-9-29_15-42-4.png

Whereas when downloaded in WebGL, using the same methods, the same audio clip has a length of 4.055:
9378041--1311575--upload_2023-9-29_15-41-21.png

So in the editor the clip plays in full, whereas in WebGL the same clip cuts out some of the way through. I’m conscious this may be a bit niche, but the audio clips we’re downloading were generated with CereProc and do have some slight audio glitches around the point they’re cut short in WebGL. When we paste the URL we used for the request into the same browser the audio plays in full, albeit with the glitch. I’m wondering if somewhere along the line some code is mistaking the audio glitch for the end of the clip somehow?

MP3 length issues were recently fixed and are currently being backported.

The bug caused MP3 files to be twice as long or short than the originals and was due to an approximation of the size based on too few MP3 frames.