コード例 #1
0
        private IEnumerator LoadWavClipRoutine(string filepath)
        {
            if (File.Exists(filepath))
            {
                FileInfo fileInfo = new FileInfo(filepath);

                Debug.Log("LoadRecordedClip: fileCreated=" + fileInfo.Exists + " fileLength=" + fileInfo.Length);

                if (fileInfo.Exists)
                {
                    WWW www = null;
                    try
                    {
                        www = new WWW("file://" + filepath);
                    }
                    catch (Exception)
                    {
                        www = null;
                    }
                    if (www != null)
                    {
                        yield return(new WaitUntil(() => www.isDone));

                        if (recordedClip != null)
                        {
                            AudioClip.Destroy(recordedClip);
                        }
                        recordedClip = WWWAudioExtensions.GetAudioClip(www);
                        Debug.Log("LoadRecordedClip: recorded clip: " + recordedClip);
                    }
                }
            }
        }
コード例 #2
0
        public IEnumerator LoadAudioClips()
        {
            for (int i = 0; i < SL.Instance.FilePaths[ResourceTypes.Audio].Count(); i++)
            {
                string filePath = @"file://" + Path.GetFullPath(SL.Instance.FilePaths[ResourceTypes.Audio][i]);
                string fileName = Path.GetFileNameWithoutExtension(filePath);

                AudioClip clip = WWWAudioExtensions.GetAudioClip(new WWW(filePath));
                DontDestroyOnLoad(clip);

                if (clip != null)
                {
                    while (clip.loadState != AudioDataLoadState.Loaded)
                    {
                        yield return(new WaitForSeconds(0.1f));
                    }

                    if (SL.Instance.AudioClips.ContainsKey(fileName))
                    {
                        SL.Instance.AudioClips[fileName] = clip;
                    }
                    else
                    {
                        SL.Instance.AudioClips.Add(fileName, clip);
                    }
                }
            }

            SL.Instance.Loading = false;
            yield return(null);
        }
コード例 #3
0
    IEnumerator Load(string url, List <AudioClip> list)
    {
        WWW www = new WWW(url);

        yield return(www);

        list.Add(WWWAudioExtensions.GetAudioClip(www));
    }
コード例 #4
0
ファイル: HttpLoadOperation.cs プロジェクト: xubingyue/hugula
        private void FinishDownload()
        {
            if (m_webrequest == null)
            {
                error = string.Format("webrequest is null , {0} ", cRequest.key);
                Debug.LogErrorFormat("url:{0},erro:{1}", cRequest.url, error);
                return;
            }

            error = m_webrequest.error;

            if (!string.IsNullOrEmpty(error))
            {
                Debug.LogErrorFormat("url:{0},erro:{1}", cRequest.url, error);
                return;
            }

            var type = cRequest.assetType;

            if (LoaderType.Typeof_AudioClip.Equals(type))
            {
#if UNITY_2017
                m_Data = WWWAudioExtensions.GetAudioClip(m_webrequest);
#else
                m_Data = m_webrequest.GetAudioClip(false);
#endif
            }
            else if (LoaderType.Typeof_Texture2D.Equals(type))
            {
                if (!string.IsNullOrEmpty(cRequest.assetName) && cRequest.assetName.Equals("textureNonReadable"))
                {
                    m_Data = m_webrequest.textureNonReadable;
                }
                else
                {
                    m_Data = m_webrequest.texture;
                }
            }
            else if (LoaderType.Typeof_AssetBundle.Equals(type))
            {
                m_Data = m_webrequest.assetBundle;
            }
            else if (LoaderType.Typeof_Bytes.Equals(type))
            {
                m_Data = m_webrequest.bytes;
            }
            else
            {
                m_Data = m_webrequest.text;
            }

            // UriGroup.CheckWWWComplete (cRequest, m_webrequest);

            cRequest.data = m_Data;
            m_webrequest.Dispose();
            m_webrequest = null;
        }
コード例 #5
0
    public IEnumerator LoadAudio(FileInfo fileInfo)
    {
        //文件绝对路径
        string filepath = fileInfo.FullName;
        //文件拓展名
        string extension = fileInfo.Extension;
        //文件转换格式后的保存路径
        string savepath = "";

        _ImgLoading.gameObject.SetActive(true);
        name = fileInfo.Name.Replace(fileInfo.Extension, string.Empty);
        //指定Mp3ToWAV的保存路径
        if (fileInfo.Extension == ".mp3")
        {
            savepath = _saveFolder + name + ".wav";
        }

        //MP3
        if (extension == ".mp3")
        {
            FileStream    stream = File.Open(filepath, FileMode.Open);
            Mp3FileReader reader = new Mp3FileReader(stream);
            //如果不存在缓存文件夹,则创建
            if (!Directory.Exists(_saveFolder))
            {
                Directory.CreateDirectory(_saveFolder);
            }
            //如果不存在缓存音频,则写入到指定目录
            //否则不再重复写入
            if (!Directory.Exists(savepath))
            {
                FileInfo file = new FileInfo(savepath);
                AudioManager.fileNameList[AudioManager.currentNum] = file;
                WaveFileWriter.CreateWaveFile(savepath, reader);
            }
            www = new WWW("file://" + savepath);
        }
        //WAV | OGG
        if (extension == ".wav" || extension == ".ogg")
        {
            www = new WWW("file://" + filepath);
        }
        yield return(www);

        //将指定路径的AudioClip赋予给AudioSource
        AudioClip clip = WWWAudioExtensions.GetAudioClip(www);

        AudioManager._audioSource.clip = clip;
        //加载完成,Loading图片不再显示
        _ImgLoading.gameObject.SetActive(false);

        AudioManager._audioIsLoadDone = true;
    }
コード例 #6
0
        void m_Done()
        {
            if (m_webrequest == null || !string.IsNullOrEmpty(m_webrequest.error))
            {
                error          = string.Format("url:{0},erro:{1}", cRequest.url, m_webrequest == null?"m_webrequest is null":m_webrequest.error);
                cRequest.error = error;
                Debug.LogError(error);
            }
            else
            {
                object m_Data = null;
                var    type   = cRequest.assetType;

                if (LoaderType.Typeof_AudioClip.Equals(type))
                {
#if UNITY_2017
                    m_Data = WWWAudioExtensions.GetAudioClip(m_webrequest);
#elif UNITY_5_5_OR_NEWER
                    m_Data = m_webrequest.GetAudioClip();
#endif
                }
                else if (LoaderType.Typeof_Texture2D.Equals(type))
                {
                    if (!string.IsNullOrEmpty(cRequest.assetName) && cRequest.assetName.Equals("textureNonReadable"))
                    {
                        m_Data = m_webrequest.textureNonReadable;
                    }
                    else
                    {
                        m_Data = m_webrequest.texture;
                    }
                }
                else if (LoaderType.Typeof_AssetBundle.Equals(type))
                {
                    m_Data = m_webrequest.assetBundle;
                }
                else if (LoaderType.Typeof_Bytes.Equals(type))
                {
                    m_Data = m_webrequest.bytes;
                }
                else
                {
                    m_Data = m_webrequest.text;
                }

                cRequest.data = m_Data;
                if (m_webrequest != null)
                {
                    m_webrequest.Dispose();
                }
                m_webrequest = null;
            }
        }
コード例 #7
0
    IEnumerator load()
    {
        WWW www = new WWW("file://" + Application.dataPath + saveSoundScript.fileName);

        yield return(www);

        recordedFiles      = WWWAudioExtensions.GetAudioClip(www);
        recordedFiles.name = saveSoundScript.fileName;
        //recordedFiles = www.GetAudioClip();

//        print(recordedFiles.name);
        clipNumber++;
        saveSoundScript.newRec = false;
    }
コード例 #8
0
    /// <summary>Loads an audio file as an AudioClip. Note that MP3 files are not supported on standalone platforms and Ogg Vorbis files are not supported on mobile platforms.</summary>
    /// <param name="imagePath">The relative or absolute path of the audio file we want to load as an AudioClip.</param>
    /// <param name="settings">The settings we want to use to override the default settings.</param>
    public static AudioClip LoadAudio(string audioFilePath, ES3Settings settings)
    {
        if (Application.platform == RuntimePlatform.WebGLPlayer)
        {
            Debug.LogError("You cannot use ES3.LoadAudio with Unity Web Player");
        }

        string extension = ES3IO.GetExtension(audioFilePath).ToLower();

        if (extension == ".mp3" && (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXPlayer))
        {
            throw new System.InvalidOperationException("You can only load Ogg, WAV, XM, IT, MOD or S3M on Unity Standalone");
        }

        if (extension == ".ogg" && (Application.platform == RuntimePlatform.IPhonePlayer ||
                                    Application.platform == RuntimePlatform.Android ||
                                    Application.platform == RuntimePlatform.WSAPlayerARM))
        {
            throw new System.InvalidOperationException("You can only load MP3, WAV, XM, IT, MOD or S3M on Unity Standalone");
        }

        var newSettings = new ES3Settings(audioFilePath, settings);

                #if UNITY_2017_1_OR_NEWER
        WWW www = new WWW(newSettings.FullPath);
                #else
        WWW www = new WWW("file://" + newSettings.FullPath);
                #endif
        while (!www.isDone)
        {
            // Wait for it to load.
        }

        if (!string.IsNullOrEmpty(www.error))
        {
            throw new System.Exception(www.error);
        }

                #if UNITY_2017_3_OR_NEWER
        return(www.GetAudioClip(true));
                #elif UNITY_5_6_OR_NEWER
        return(WWWAudioExtensions.GetAudioClip(www));
                #else
        return(www.audioClip);
                #endif
    }
コード例 #9
0
    public void PlayRecording(string filename)
    {
        string filepath = Path.Combine(Application.persistentDataPath, filename);

        Debug.Log(string.Format("MicHelper::PlayRecording() {0}", filepath));

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

        while (!www.isDone)
        {
            // wait til done since it takes more than 1 frame in some cases
        }

        goAudioSource.clip = WWWAudioExtensions.GetAudioClip(www, true, false, AudioType.WAV);
        Debug.Log(goAudioSource.clip.loadState);
        goAudioSource.Play();
    }
コード例 #10
0
    //-------------------------------------------------------------------------------------------------------------------------------------
    protected IEnumerator loadAssetsFromUrl(string url, Type assetsType, AssetLoadDoneCallback callback, object userData)
    {
        WWW www = new WWW(url);

        yield return(www);

        if (www.error != null)
        {
            // 下载失败
            UnityUtility.logInfo("下载失败 : " + url, LOG_LEVEL.LL_FORCE);
            callback(null, userData);
        }
        else
        {
            UnityEngine.Object obj = null;
            if (assetsType == typeof(AudioClip))
            {
#if UNITY_5_3_5
                obj = www.audioClip;
#else
                obj = WWWAudioExtensions.GetAudioClip(www);
#endif
            }
            else if (assetsType == typeof(Texture2D) || assetsType == typeof(Texture))
            {
                obj = www.texture;
            }
            else if (assetsType == typeof(MovieTexture))
            {
#if UNITY_5_3_5
                obj = www.movie;
#else
                obj = WWWAudioExtensions.GetMovieTexture(www);
#endif
            }
            else if (assetsType == typeof(AssetBundle))
            {
                obj = www.assetBundle;
            }
            obj.name = url;
            callback(obj, userData);
        }
        www.Dispose();
        www = null;
    }
コード例 #11
0
ファイル: Test.cs プロジェクト: Thomas33033/FiveScreem
    IEnumerator DownloadMovie()
    {
        WWW www = new WWW("file://D://ScreenDisplay//123.ogv");

        movieTexture = WWWAudioExtensions.GetMovieTexture(www);

        while (!movieTexture.isReadyToPlay)
        {
            yield return(www);
        }

        image.texture    = movieTexture;           //视频纹理
        audioPlayer.clip = movieTexture.audioClip; //音频

        yield return(new WaitForSeconds(1));

        Play();
    }
コード例 #12
0
        private void Load()
        {
            string text = GetAudioClipReferenceFilename();

            if (_languageSupported)
            {
                int languageIndex = FabricManager.Instance.GetLanguageIndex();
                if (languageIndex >= 0)
                {
                    LanguageProperties languagePropertiesByIndex = FabricManager.Instance.GetLanguagePropertiesByIndex(languageIndex);
                    if (languagePropertiesByIndex != null)
                    {
                        text = text.Replace("LANGUAGE", languagePropertiesByIndex._languageFolder);
                    }
                }
            }
            www            = new WWW(text);
            base.AudioClip = WWWAudioExtensions.GetAudioClip(www, _is3D, _isStreaming, _audioType);
        }
コード例 #13
0
    /// <summary>
    /// Async for rendering an AudioClip
    /// </summary>
    /// <returns></returns>
    IEnumerator RenderClip(GameObject theClient, string wordsToSpeak, string recieptMessage)
    {
        Regex  rgx    = new Regex("\\s+");
        string result = rgx.Replace(wordsToSpeak, "%20");

#if (UNITY_ANDROID || UNITY_IOS)
        string url = "http://api.voicerss.org/?key=" + APIKey + "&hl=en-us&src=" + result + "&c=MP3&f=48khz_16bit_mono";
        WWW    www = new WWW(url);
        yield return(www);

        clip = WWWAudioExtensions.GetAudioClip(www, false, false, AudioType.MPEG);
#else
        string url = "http://api.voicerss.org/?key=" + APIKey + "&hl=en-us&src=" + result + "&c=OGG&f=48khz_16bit_mono";
        WWW    www = new WWW(url);
        yield return(www);

        clip = www.GetAudioClip(false, false, AudioType.OGGVORBIS);
#endif
        theClient.SendMessage(recieptMessage, clip);
    }
コード例 #14
0
    public static IEnumerator streamSong(string identifier, string filename, bool isPlaying)
    {
        AudioSource audioSource = GameObject.FindGameObjectWithTag("AudioSource").GetComponent <AudioSource>();

        if (audioSource.isPlaying)
        {
            audioSource.Stop();
        }

        if (!isPlaying)
        {
            string file = "https://archive.org/download/" + identifier + "/" + filename;
            Debug.Log(file);

            using (WWW request = new WWW(file)) {
                yield return(request);

                audioSource.clip = WWWAudioExtensions.GetAudioClip(request, false, true, AudioType.OGGVORBIS);
                audioSource.Play();
            }
        }
    }
コード例 #15
0
 public AudioClip LoadSoundAsClip(string path)
 {
     try
     {
         if (File.Exists(path))
         {
             WWW www = new WWW(new Uri(path).AbsoluteUri);
             while (!www.isDone)
             {
                 Thread.Sleep(100);
             }
             AudioClip audioClip = WWWAudioExtensions.GetAudioClip(www);
             KKVMDPlugin.Logger.Log(LogLevel.Debug, string.Format("Successfully loaded {0} as AudioClip.", path));
             return(audioClip);
         }
     }
     catch (Exception value)
     {
         Console.WriteLine(value);
     }
     return(null);
 }
コード例 #16
0
    IEnumerator MusicLoading()
    {
        // 資源路徑
        string dPath = Application.streamingAssetsPath + "/Music";

        if (!Directory.Exists(dPath))
        {
            Directory.CreateDirectory(dPath);
        }
        // 取得該路徑下資源數,篩選wav檔,因為Editor會含有meta的檔案
        string[] wav   = Directory.GetFileSystemEntries(dPath, "*.wav");
        string[] mp3   = Directory.GetFileSystemEntries(dPath, "*.mp3");
        string[] files = mp3.Union(wav).ToArray();
        int      count = files.Length;

        if (count > 0)
        {
            clips = new AudioClip[count];

            for (int i = 0; i < count; i++)
            {
                string sPath = "file://" + files[i];
                WWW    www   = new WWW(sPath);
                yield return(www);

                clips[i]         = WWWAudioExtensions.GetAudioClip(www, true, true);
                clips[i].name    = files[i].Replace(dPath + "\\", "");
                textLoader.text += OrderColor(i + 1) + clips[i].name + "\n";
            }
            bgAudio.clip     = clips[defaultTrack];
            textPlaying.text = clips[defaultTrack].name;
        }
        else
        {
            textLoader.text += "No Track\n";
        }
    }
コード例 #17
0
        private IEnumerator LoadPlayCoroutine(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents)
        {
            string filename = GetAudioClipReferenceFilename();

            if (_languageSupported)
            {
                int languageIndex = FabricManager.Instance.GetLanguageIndex();
                if (languageIndex >= 0)
                {
                    LanguageProperties languagePropertiesByIndex = FabricManager.Instance.GetLanguagePropertiesByIndex(languageIndex);
                    if (languagePropertiesByIndex != null)
                    {
                        filename = filename.Replace("LANGUAGE", languagePropertiesByIndex._languageFolder);
                    }
                }
            }
            www = new WWW(filename);
            while (!www.isDone)
            {
                yield return(new WaitForSeconds(0.1f));
            }
            base.AudioClip = WWWAudioExtensions.GetAudioClip(www, _is3D, _isStreaming, _audioType);
            PlayInternalWait(zComponentInstance, target, curve, dontPlayComponents);
        }