当我将SoundPool实例移动到单独的线程和类时,我遇到了一个问题。
虽然所有流和状态标志都成功,但没有声音播放。
我在错误日志中收到以下输出:
D/chris﹕ before play
E/AudioPolicyManagerBase﹕ getOutput() IOProfile is null.
E/AudioPolicyManagerBase﹕ getOutput() IOProfile is null.
E/AudioPolicyManagerBase﹕ getOutput() IOProfile is null.
D/libc﹕ pt_debug : pthread_create->start_routine=0x402c8509, tls=0x55c6ff00, arg=0x512c4370
D/libc﹕ pt_debug : __thread_entry->func=0x402c8509 , tls=0x55c6ff00, arg=0x512c4370
D/chris﹕ after play
有没有人知道这些错误表明了什么?
public class SoundPoolFactory extends Thread {
public SoundPool soundPool;
public HashMap<String, AssetFileDescriptor> soundLoadList = new HashMap<String, AssetFileDescriptor>();
public void run()
{
Looper.prepare();
looper = Looper.myLooper();
soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
soundLoaded.release();
}
});
Iterator iterator = soundLoadList.entrySet().iterator();
while (iterator.hasNext())
{
Map.Entry entry = (Map.Entry)iterator.next();
loadSound((AssetFileDescriptor)entry.getValue(), (String)entry.getKey());
}
Looper.loop();
}
public void loadSound(AssetFileDescriptor assetFile, String soundIndex)
{
try {
soundIndexes.put(soundIndex, soundPool.load(assetFile, 1));
} catch (Exception e)
{
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter( writer );
e.printStackTrace(printWriter);
printWriter.flush();
Log.e("chris", writer.toString());
}
}
public SoundPool getSoundPoolInstance()
{
try {
Log.d("chris", "before play");
soundPool.play(1, 1.0f, 1.0f,1,0,1.0f);
Log.d("chris", "after play");
return soundPool;
}
catch (Exception e)
{
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter( writer );
e.printStackTrace(printWriter);
printWriter.flush();
Log.e("chris", writer.toString());
}
return null;
}
}