public class Test : MonoBehaviour
{
public AudioClip clip;
public AudioSource source;
// Start is called before the first frame update
IEnumerator Start()
{
Debug.Log(string.Format("Play: len = {0}, channels = {1}, samples = {2}, frequency = {3}", clip.length, clip.channels, clip.samples, clip.frequency));
UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip("file://" + Application.streamingAssetsPath + "/100013_123956000001_1575965491.mp3", AudioType.MPEG);
UnityWebRequestAsyncOperation ao = request.SendWebRequest();
yield return ao;
if (ao.isDone)
{
AudioClip ccc = DownloadHandlerAudioClip.GetContent(request);
Debug.Log(string.Format("Play: len = {0}, channels = {1}, samples = {2}, frequency = {3}", ccc.length, ccc.channels, ccc.samples, ccc.frequency));
source.PlayOneShot(ccc);
}
}
}
Here is a very simple code to load audio clip by UnityWebRequestMultimedia.GetAudioClip.
The first line “public AudioClip clip” is an AudioClip file attached on the GameObject, and output Logs when Start.
Then, I load a same audio file from StreamingAssetPath, when success, output a log too.
I’m very sure, tow audio files are the same.
Here is the logs, the first audioClip attached on game object is correct.
But the second one, I load from disk, the length and samples are changed.
I wonder WHY? I’m confused for days.
It only shows on 16000 frequency mp3 file, 44100 is ok.