[英]Android Java - SoundPool sounds stop playing for some reason
Well , I use SoundPool for onClick on ImageView sounds and some of them starts another Activity. 好吧,我使用SoundPool onClick on ImageView声音,其中一些启动另一个Activity。 Like this : 像这样 :
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.main_menue_status:{
button_click.play(button_clickID, 1,1, 0, 0, 1); //this is SoundPoool's play
Intent intent=new Intent(context,MainMenueActivity.class);
startActivity(intent);
finish();
}
other activities has same ImageViews(actually, buttons) to navigate through the app. 其他活动具有相同的ImageViews(实际上是按钮)来浏览应用程序。 And all the time I use finish(); 并且我一直使用finish(); to prevent creating millions of copies of activities. 防止创建数百万个活动副本。 So after about 30 SoundPool's plays sound stops playing at all. 因此,在大约30个SoundPool播放之后声音停止播放。
My guess is that's because I finish() Activity before sound complete it's playback so somehow system stop playing any SoundPool at all. 我的猜测是因为我在声音完成之前完成了()活动,因此系统停止播放任何SoundPool。
Any advice? 有什么建议?
UPD : Log : UPD:日志:
12-01 19:04:49.797: E/AudioTrack(19981): AudioFlinger could not create track, status: -12
12-01 19:04:49.797: E/SoundPool(19981): Error creating AudioTrack
The "status: -12", I believe, is an Out of Memory error. 我相信“状态:-12”是内存不足的错误。 Also, calling finish()
in an Activity is not a guarantee that the Activity will immediately finish and release resources. 此外,在Activity中调用finish()
并不能保证Activity将立即完成并释放资源。
Since you have several Activities and several SoundPools, I would recommend creating the SoundPool and loading your sound resources in the Activity's onResume()
method, and then unloading the resources and releasing the SoundPool in the onPause() method. 由于您有多个活动和几个SoundPools,我建议创建SoundPool并在Activity的onResume()
方法中加载声音资源,然后卸载资源并在onPause()方法中释放SoundPool。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.