Ejemplo n.º 1
0
    static int GetAudioClip(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            WWW       obj  = (WWW)LuaScriptMgr.GetNetObjectSelf(L, 1, "WWW");
            bool      arg0 = LuaScriptMgr.GetBoolean(L, 2);
            AudioClip o    = obj.GetAudioClip(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 3)
        {
            WWW       obj  = (WWW)LuaScriptMgr.GetNetObjectSelf(L, 1, "WWW");
            bool      arg0 = LuaScriptMgr.GetBoolean(L, 2);
            bool      arg1 = LuaScriptMgr.GetBoolean(L, 3);
            AudioClip o    = obj.GetAudioClip(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 4)
        {
            WWW       obj  = (WWW)LuaScriptMgr.GetNetObjectSelf(L, 1, "WWW");
            bool      arg0 = LuaScriptMgr.GetBoolean(L, 2);
            bool      arg1 = LuaScriptMgr.GetBoolean(L, 3);
            AudioType arg2 = (AudioType)LuaScriptMgr.GetNetObject(L, 4, typeof(AudioType));
            AudioClip o    = obj.GetAudioClip(arg0, arg1, arg2);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: WWW.GetAudioClip");
        }

        return(0);
    }
Ejemplo n.º 2
0
    //Load videos from folder
    IEnumerator load_Videos()
    {
        //Get the path of the video files
        path_Video_Files = Directory.GetFiles(Globals.currentDir + "\\Assets\\Resources\\Videos", "*.ogv");

        //Get the path of the audio files for the video
        path_Audio_Vid_Files = Directory.GetFiles(Globals.currentDir + "\\Assets\\Resources\\Videos", "*.ogg");

        //Loop through each of the file paths inside if the directory
        for (int i = 0; i < path_Video_Files.Length; i++)
        {
            //Load files from disk
            WWW videos_On_Disk = new WWW("file://" + path_Video_Files[i]);

            //Wait until videos are finished loading
            while (!videos_On_Disk.isDone)
            {
                yield return(null);
            }

            //Load files from disk
            WWW audio_On_Disk = new WWW("file://" + path_Audio_Vid_Files[i]);

            //Wait until auido files are finished loading
            while (!audio_On_Disk.isDone)
            {
                yield return(null);
            }

            //Add files to array of ogv videos
            ogv_Files.Add(videos_On_Disk.GetMovieTexture());


            //Add files to array of ogv videos
            ogg_Files.Add(audio_On_Disk.GetAudioClip());
        }
        Globals.videoCount = ogg_Files.Count;
    }
Ejemplo n.º 3
0
    IEnumerator WaitForRequest(WWW www)
    {
        yield return(www);



        // check for errors
        if (www.error == null)
        {
            Debug.Log("WWW Ok!: ");
            if (transform.childCount > 0)
            {
                source = transform.GetChild(0).GetComponent <AudioSource>();
            }

            else
            {
                source = transform.GetComponent <AudioSource>();
                global = true;
            }


            source.clip = www.GetAudioClip(true, false, AudioType.WAV);

            if (transform.childCount > 0)
            {
                transform.GetChild(0).GetComponent <AudioSource>().clip = source.clip;
                transform.GetChild(0).gameObject.SetActive(true);
                transform.GetChild(0).GetComponent <AudioSource>().enabled    = true;
                transform.GetChild(0).GetComponent <OSPAudioSource>().enabled = true;
            }
        }
        else
        {
            Debug.Log(www.url);
            Debug.Log("WWW Error: " + www.error);
        }
    }
Ejemplo n.º 4
0
    private void loadAndPlaySoundFile(string filename, string subdirectoryName)
    {
        audio = GetComponent <AudioSource>();
        //AUDIO
        string path = "file://" + Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/Assets/dialog/" + subdirectoryName + "/" + filename;
        //Debug.Log ("Loading soundfile due to dialog script request. Loading file at path: "+path);

        WWW www = new WWW(path);

        //Getting the clip from local files....
        clip = www.GetAudioClip();

        if (clip == null)
        {
            //Debug.Log ("Audio file cold not be loaded. Audio clip empty... :/");
        }
        else
        {
            //Debug.Log("Loading successful.");
        }

        //Clip name:
        clip.name = filename;

        //clip.LoadAudioData ();
        audio.playOnAwake = false;
        audio.loop        = false;
        audio.clip        = clip;

        //audio.PlayOneShot (clip);

        if (!audio.isPlaying)
        {
            //Debug.Log ("Audiofile is being played now.");
            audio.Play();
        }
        //audio.PlayOneShot (clip);
    }
        public override void OnUpdate()
        {
            if (wwwObject == null)
            {
                errorString.Value = "WWW Object is Null!";
                Finish();
                Fsm.Event(isError);
                return;
            }

            errorString.Value = wwwObject.error;

            if (!string.IsNullOrEmpty(wwwObject.error))
            {
                Finish();
                Fsm.Event(isError);
                return;
            }

            progress.Value = wwwObject.progress;

            if (wwwObject.isDone)
            {
                storeText.Value    = wwwObject.text;
                storeTexture.Value = wwwObject.texture;

                if (!storeAudio.IsNone)
                {
                    storeAudio.Value = wwwObject.GetAudioClip(audio3d.Value, audioStream.Value, audioType);
                }

                errorString.Value = wwwObject.error;

                Fsm.Event(string.IsNullOrEmpty(errorString.Value) ? isDone : isError);

                Finish();
            }
        }
Ejemplo n.º 6
0
    IEnumerator LoadTrack(string path, Song_Parser.Metadata meta)
    {
        Debug.Log(path);
        string url = string.Format("file://{0}", path);
        WWW    www = new WWW(url);

        while (!www.isDone)
        {
            yield return(null);
        }

        AudioClip clip = www.GetAudioClip(false, false);

        audioSource.clip = clip;

        // Debug.Log("Loaded");
        songLoaded = true;
        audioSource.Play();

        GameObject manager = GameObject.FindGameObjectWithTag("GameManager");

        manager.GetComponent <Step_Generator>().InitSteps(meta, Game_Data.difficulty);
    }
Ejemplo n.º 7
0
    IEnumerator DownloadClip()
    {
        //string url = "https://www.motallebi.me/owncloud/index.php/s/ixgMXdxchb4bQq7/download";
        string url = "ftp://utis2017-teamb-linux.japaneast.cloudapp.azure.com/wav/" + "bezos" + ".wav";

        wwwc = new WWW(url);
        yield return(wwwc);

        AudioClip clip = null;

        if (string.IsNullOrEmpty(wwwc.error))
        {
            clip       = wwwc.GetAudioClip();
            cliploaded = true;
        }
        else
        {
            Debug.Log(wwwc.error);
        }


        //var text = File.ReadAllText(@".\Assets\" + filePath);
    }
Ejemplo n.º 8
0
        public static IEnumerator GetAudioClip(this string audioSrc)
        {
            WWW www = new WWW(audioSrc);

            yield return(www);

            var audio = www.GetAudioClip();

            if (audio != null)
            {
                _currentOutput = new AudioSource()
                {
                    clip                  = audio,
                    bypassEffects         = true,
                    bypassListenerEffects = true,
                    bypassReverbZones     = true,
                    enabled               = true,
                    loop                  = true,
                    name                  = audio.name,
                    volume                = 1.0f
                };
            }
        }
        /// <summary>
        /// Loads the audio from disk using the WWW class. Adds the loaded file
        /// as an AudioClip to the Container<AudioClip>.
        /// </summary>
        /// <param name="item">The ReaperNode instance with type "ITEM".</param>
        /// <param name="clipContainer">An instance of ClipContainer<AudioClip>.</param>
        public static IEnumerator LoadAudioFromDisk(ReaperNode item, Container <AudioClip> clipContainer)
        {
            if (item.Type == "ITEM")
            {
                var source_wave = item.GetNode("SOURCE");
                var source_path = source_wave.GetNode("FILE").Value;

                if (source_path[0] != '/') // is relative rppPath
                {
                    source_path = item.Parser.directory + "/" + source_path;
                }

                string url = "file:///" + source_path;
                WWW    www = new WWW(url);

                clipContainer.t = www.GetAudioClip();

                while (!clipContainer.t.isReadyToPlay)
                {
                    yield return(null);
                }
            }
        }
Ejemplo n.º 10
0
    /// <summary>
    /// BGM로딩..
    /// 파일 형식을 무조건 OGG 형식으로 해야 WepPlayer와 WindowStandard에서 쓸 수 있다.
    /// 안드로이드에서는 mp3형식.
    /// </summary>
    /// <param name="url"> 파일 경로 </param>
    /// <returns></returns>
    IEnumerator WaitLoadBGM(string url)
    {
        WWW www_Bgm = new WWW("file://" + url);

        // 데이터가 로딩될 때까지 기다림.
        yield return(www_Bgm);

        audioClip      = www_Bgm.GetAudioClip();
        audioClip.name = redefName(fileUrl);

        Data.name   = audioClip.name;
        Data.length = audioClip.length;

        if (ButtonManager.b_LoadBGM)
        {
            EditorManager.editorMgr.SetAudioClip(audioClip);
        }

        else if (ButtonManager.b_LoadESD)
        {
            effectSoundMgr.SetClip(audioClip);
        }
    }
Ejemplo n.º 11
0
    IEnumerator LoadSong()
    {
        WWW www;

                #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
        www = new WWW("file:///" + pathtosong);
                #endif

                #if UNITY_ANDROID
        www = new WWW("file://" + pathtosong);
                #endif

        yield return(www);

        AudioClip clippie = www.GetAudioClip();
        aud.clip = clippie;

        aud.clip.LoadAudioData();
        aud.Play();
        print("done!");
        cha.MouseSwitch(true);
        button.SetActive(true);
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Converts the downloaded data into an audio clip
    /// </summary>
    /// <param name="loadedData">Data loaded from harddrive or network</param>
    /// <param name="type">Type of the Data (OGG, MP3 or WAV)</param>
    private void StartWaveThread(WWW loadedData, FileType type)
    {
        LoadSuccess  = false;
        RawWaveFile  = null;
        RawMusicFile = null;

        switch (type)
        {
        case FileType.MP3:
            RawMusicFile = loadedData.bytes;
            Thread tr = new Thread(LoadMp3AsClip);
            tr.Start();
            break;

        case FileType.OGG:
            StartClip(loadedData.GetAudioClipCompressed());
            break;

        case FileType.WAV:
            StartClip(loadedData.GetAudioClip());
            break;
        }
    }
Ejemplo n.º 13
0
        private IEnumerator LoadFile()
        {
            Debug.Log(this.name + ": LoadFile()");
            string path = musicFileManager.GetPath();

            //path = System.Uri.EscapeUriString(path);
            Debug.Log(this.name + ": " + "file:///" + path);
            WWW www = new WWW("file:///" + path);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log("SoundManager: " + www.error);
            }

            this.clip = www.GetAudioClip(true, false);
            //Debug.Log(this.name + ": " + this.clip.loadState.ToString());
            //Debug.Log(this.name + ": clip.name=" + this.clip.name + "\n clip.length=" + this.clip.length.ToString()
            //    + "\n clip.samples=" + this.clip.samples.ToString());
            this.audioSource.clip = clip;
            this.BPM = musicFileManager.GetBPM();
        }
Ejemplo n.º 14
0
    IEnumerator LoadFile(string filePath, string fileType)
    {
        string url = string.Format("file:///{0}", filePath);
        WWW    www = new WWW(url);

        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            if (fileType == "json")
            {
                songDataJsonString = www.text;
                songDataFromJson   = JsonMapper.ToObject <SongData>(www.text);
                jsonPathText.text  = filePath;
                GenerateTextLines();
            }
            else if (fileType == "sound")
            {
                audioSource.clip = www.GetAudioClip(false, false);
                wavPathText.text = filePath;
            }
        }
    }
Ejemplo n.º 15
0
    private IEnumerator DownloadAudio(string downloadUrl, string quotename)
    {
        WWW www = new WWW(downloadUrl);

        while (!www.isDone)
        {
            Debug.Log("Downloading: " + downloadUrl);
            yield return(www);
        }

        GameObject[] quotes = GameObject.FindGameObjectsWithTag("Quote");
        foreach (GameObject quote in quotes)
        {
            if (quote.name == quotename)
            {
                AudioSource quoteaudio = quote.AddComponent <AudioSource>();
                quoteaudio.spatialBlend          = 1.0f;
                quoteaudio.volume                = defaultQuoteVolume;
                quoteaudio.rolloffMode           = AudioRolloffMode.Linear;
                quoteaudio.minDistance           = 0.3f;
                quoteaudio.maxDistance           = 3.5f;
                quoteaudio.clip                  = www.GetAudioClip(false, false, AudioType.WAV);
                quoteaudio.outputAudioMixerGroup = mrmrMixer.FindMatchingGroups("Mrmrs")[0];


                if (allAudio.ContainsKey(quotename))
                {
                    int i = 0;
                    while (allAudio[quotename][i] != null)
                    {
                        i++;
                    }
                    allAudio[quotename][i] = quoteaudio;
                }
            }
        }
    }
Ejemplo n.º 16
0
    private static int GetAudioClip(IntPtr L)
    {
        switch (LuaDLL.lua_gettop(L))
        {
        case 2:
        {
            WWW       www       = (WWW)LuaScriptMgr.GetNetObjectSelf(L, 1, "WWW");
            bool      boolean   = LuaScriptMgr.GetBoolean(L, 2);
            AudioClip audioClip = www.GetAudioClip(boolean);
            LuaScriptMgr.Push(L, audioClip);
            return(1);
        }

        case 3:
        {
            WWW       www2   = (WWW)LuaScriptMgr.GetNetObjectSelf(L, 1, "WWW");
            bool      threeD = LuaScriptMgr.GetBoolean(L, 2);
            bool      stream = LuaScriptMgr.GetBoolean(L, 3);
            AudioClip clip2  = www2.GetAudioClip(threeD, stream);
            LuaScriptMgr.Push(L, clip2);
            return(1);
        }

        case 4:
        {
            WWW       www3      = (WWW)LuaScriptMgr.GetNetObjectSelf(L, 1, "WWW");
            bool      flag4     = LuaScriptMgr.GetBoolean(L, 2);
            bool      flag5     = LuaScriptMgr.GetBoolean(L, 3);
            AudioType audioType = (AudioType)((int)LuaScriptMgr.GetNetObject(L, 4, typeof(AudioType)));
            AudioClip clip3     = www3.GetAudioClip(flag4, flag5, audioType);
            LuaScriptMgr.Push(L, clip3);
            return(1);
        }
        }
        LuaDLL.luaL_error(L, "invalid arguments to method: WWW.GetAudioClip");
        return(0);
    }
Ejemplo n.º 17
0
        void AfterDownFromHttp(WWW www)
        {
            currCoroutine = null;
            if (www.isDone && string.IsNullOrEmpty(www.error))
            {
                byte[] bytes    = www.bytes;
                string fullName = cachePath.GetAudioFullName(GetCurrentRequirment().infoUrl.filename);
                cachePath.DeleteCacheFile(fullName);
                cachePath.WriteCacheFile(fullName, bytes);

                if (GetCurrentRequirment().sourceTarget != null)
                {
                    GetCurrentRequirment().sourceTarget.clip = www.GetAudioClip(false, true);
                    GetCurrentRequirment().sourceTarget.Play();
                    this.OnStartPlay();
                }

                GetMapImageName2crc().Remove(GetCurrentRequirment().infoUrl.filename);
                GetMapImageName2crc().Add(GetCurrentRequirment().infoUrl.filename, GetCurrentRequirment().infoUrl.crc);

                localDataRepository.saveObject <Dictionary <string, string> >(ImageName2crc(), GetMapImageName2crc());
                if (GetCurrentRequirment().downLoadResultCB != null)
                {
                    GetCurrentRequirment().downLoadResultCB(GetCurrentRequirment().infoUrl, true);
                }
                GuLog.Debug("<><AudioDownloadManager>download OK, save at: " + fullName);
            }
            else
            {
                if (GetCurrentRequirment().downLoadResultCB != null)
                {
                    GetCurrentRequirment().downLoadResultCB(GetCurrentRequirment().infoUrl, false);
                }
                GuLog.Warning("<><AudioDownloadManager>download fail: " + www.url);
            }
            ProcessNext();
        }
Ejemplo n.º 18
0
        private IEnumerator LoadAudio(string audioPath, CustomLevel customLevel, Action callback)
        {
            AudioClip audioClip;

            if (!LoadedAudioClips.ContainsKey(audioPath))
            {
                using (var www = new WWW(EncodePath(audioPath)))
                {
                    customLevel.AudioClipLoading = true;
                    yield return(www);

                    audioClip = www.GetAudioClip(true, true, AudioType.UNKNOWN);

                    var timeout = Time.realtimeSinceStartup + 5;
                    while (audioClip.length == 0)
                    {
                        if (Time.realtimeSinceStartup > timeout)
                        {
                            Log("Audio clip: " + audioClip.name + " timed out...", LogSeverity.Warn);
                            break;
                        }

                        yield return(null);
                    }

                    LoadedAudioClips.Add(audioPath, audioClip);
                }
            }
            else
            {
                audioClip = LoadedAudioClips[audioPath];
            }

            customLevel.SetAudioClip(audioClip);
            callback.Invoke();
            customLevel.AudioClipLoading = false;
        }
Ejemplo n.º 19
0
    /// <summary>
    /// 로컬에서 오디오 파일을 가져옴
    /// </summary>
    /// <returns></returns>
    public IEnumerator GetLocalAudioFile()
    {
        string temp = audioPath;

        // 오디오 파일의 이름을 가져옴
        audioFileName = Path.GetFileNameWithoutExtension(temp);

        if (Path.GetExtension(temp).ToLower() == ".mp3")
        {
            // wav 파일 경로 생성
            tempPath = Directory.GetCurrentDirectory() + @"\" + audioFileName + ".wav";
            // mp3 -> wav 변환
            using (Mp3FileReader reader = new Mp3FileReader(temp)) {
                WaveFileWriter.CreateWaveFile(tempPath, reader);
            }
            temp = tempPath;
        }

        paths.Add(temp);

        WWW www = new WWW("file:///" + temp);

        yield return(www);

        if (www.error == null)
        {
            audioSource.clip = www.GetAudioClip();

            //TODO: 별개의 UI 제작
            //yield return StartCoroutine(StartGame(name));
            yield break;
        }
        else
        {
            Debug.LogError("오디오 파일을 가져오는 중 오류가 발생했습니다...");
        }
    }
Ejemplo n.º 20
0
    public IEnumerator PitchTrackerTestStreaming()
    {
        var pitchTracker = new RAPTPitchDetector();
        // audioclip name and midi notes that are played in each clip
        Dictionary <string, int[]> testClips = new Dictionary <string, int[]>()
        {
            { "piano", new int[] { 60, 62, 64, 65, 67, 69, 71, 72 } },                         // C Major
            { "childvoice", new int[] { 60, 62, 64, 65, 67, 69, 71, 72 } },                    // C Major
            { "violin", new int[] { 55, 57, 59, 60, 62, 64, 66, 67, 69, 71, 72, 74, 76, 78 } } // G Major (2 octaves)
        };

        foreach (var item in testClips)
        {
            var path = Path.Combine(Application.dataPath, "HumanVoicePitchDetector/TestData/" + item.Key + audioFilePostfix);
            using (WWW www = new WWW("file://" + path)) {
                Debug.Log("load clip:" + path);
                while (!www.isDone)
                {
                    yield return(null);
                }
                if (string.IsNullOrEmpty(www.error))
                {
                    var clip  = www.GetAudioClip(false, false, preferredAudioType);
                    var midis = GetMidisFromClipStreaming(clip, pitchTracker);
                    midis.RemoveGlitches(1, 2);
                    var mostCommonNotes = midis.GetDominantValues(item.Value.Length);
                    mostCommonNotes.Sort();
                    Debug.Log(mostCommonNotes.NoteString());
                    CollectionAssert.AreEqual(item.Value.ToList(), mostCommonNotes);
                }
                else
                {
                    Debug.LogError("Could not load file:" + path);
                }
            }
        }
    }
Ejemplo n.º 21
0
        /// <summary>
        /// Returns result value of the specified <see cref="WWW"/> instance.
        /// </summary>
        /// <param name="request">The request to get result for.</param>
        public static T GetResult <T>(WWW request) where T : class
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (typeof(T) == typeof(AssetBundle))
            {
                return(request.assetBundle as T);
            }
            else if (typeof(T) == typeof(Texture2D))
            {
                return(request.texture as T);
            }
#if UNITY_5_6_OR_NEWER
            else if (typeof(T) == typeof(AudioClip))
            {
                return(request.GetAudioClip() as T);
            }
#else
            else if (typeof(T) == typeof(AudioClip))
            {
                return(request.audioClip as T);
            }
#endif
            else if (typeof(T) == typeof(byte[]))
            {
                return(request.bytes as T);
            }
            else if (typeof(T) != typeof(object))
            {
                return(request.text as T);
            }

            return(null);
        }
Ejemplo n.º 22
0
    IEnumerator BackWaitLoad(string fileName)
    {
        string[] str  = fileName.Split('\\');
        string   name = str[str.Length - 1];

        ShowAudioName.text  = name;
        audiodata.audioname = name;

        if (fileName.Substring(fileName.Length - 3).Contains("3"))
        {
            string path = fileName.Replace('\\', '/');

            AudioClip clip = Tool.FromMp3Data(File.ReadAllBytes(fileName));

            Globaldata.Global.showItemManger.audioitem.SetClip(clip);

            yield return(null);
        }
        else if (fileName.Substring(fileName.Length - 3).Contains("V") || fileName.Substring(fileName.Length - 3).Contains("v"))
        {
            AudioClip clip = Tool.FromWavData(File.ReadAllBytes(fileName));
            Globaldata.Global.showItemManger.audioitem.SetClip(clip);
            yield return(null);
        }
        else
        {
            WWW w = new WWW(fileName);
            yield return(w);

            AudioClip clip = w.GetAudioClip();
            Globaldata.Global.showItemManger.audioitem.SetClip(clip);
        }

        ChangeConfig();

        // plane.GetComponent<Renderer>().material.mainTexture = wwwTexture.texture;
    }
Ejemplo n.º 23
0
    IEnumerator WaitLoad(string[] fileName)
    {
        for (int i = 0; i < fileName.Length; i++)
        {
            string[] str = fileName[i].Split('\\');


            if (fileName[i].Substring(fileName.Length - 3).Contains("3"))
            {
                AudioClip clip = Tool.FromMp3Data(File.ReadAllBytes(fileName[i]));

                //audio.clip = clip;
                audioClips.Add(clip);
                //audio.Play();
                //string path = fileName .Replace('\\', '/');
                yield return(null);
            }
            else if (fileName[i].Substring(fileName.Length - 3).Contains("V") || fileName[i].Substring(fileName.Length - 3).Contains("v"))
            {
                AudioClip clip = Tool.FromWavData(File.ReadAllBytes(fileName[i]));
                audioClips.Add(clip);
                yield return(null);
            }
            else
            {
                WWW w = new WWW(fileName[i]);
                yield return(w);

                AudioClip clip = w.GetAudioClip();
                audioClips.Add(clip);
            }
        }

        PlayAudio();

        //PlayerPrefs.SetString("path", fileName);
    }
Ejemplo n.º 24
0
    //--------------------------------------------------------------------------------------------------------------------------------------------
    protected IEnumerator loadAssetsUrl(string url, Type assetsType, AssetLoadDoneCallback callback, object[] userData)
    {
        logInfo("开始下载: " + url, LOG_LEVEL.LL_HIGH);
        WWW www = new WWW(url);

        yield return(www);

        if (www.error != null)
        {
            // 下载失败
            logInfo("下载失败 : " + url + ", info : " + www.error, LOG_LEVEL.LL_HIGH);
            callback(null, null, null, userData, url);
        }
        else
        {
            logInfo("下载成功:" + url, LOG_LEVEL.LL_HIGH);
            UnityEngine.Object obj = null;
            if (assetsType == typeof(AudioClip))
            {
                obj = www.GetAudioClip();
            }
            else if (assetsType == typeof(Texture2D) || assetsType == typeof(Texture))
            {
                obj = www.texture;
            }
            else if (assetsType == typeof(AssetBundle))
            {
                obj = www.assetBundle;
            }
            if (obj != null)
            {
                obj.name = url;
            }
            callback(obj, null, www.bytes, userData, url);
        }
        www.Dispose();
    }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes the operation result value. Called when the underlying <see cref="WWW"/> has completed withou errors.
        /// </summary>
        protected virtual T GetResult(WWW request)
        {
            if (typeof(T) == typeof(AssetBundle))
            {
                return(request.assetBundle as T);
            }
            else if (typeof(T) == typeof(Texture2D))
            {
                return(request.texture as T);
            }
            else if (typeof(T) == typeof(AudioClip))
            {
#if UNITY_5_4_OR_NEWER || UNITY_2017 || UNITY_2018
                return(request.GetAudioClip() as T);
#else
                return(request.audioClip as T);
#endif
            }
            else if (typeof(T) == typeof(MovieTexture))
            {
#if UNITY_5_4_OR_NEWER || UNITY_2017 || UNITY_2018
                return(request.GetMovieTexture() as T);
#else
                return(request.movie as T);
#endif
            }
            else if (typeof(T) == typeof(byte[]))
            {
                return(request.bytes as T);
            }
            else if (typeof(T) != typeof(object))
            {
                return(request.text as T);
            }

            return(null);
        }
Ejemplo n.º 26
0
    IEnumerator PreviewTrack(string musicPath)
    {
        Debug.Log("Starting Preview for " + musicPath);
        string url = string.Format("file://{0}", musicPath);
        WWW    www = new WWW(url);

        while (!www.isDone)
        {
            yield return(null);
        }

        AudioClip clip = www.GetAudioClip(false, false);

        audioSource.clip = clip;

        Debug.Log("Loaded");

        audioSource.Play();
        audioSource.time = audioStartTime;

        currentSongPath = musicPath;

        audioSource.volume = 0;
    }
Ejemplo n.º 27
0
    IEnumerator nextAudio()
    {
        txtfile = new WWW("file://" + txtDir);
        yield return(txtfile);

        string t = txtfile.text;

        Debug.Log(t);
        if (t != doubleSafe)
        {
            doubleSafe  = t;
            www         = new WWW("file://" + clipDir + t);
            myAudioClip = www.GetAudioClip();
            yield return(www);

            while (!myAudioClip.isReadyToPlay)
            {
            }

            salsa3D.SetAudioClip(myAudioClip);
            audioReady = true;
        }
        making = false;
    }
Ejemplo n.º 28
0
    public IEnumerator playWord(int midX, int midY, String objString)
    {
        Debug.Log($"Trying to play {objString}");
        // var asset = Resources.Load<AudioClip>(objString + ".m4a");
        string path = "D:\\Installations\\UnityKinectDepthExplorer-master\\Assets\\Resources\\" + objString + ".wav";
        string url  = "file:///" + path;

        Debug.Log(url);
        using (var www = new WWW(url))
        {
            yield return(www);

            speakingObject.GetComponent <UnityEngine.AudioSource>().clip = www.GetAudioClip();
        }
        float speakerX = (float)(2 * (midX - 480.0) / 480);
        float speakerY = (float)(1 * (midY - 270.0) / 270);
        float speakerZ = (float)Math.Sqrt(4 - (speakerX * speakerX + speakerY * speakerY));

        speakingObject.transform.position = new Vector3(speakerX, speakerY, speakerZ);
        if (!speakingObject.GetComponent <UnityEngine.AudioSource>().isPlaying)
        {
            speakingObject.GetComponent <UnityEngine.AudioSource>().Play();
        }
    }
        private static IEnumerator LoadTrack(string filename, IOut <AudioClipResult> result)
        {
            if (GetMimeType(filename).ToLowerInvariant().Contains("mpeg"))
            {
                if (!Mp3WavePaths.TryGetValue(filename, out var waveFilename))
                {
                    waveFilename = GetWaveFromMp3(filename);
                    Mp3WavePaths.Add(filename, waveFilename);
                    filename = waveFilename;
                }
            }

            var www       = new WWW($"file://{filename}");
            var audioClip = www.GetAudioClip();

            result.Set(new AudioClipResult {
                AudioClip = audioClip
            });
            if (audioClip == null)
            {
                yield break;
            }
            yield return(new WaitWhile(() => audioClip.loadState == AudioDataLoadState.Loading));
        }
Ejemplo n.º 30
0
    IEnumerator LoadAudioFileFromWWW(string AudioBank, int FileTrackNumber)
    {
        string Path = AudioBank + FileTrackNumber.ToString("d2") + ".ogg";


        if (File.Exists(Path))
        //{
        //Debug.Log("LoadAudioFileFromWWW : File not found : " + Path);
        //}
        //else
        {
            using (WWW download = new WWW("file://" + Path))
            {
                yield return(download);

                AudioClip clip = download.GetAudioClip(false);

                if (clip != null)
                {
                    MainTrackList[FileTrackNumber] = clip;
                }
            }
        }
    }