我與,我想同時播放聲音文件的特定時間段的安卓媒體應用工作的特定時間,以播放聲音。所以,我創建了一個類和我使用這個類裏面SoundPool
和Thread
概念來播放聲音,但是當我運行我的應用程序它要的ANR狀態,並顯示登錄貓如何同時使用的Soundpool的時間
樣本警告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;
}
}
logcat的
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
我編輯的類文件,你在你的答案中提到我仍然在相同的情況意味着它是不是在玩任何聲音,但沒有出現在logcat的任何警告。 –
對不起,我忘了從活動中調用構造函數。現在它在logcat中返回相同的警告,直到while循環結束。 –
確保你將'load()'返回的id傳遞給'play()'。在上面的代碼中,你只是返回'resId'。另外我也沒有看到你在哪裏調用'load()'。 –