Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用soundpool和setOnLoadCompleteListener时出现的问题_Android_Soundpool - Fatal编程技术网

Android 使用soundpool和setOnLoadCompleteListener时出现的问题

Android 使用soundpool和setOnLoadCompleteListener时出现的问题,android,soundpool,Android,Soundpool,因此,我使用soundpool在计时器结束时播放声音。一旦创建,我就这样做 int mySoundId; SoundPool soundPool; // load sound soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); AssetManager am = this.getAssets(); //Use in whatever method is used to load the sounds try {

因此,我使用soundpool在计时器结束时播放声音。一旦创建,我就这样做

int mySoundId;
SoundPool soundPool;

// load sound

soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

AssetManager am = this.getAssets();

//Use in whatever method is used to load the sounds
try {
    mySoundId = soundPool.load(am.openFd("alarm.wav"), 1);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
我正在

样本0未就绪

所以我发现我必须使用

soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
    @Override
    public void onLoadComplete(SoundPool soundPool, int mySoundId, int status) {
        loaded = true;
    }
});
但我的问题是,setOnLoadCompleteListener给了我以下错误

方法setOnLoadCompleteListener(SoundPool.OnLoadCompleteListener) 在类型中,SoundPool不适用于参数(新 OnLoadCompleteListener(){})


我尝试过各种方法,比如“Android工具->修复项目属性”和摆弄“属性->Java编译器”,但没有乐趣。我的API范围是10-16,所以应该可以。有什么问题吗?

使用下面的代码。也许你的进口错了。无论如何,这应该行得通

soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
    @Override
    public void onLoadComplete(SoundPool soundPool, int mySoundId, int status) {
        loaded = true;
    }
});
我也有同样的问题, 然后我注意到我只是
导入android.media.SoundPool.OnLoadCompleteListener

有趣的是,在我发布它几秒钟后,就有人对它进行了升级!没时间看吗?对不起,我不得不把这个写下来一点,如果正确的话,我会确保在我回来的时候接受你的答案,谢谢!好吧,它有点工作,现在它说-打开跟踪文件时出错:没有这样的文件或目录(2)