gpt4 book ai didi

android - Android声音池无法正常工作

转载 作者:行者123 更新时间:2023-12-03 02:03:06 24 4
gpt4 key购买 nike

当我尝试在程序中运行soundpool时,它总是给我一个错误。

首先,我添加了

SoundPool sp;

int shot = 0;

在程序开始时。然后,我尝试通过添加以下代码在想要运行的方法中添加声音,
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

shot = sp.load(this, R.raw.sound, 1);

但是,它始终强调.load并一直说“SoundPool类型的方法load(Context,int,int)不适用于参数(GameView,int,int)”

我怎样才能解决这个问题?

最佳答案

您不能将 View 作为第一个参数传递,它必须是上下文。使用this.getContext()代替。

关于android - Android声音池无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29931634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com