How to change Audio Loadtype through code?

Hi everyone!

I was wondering if it was somehow possible to change the audio loadtype through script. I wish to load dynamically .mp3 from disc and set the flag to LoadType “Stream from disc” without having to pass through Unity.
Is it possible to change this flag ? Or is it possible to set a “default flag” so that every new clip will be like that?

Thanks for your answers :slight_smile:

(and sorry for my english)

Hi. Trying to find a solution on this too. I’m trying to call AudioClip.GetData(…) on a sample but get the following error:

*Cannot get data on compressed samples. Changing the load type to DecompressOnLoad on the AudioClip will fix this.
UnityEngine.AudioClip:GetData(Single[], Int32)*

I need to do this on any AudioClip of my game so my approach would be:

string path = AssetDatabase.GetAssetPath(clip);
clip.loadType = DecompressOnLoad;
clip.loadType = /*RestoreOriginalLoadType*/;

Any way this can be done? Thanks in advance

When you load an audio file from disk using the newer UnityWebRequest and UnityWebRequestMultimedia.GetAudioClip() - you can use a DownloadHandlerAudioClip to get access to the audio clip.

This class - DownloadHandlerAudioClip - has properties that allow you to specify whether the files from disc should be compressed in memory or streaming.