Beispiel #1
0
    private void E_Show(Text txName, FileInfo file, bool isNeedDaoRu)       // 显示音乐页事件
    {
        tx_Name = txName;
        mUIGameObject.SetActive(true);
        go_Wait.SetActive(true);
        go_ShowMusic.SetActive(false);
        go_DaoRu.SetActive(false);
        tx_WaitName.text = file.Name;
        Ctrl_LoadAudioClip.Instance.StartLoadAudioClip(file, (resBean) =>
        {
            mAudioSource.loop    = true;
            mCurrentAudioResBean = resBean;
            go_Wait.SetActive(false);
            go_ShowMusic.SetActive(true);
            go_DaoRu.SetActive(isNeedDaoRu);
            tx_InfoName.text         = file.Name;
            mTotalTime               = resBean.Clip.length.ToTiemStr();
            mAudioSource.clip        = resBean.Clip;
            slider_Progress.minValue = 0;
            slider_Progress.maxValue = resBean.Clip.length;

            tx_DR1.text = Ctrl_UserInfo.Instance.BottomAudioName[0];
            tx_DR2.text = Ctrl_UserInfo.Instance.BottomAudioName[1];
            tx_DR3.text = Ctrl_UserInfo.Instance.BottomAudioName[2];
            tx_DR4.text = Ctrl_UserInfo.Instance.BottomAudioName[3];
            tx_DR5.text = Ctrl_UserInfo.Instance.BottomAudioName[4];

            Btn_OnPlay();
        });
    }
Beispiel #2
0
    IEnumerator LoadMp3(FileInfo fileInfo, MP3ResBean res, Action <AudioResBean> callBack)
    {
        while (!res.isOk)
        {
            yield return(new WaitForSeconds(0.1f));
        }
        using (UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip("file://" + res.SavePath, AudioType.WAV))
        {
            yield return(request.SendWebRequest());

            if (request.isHttpError || request.isNetworkError)
            {
                MyLog.Red(request.error);
                yield break;
            }
            AudioClip clip = DownloadHandlerAudioClip.GetContent(request);
            clip.name = Path.GetFileNameWithoutExtension(res.SavePath);

            AudioResBean resBean = new AudioResBean(clip, res.YuanPath, res.SavePath, true, fileInfo);
            l_AudioResBean.Add(resBean);
            if (null != callBack)
            {
                callBack(resBean);
            }
        }
    }
Beispiel #3
0
    private void E_DaoRuAudioFromResult(EAudioType type, AudioResBean resBean)
    {
        mSelectIndex = (ushort)type;
        bool isNoError = IsSaveOk(EGameType.Audio, (ushort)type, new string[] { resBean.SavePath });

        go_Bottom2.SetActive(true);
        Show(EGameType.Audio, isNoError);
        if (isNoError)
        {
            MyEventCenter.SendEvent(E_GameEvent.DaoRu_Audio, type, resBean);
        }
    }
Beispiel #4
0
    private readonly List <AudioResBean> l_AudioResBean = new List <AudioResBean>(); // 所有的音频文件返回结果的集合



    IEnumerator LoadOtherGeShi(FileInfo file, Action <AudioResBean> callBack)
    {
        AudioType type;

        if (file.Extension == ".ogg")
        {
            type = AudioType.OGGVORBIS;
        }
        else if (file.Extension == ".aiff")
        {
            type = AudioType.AIFF;
        }
        else if (file.Extension == ".wav")
        {
            type = AudioType.WAV;
        }
        else
        {
            throw new Exception("还有其他格式?");
        }
        string path = file.FullName;

        using (UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip("file://" + path, type))
        {
            yield return(request.SendWebRequest());

            if (request.isHttpError || request.isNetworkError)
            {
                MyLog.Red(request.error);
                yield break;
            }
            AudioClip clip = DownloadHandlerAudioClip.GetContent(request);
            clip.name = Path.GetFileNameWithoutExtension(path);
            AudioResBean resBean = new AudioResBean(clip, path, path, false, file);
            l_AudioResBean.Add(resBean);
            if (null != callBack)
            {
                callBack(resBean);
            }
        }
    }
Beispiel #5
0
    //———————————————————— 事件 ————————————————

    private void E_DaoRu_Audio(EAudioType type, AudioResBean resBean)
    {
        Transform t = InstantiateMoBan(go_MoBan, GetParentRT(type), CREATE_FILE_NAME);

        t.Find("Top/TxName").GetComponent <Text>().text = Path.GetFileNameWithoutExtension(resBean.YuanPath);
        Text tx_ZhongTime = t.Find("Top/TxZhongTime").GetComponent <Text>();

        if (resBean.Clip.length <= 1)
        {
            tx_ZhongTime.text = "极短";
        }
        else
        {
            tx_ZhongTime.text = resBean.Clip.length.ToTiemStr();
        }

        Text   tx_CurrentTime  = t.Find("Bottom/TxCurrentTime").GetComponent <Text>();
        Button btn_Play        = t.Find("Bottom/BtnPlay").GetComponent <Button>();
        Button btn_Pause       = t.Find("Bottom/BtnPause").GetComponent <Button>();
        Slider slider_Progress = t.Find("Bottom/Slider_Progress").GetComponent <Slider>();

        EachItemBean itemBean = new EachItemBean(mAudioSource, resBean.Clip, btn_Play.gameObject, btn_Pause.gameObject, slider_Progress, tx_CurrentTime);

        typeK_BeanListV[type].Add(itemBean);
        // 播放按钮
        btn_Play.onClick.AddListener(() =>
        {
            if (null != mCurrentPlayBean)
            {
                mCurrentPlayBean.Stop();
            }
            mCurrentPlayBean = itemBean;
            mCurrentPlayBean.Play();
        });
        // 暂停按钮
        btn_Pause.onClick.AddListener(() =>
        {
            mCurrentPlayBean.Pause();
        });
        // 检测双击
        t.Find("Bg").GetComponent <Button>().onClick.AddListener(() =>
        {
            if (isSelect)
            {
                isSelect = false;
                StopAudio();
                MyEventCenter.SendEvent <Text, FileInfo, bool>(E_GameEvent.ShowMusicInfo, null, new FileInfo(resBean.SavePath), false);
            }
            else
            {
                Ctrl_Coroutine.Instance.StartCoroutine(CheckoubleClick());
            }
        });
        // 删除按钮
        t.Find("Top/BtnClose").GetComponent <Button>().onClick.AddListener(() =>
        {
            if (itemBean == mCurrentPlayBean)
            {
                mCurrentPlayBean.Stop();
                mAudioSource.clip = null;
                mCurrentPlayBean  = null;
            }
            typeK_BeanListV[type].Remove(itemBean);
            UnityEngine.Object.Destroy(t.gameObject);
            Ctrl_TextureInfo.Instance.DeleteAudioSave(type, resBean.SavePath);
        });
    }