Android 如何在soundpool中实现释放功能?
我是android的新手,我有个错误 运行我的应用程序时,AudioFlinger无法创建曲目,状态:-12。我阅读了使用Android 如何在soundpool中实现释放功能?,android,soundpool,Android,Soundpool,我是android的新手,我有个错误 运行我的应用程序时,AudioFlinger无法创建曲目,状态:-12。我阅读了使用release()方法来修复它,但我不知道如何在我的代码上实现,请帮助我??这是我的代码,请修复:) 你的声音大于1MB吗?SoudPool不会播放比这更大的声音 如果不是,您可以在播放声音后使用释放 // your code: this.setVolumeControlStream(AudioManager.STREAM_MUSIC); spool = new Sound
release()
方法来修复它,但我不知道如何在我的代码上实现,请帮助我??这是我的代码,请修复:)
你的声音大于1MB吗?SoudPool不会播放比这更大的声音 如果不是,您可以在播放声音后使用释放
// your code:
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID = spool.load(this, R.raw.doo, 1);
//after this you have to:
spool.setOnLoadCompleteListener(new OnLoadCompleteListener(){
@Override
public void onLoadComplete(SoundPool sound,int sampleId,int status){
spool.play(teste, 20,20, 1, 0, 1);
new Thread(new Runnable(){
@Override
public void run(){
try {
Thread.sleep(2000);
spool.release();
} catch (InterruptedException e) { e.printStackTrace(); }
}
}).start();
}
});
// in the Thread.sleep put the value in millisecs of the time of your music this is a sample os 2 seconds
您能给我们看一下
logcat
错误吗?这是:):“AudioFlinger无法创建音轨,状态:-12”和“创建音轨时出错”请帮助我:(我尝试了此操作,但发现错误:类型SoundPool中的方法setOnLoadCompleteListener(SoundPool.OnLoadCompleteListener)不适用于参数(新的OnLoadCompleteListener(){})?我的资源只有7Kb,但我有16个声音可以与soundpool一起运行:)右键单击项目,转到属性->Java编译器->检查启用项目特定设置->然后选择最高的编译器符合性级别。如果这不起作用,然后右键单击项目,AndroidTools->修复项目属性。不要忘了将值:2000更改为大于声音持续时间(毫秒)的值@Override public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.talempong);this.setVolumeControlStream(AudioManager.STREAM_MUSIC);spool=new SoundPool(10,AudioManager.STREAM_MUSIC,0);soundID=spool.load(this,R.raw.doo,1);//新发布的ImageButton Button=(ImageButton)findViewById(R.id.imagebutton1);Button.setOnClickListener(新视图.OnClickListener(){@Override public void onClick(视图v){Sound();
和` public void Sound(){AudioManager AudioManager=(AudioManager)getSystemService(AUDIO_SERVICE);float volume=audioManager.getStreamVolume(audioManager.STREAM_MUSIC);spool.play(soundID,volume,volume,1,0,1f);`这是我的完整示例代码,我不知道如何实现您的代码,我遇到一些错误,但非常感谢:)
// your code:
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID = spool.load(this, R.raw.doo, 1);
//after this you have to:
spool.setOnLoadCompleteListener(new OnLoadCompleteListener(){
@Override
public void onLoadComplete(SoundPool sound,int sampleId,int status){
spool.play(teste, 20,20, 1, 0, 1);
new Thread(new Runnable(){
@Override
public void run(){
try {
Thread.sleep(2000);
spool.release();
} catch (InterruptedException e) { e.printStackTrace(); }
}
}).start();
}
});
// in the Thread.sleep put the value in millisecs of the time of your music this is a sample os 2 seconds