我正在使用一个 android 媒体应用程序,我想在特定时间段内同时播放声音文件。所以我创建了一个类,我在这个类中使用SoundPool
和Thread
概念来播放声音,但是当我运行我的应用程序时,它会进入 ANR 状态并在 log-cat 中显示警告
样品 2130968576 未准备好
任何人都请帮我解决这个问题...
班级
package com.kodspider.funk;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
public class CustomPlayer implements Runnable{
int song_id;
long time;
int button_id;
Context ctx;
SoundPool soundpool;
public CustomPlayer(int s_id, long Time, Context ct){
song_id = load(ctx, s_id, 0);
time = Time;
ctx = ct;
}
public void run(){
long start = System.currentTimeMillis();
System.out.println("set_time:"+time+"Song_id:"+song_id+"current_time:"+start);
long end = start + time;
while (System.currentTimeMillis() < end){
//Initialization
soundpool = new SoundPool(8, AudioManager.STREAM_MUSIC, 0);
soundpool.play(song_id, 1.0f, 1.0f, 1, -1, 1.0f);
}
}
public int load (Context context, int resId, int priority){
return resId;
}
}
日志猫
07-07 10:57:51.828: I/ApplicationPackageManager(13625): cscCountry is not German : INS
07-07 10:57:57.656: I/ApplicationPackageManager(13625): cscCountry is not German : INS
07-07 10:57:59.343: W/KeyCharacterMap(13625): Can't open keycharmap file
07-07 10:57:59.343: W/KeyCharacterMap(13625): Error loading keycharmap file
07-07 10:57:59.343: W/KeyCharacterMap(13625): Using default keymap
07-07 10:58:44.820: I/ApplicationPackageManager(13625): cscCountry is not German : INS
07-07 10:58:49.718: I/System.out(13625): TAG------->60000---->2130968576
07-07 10:58:49.726: W/SoundPool(13625): sample 2130968576 not READY