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

(WEB_GL) streaming of "ogg" is not supported .... -- both Firefox and Chrome

Discussion in 'Web' started by mave92, Jul 26, 2017.

  1. mave92

    mave92

    Joined:
    Jun 28, 2015
    Posts:
    12
    Hi guys! I'm trying to load audio at runtime in WEBGL with UNITY PRO 5.6 but I'm losing my head trying to solve this error but it just won't work.
    error: streaming of "ogg" is not supported on this platform

    This is what the script does:
    1- Takes a URL pointing to a file (WWW)
    2- Waits until the file is downloaded
    3- Makes audioclip from dowloaded data (GetAudioClip (false, false, AudioType.OGGVORBIS)
    4- Plays Audio (THIS IS WHERE IT FAILS!)

    Everything is fine in Editor.
    I tried every possible export combination and file format but nothing seems to work in browser.

    PLEASE HELP!
     
  2. mave92

    mave92

    Joined:
    Jun 28, 2015
    Posts:
    12
    Bump*
    Does anyone have any idea?
     
  3. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    TRY:
    Code (CSharp):
    1. AudioClip ac = data.GetAudioClipCompressed(false, AudioType.AUDIOQUEUE) as AudioClip;

    I tried this once, and it was working. only tested until unity 5.5
    pearhaps this helps:

    use it like this:
    Code (CSharp):
    1. StartCoroutine(ReadWriteLocalFiles.ReadSound("", "", (returnClip) => { if(returnClip != null) { gameObject.GetComponent<AudioSource> ().clip = returnClip; } }));
    other functions...
    .jslib
    Code (JavaScript):
    1. var SoundUploaderPlugin = {
    2.   SoundUploader: function() {
    3.     if (!document.getElementById('SoundUploaderInput')) {
    4.       var fileInput = document.createElement('input');
    5.       fileInput.setAttribute('type', 'file');
    6.       fileInput.setAttribute('id', 'SoundUploaderInput');
    7.       fileInput.setAttribute('accept', '.ogg');
    8.       fileInput.style.visibility = 'hidden';
    9.       fileInput.onclick = function (event) {
    10.         this.value = null;
    11.       };
    12.       fileInput.onchange = function (event) {
    13.         SendMessage('SaveLoadScriptHolder', 'SoundFileSelected', URL.createObjectURL(event.target.files[0]));
    14.       }
    15.       document.body.appendChild(fileInput);
    16.     }
    17.     var OpenFileDialog = function() {
    18.       //document.getElementById('SoundUploaderInput').click();
    19.       $("#SoundUploaderInput").click()
    20.       document.getElementById('canvas').removeEventListener('click', OpenFileDialog);
    21.     };
    22.     document.getElementById('canvas').addEventListener('click', OpenFileDialog, false);
    23.     var isFirefox = typeof InstallTrigger !== 'undefined';
    24.     if (isFirefox) {
    25.       $("#canvas").click()
    26.     }
    27.   }
    28. };
    29. mergeInto(LibraryManager.library, SoundUploaderPlugin);
    Called from jslib
    Code (CSharp):
    1. //OGG
    2.     void SoundFileSelected (string url)
    3.     {
    4.         StartCoroutine(ReadWriteLocalFiles.LoadSoundWebGL(url, (returnClip) =>
    5.             {
    6.                 if(returnClip != null) { gameObject.GetComponent<AudioSource> ().clip = returnClip; playButtonWebGL = true; }
    7.                 else { gameObject.GetComponent<AudioSource> ().clip = null; playButtonWebGL = false; }
    8.             }));
    9.     }
    ReadWriteLocalFiles.cs
    Code (CSharp):
    1.  
    2. #if UNITY_WEBGL
    3. using System.Runtime.InteropServices;
    4. #endif
    5. //...
    6. //.....
    7. #if UNITY_WEBGL
    8. [DllImport("__Internal")]
    9. private static extern void SoundUploader();
    10. #endif
    11. //...
    12. //.....
    13. public static IEnumerator ReadSound (string directory, string fileName, System.Action<AudioClip> callback)
    14. {
    15.             #if UNITY_STANDALONE
    16.             string directoryPath = GetDirectoryPath(directory);
    17.             string fullPath = System.IO.Path.Combine(directoryPath, fileName);
    18.             string extension = Path.GetExtension(fullPath);
    19.  
    20.             AudioClip clip = null;
    21.  
    22.             if(extension == ".ogg")
    23.             {
    24.                 if (File.Exists(fullPath))  
    25.                 {
    26.                     WWW www = new WWW("file://"+fullPath);
    27.                     yield return www;
    28.                     try
    29.                     {
    30.                         clip = www.GetAudioClip(false);
    31.                         string[] parts = fullPath.Split('\\');
    32.                         clip.name = parts[parts.Length - 1];
    33.                         callback(clip);
    34.                     }
    35.                     catch(System.Exception e)
    36.                     {
    37.                         Debug.Log("error:"+e.Message);
    38.                         callback(clip);
    39.                     }
    40.                 }
    41.                 else
    42.                 {
    43.                     Debug.Log("file don't exist.");
    44.                     callback(clip);
    45.                 }
    46.             }
    47.             else
    48.             {
    49.                 Debug.Log("invalid extension.");
    50.                 callback(clip);
    51.             }
    52.             #elif UNITY_WEBGL
    53.             SoundUploader();
    54.             return null;
    55.             #else
    56.             Debug.Log("only aviable in webgl and standalone builds.");
    57.             return null;
    58.             #endif
    59. }
    60. public static IEnumerator LoadSoundWebGL (string url, System.Action<AudioClip> callback)
    61. {
    62.             #if UNITY_WEBGL
    63.             WWW data = new WWW (url); yield return data;
    64.             try
    65.             {
    66.                 AudioClip ac = data.GetAudioClipCompressed(false, AudioType.AUDIOQUEUE) as AudioClip;
    67.                 if(ac != null)
    68.                 {
    69.                     ac.name = "mySoundFile.ogg";
    70.                     callback(ac);
    71.                 }
    72.                 else
    73.                 {
    74.                     Debug.Log("no audio found.");
    75.                     callback(ac);
    76.                 }
    77.             }
    78.             catch (System.Exception e)
    79.             {
    80.                 Debug.Log(e);
    81.                 AudioClip ac = null;
    82.                 callback(ac);
    83.             }
    84.             #else
    85.             Debug.Log("only for webgl."); return null;
    86.             #endif
    87. }
     
    Last edited: Aug 4, 2017