Exemplo n.º 1
0
        /// <summary>
        /// 内部播放方法,编排好CachePlayList之后调用这里
        /// </summary>
        private void DoPlay()
        {
            //当前是否有播放
            if (mCur_PlayingClip != null)
            {
                MainAudioSource.Stop();
                mCur_PlayingClip = null;
                if (mCurPlayerTimer != null)
                {
                    mCurPlayerTimer.Dispose();
                    mCurPlayerTimer = null;
                }
            }
            if (mCachePlayList.Count <= 0)
            {
                XLog.PrintW("[TinaX] 音轨 " + mSoundTrackName + " 播放失败:音频缓存队列为空");
                return;
            }
            mCur_PlayingClip     = mCachePlayList[0];
            MainAudioSource.clip = mCur_PlayingClip.OriginClip;
            var length = mCur_PlayingClip.OriginClip.length;

            //设置计时器
            mCurPlayerTimer = Observable.Timer(TimeSpan.FromSeconds(length)).Subscribe(_ => {
                Timer_OnClipPlayEnd();
            });

            MainAudioSource.Play();
            mCachePlayList.RemoveAt(0);
        }
Exemplo n.º 2
0
        //某个Clip播放结束的计时器
        private void Timer_OnClipPlayEnd()
        {
            Debug.Log("播放器:播放Clip计时器触发");
            //某个clip播放结束了,我们看看接下来要干嘛
            //首先看看播放模式
            if (mPlayMode == E_PlayMode.single)
            {
                //那就播放结束了呗,处理下回调
                foreach (var item in OnClipPlayEnd)
                {
                    item.Value(mCur_PlayingClip.Name, "");
                }
                //然后,清空当前状态
                mCurPlayerTimer  = null;
                mCur_PlayingClip = null;
            }
            if (mPlayMode == E_PlayMode.single_loop)
            {
                //循环啊,那就再放一遍
                mCachePlayList.Add(mCur_PlayingClip);
                DoPlay();
            }
            if (mPlayMode == E_PlayMode.list || mPlayMode == E_PlayMode.list_loop)
            {
                //列表循环,播放下一个,编排Cache
                int index = 0;
                for (int i = 0; i < mPlayList.Count; i++)
                {
                    if (mPlayList[i].Name == mCur_PlayingClip.Name)
                    {
                        index = i;
                        break;
                    }
                }
                index++;
                if (index >= mPlayList.Count)
                {
                    index = 0;
                    if (mPlayMode == E_PlayMode.list)
                    {
                        foreach (var item in OnListPlayEnd)
                        {
                            item.Value();
                        }
                    }
                }
                mCachePlayList.Add(mPlayList[index]);
                DoPlay();
            }


            mCurPlayerTimer = null;
        }