Search Unity

Audio Load Mp3 from PersistentData result in a shorter clip

Discussion in 'Audio & Video' started by GianMarsh, Nov 6, 2018.

  1. GianMarsh

    GianMarsh

    Joined:
    Sep 26, 2018
    Posts:
    2
    Hello everybody, I'm facing a weird problem.

    I put a snippet of my code (the file is correctly saved, in Audacity the length is right)

    Code (CSharp):
    1. // Assigns the loaded audio clip to the source or does nothing if the argument filename or path is inexistent.
    2.  
    3.     public IEnumerator<WWW> Load(string filename )
    4.     {
    5.         string path = Path.Combine(Application.persistentDataPath, filename + ".mp3");
    6.         Debug.Log(path);
    7.         if (File.Exists(path))
    8.             {
    9.             AudioClip clip = new AudioClip();
    10.                 WWW www = new WWW("file://" + path);
    11.             yield return www;
    12.             Debug.Log("Sto caricando il file...");
    13.             clip = www.GetAudioClip();
    14.                 clip.name = filename;
    15.             Debug.Log(clip.length);
    16.             if (onLoadedAudioRecordedDelegate!=null){
    17.                 onLoadedAudioRecordedDelegate(clip);
    18.             }
    19.  
    20.         }
    21.     }
    The clip is returned fine, but the length is not right.
    For example the original file length is about 3.30 seconds, the one that Unity return is about 2.74 seconds. I used UnityWebRequest too but the result is the same.

    There is some way to resolve this bizzare error? Thank you! :)