Example #1
0
        private static IEnumerator loadSoundFileClip(SoundFile sf, System.Action <SoundFile> completion = null)
        {
            if (sf.isDefaultSoundFile || (sf.loadState == LoadState.Success && sf.clip != null))
            {
                // ALREADY LOADED!
                if (completion != null)
                {
                    completion(sf);
                }
                yield break;
            }

            sf.loadState = LoadState.Loading;
            // Get and bind the assoc soundfile
            string url = "file://" + sf.soundFilepath; // System.Text.Encoding.UTF8

            using (UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(url,
                                                                                MP3_otherwise_WAV ? AudioType.MPEG : AudioType.WAV)) {
                DownloadHandlerAudioClip dHandler = req.downloadHandler as DownloadHandlerAudioClip;
                // dHandler.streamAudio = true;
                dHandler.compressed = true;

                yield return(req.SendWebRequest());

                // if (dHandler.isDone) {
                //     Debug.Log("Get Audio clip IS DONE");
                // } else {
                //     Debug.Log("Get Audio clip is NOT done");
                // }
                if (req.error != null)
                {
                    Debug.Log(req.error + " for: " + url);
                    sf.loadState = LoadState.Fail;
                }
                else
                {
                    AudioClip ac = DownloadHandlerAudioClip.GetContent(req);
                    if (ac != null)
                    {
                        // Debug.Log("AudioClip loadState: " + ac.loadState + " - " + sf.filename);

                        if (sf.clip != null)
                        {
                            GameObject.Destroy(sf.clip);
                        }
                        sf.clip = ac;

                        sf.loadState = LoadState.Success;
                        sf.duration  = Mathf.RoundToInt(ac.length);
                        sf.Save();
                    }
                }
            }
            // Debug.LogWarning("SoundFile::loadSoundFileClip WILL call completion...");
            if (completion != null)
            {
                completion(sf);
            }
        }
Example #2
0
        public static void CreateNewMetas()
        {
            // Get list of soundFiles listed in metafiles
            List <string> foundFilenamesWithData = new List <string>();

            foreach (string filename in SoundFile.metaFiles)
            {
                foundFilenamesWithData.Add(ReadFromMeta(filename).soundFilepath);
            }
            // look for wavs without metas and create them
            foreach (string filename in SoundFile.soundFilenames)
            {
                if (!foundFilenamesWithData.Contains(filename))
                {
                    SoundFile sf = new SoundFile(filename);
                    sf.Save();
                }
            }
        }