Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] How to play 'mp3' audio when using WWW.GetAudioClip (Windows PC)

Discussion in 'Audio & Video' started by AlanMattano, Sep 5, 2016.

  1. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Do Unity handles mp3 file format in windows when uploading loading a file from HD or URL?


    using windows 10 . The code works well when I load .wav extension files.
    The code is similar to this:

    Code (CSharp):
    1. IEnumerator LoadAudio()
    2. {
    3.     string FullPath = BrowserPath;
    4.  
    5.     print(FullPath); // result: D:\files\audio files\ZOOM0001.WAV
    6.  
    7.     FullPath = FullPath.replace('\\', '/');
    8.     FullPath = "file:///" + FullPath ;
    9.  
    10.     print(FullPath); // result: file:///D:/files/audio files/ZOOM0001.WAV
    11.  
    12.     WWW URL = new WWW(FullPath);
    13.     yield return URL;
    14.  
    15.     audioContainer.clip = URL.GetAudioClip(false,false);
    16. }
    This or similar code works fine. But if I change it to "myAudioClip.mp3" it fail.
    I get the error:

    Streaming of 'mp3' on this platform is not supported

    Any idea?
     
    Last edited: Sep 6, 2016
    twobob likes this.
  2. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Last edited: Sep 6, 2016
    twobob likes this.
  3. HelloMeow

    HelloMeow

    Joined:
    May 11, 2014
    Posts:
    280
    No, only on mobile platforms. I suspect it has something to do with mp3 licensing. You will have to use NAudio or something similar.
     
    AlanMattano likes this.
  4. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    ok, looks mp3 license decay in 2017. How Naudio license work?
    This code is working
    Code (CSharp):
    1. IEnumerator LoadAudio()
    2. {
    3.     string FullPath = myBrowserPath;
    4.     print(FullPath); // result: D:\files\audio files\ZOOM0001.WAV
    5.  
    6.     string pathLowercase = FullPath.ToLower();
    7.  
    8.     if (    pathLowercase.Contains(".wav") ||
    9.                 pathLowercase.Contains(".mp3") ||
    10.                 pathLowercase.Contains(".ogg") )
    11.     {
    12.         // it will continu running skipping the else return.
    13.     // Was not posible to do the oposite !pathLowercase.Contains(".wav")
    14.     } else {
    15.         mss("ALERT: This format is not supported or is not an audio file format. Streaming of 'this type' on this platform is not supported" + "\n" + pathLowercase);
    16.         return true;
    17.     }
    18.  
    19.     FullPath = FullPath.Replace('\\', '/');
    20.     FullPath = "file:///" + FullPath ;
    21.     print(FullPath); // result: file:///D:/files/audio files/ZOOM0001.WAV
    22.     WWW URL = new WWW(FullPath);
    23.     yield return URL;
    24.  
    25.     if ( pathLowercase.Contains(".mp3"))
    26.     {
    27.             audioContainer.clip = NAudioPlayer.FromMp3Data(URL.bytes);
    28.     } else {
    29.          audioContainer.clip = URL.GetAudioClip(false,false);
    30.     }
    31. }
    32.  
     
    JorgeQuevedoC and twobob like this.