[Unity]播放音频卡顿问题

记录一个问题:

游戏内播放完音频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()即可。

相关推荐
阿松爱学习16 小时前
【Unity开发】FileStream 详解及用法指南
unity·c#·unity开发
想做后端的前端16 小时前
Unity-UIGI优化Rebatch与Rebuild
unity
玖玥拾1 天前
Unity Shader 基础与图形学(一)
unity·图形渲染·图形学·shader
百里香酚兰2 天前
【Unity学习笔记】如何把粉色Prefab还原
笔记·学习·unity
xcLeigh2 天前
Unity基础:使用Transform控制物体旋转——Rotate与LookAt详解
unity·教程·transform·rotate·lookat
坤坤藤椒牛肉面2 天前
RK3576 音频修改:解决HDMI抢占媒体声音
音频
平行云2 天前
3D应用推流太贵太慢?ImmerShare Lite:利用本地算力实现极简一键分享
unity·ue5·实时云渲染·云桌面·像素流·云游戏·串流
凤山老林2 天前
高并发系统架构设计:Spring Boot 多级限流、库存预扣减与异步下单全链路实战
springboot·高并发·限流·异步
淡海水2 天前
11-04-Unity-Span-foreach-LINQ的分配与热路径边界
unity·c#·linq·foreach·span
开发笔记-阿牛2 天前
做工业报警器语音提示,CK6159A 为什么更合适?
人工智能·stm32·单片机·嵌入式硬件·音频