记录一个问题:
游戏内播放完音频A再去循环播放音频B,在协程里使用等待n秒来实现拼接,发现在个别手机上会有卡顿的问题,盲猜是和帧率有关。
这是最初的实现方案:
            
            
              cs
              
              
            
          
              IEnumerator IEPlayAudio()
    {
        if(ASOnBeginDrag != null)
        {
            AudioClip clip = ASOnBeginDrag.clip;
            if(clip != null)
            {
                float m_AudioLen = clip.length;
                ASOnBeginDrag.Play();
                yield return new WaitForSeconds(m_AudioLen);
                if (ASOnDrag != null)
                {
                    ASOnDrag.Play();
                    ASOnDrag.loop = true;
                }
            }
        }
        yield return null;
    }这是修改后的代码:
            
            
              cs
              
              
            
          
              void PlayBeginDragAudio()
    {
        if(ASOnBeginDrag != null)
        {
            ASOnBeginDrag.Play();
            if (ASOnDrag != null)
            {
                //使用Audio System绝对时间来处理音频拼接问题
                ASOnDrag.PlayScheduled(AudioSettings.dspTime + m_AudioLen);
                ASOnDrag.loop = true;
            }
        }
    }AudioSourec.PlayScheduled(AudioSettings.dspTime + timeInterval);
表示在当前Audio System绝对时间之后的timeInterval秒,来播放;同时想要停止这个操作只需要AudioSourec.Stop()即可。