기술/beginning games2011. 5. 25. 10:33
download download
public class SoundPoolTest extends Activity implements OnTouchListener{
SoundPool soundPool;
int explosionId=-1;
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   TextView textView = new TextView(this);
   textView.setOnTouchListener(this);
   setContentView(textView);
   
   setVolumeControlStream(AudioManager.STREAM_MUSIC);
   soundPool = new SoundPool(20,AudioManager.STREAM_MUSIC,0);
   
   try{
    AssetManager assetManager = getAssets();
    AssetFileDescriptor des = assetManager.openFd("ex.ogg");
    explosionId = soundPool.load(des, 1);
   } catch(IOException e){
    textView.setText("사운드를 읽을 수 없습니다."+e.getMessage());
   }
}

@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP){
if(explosionId != -1){
soundPool.play(explosionId, 1, 1, 0, 0, 1);
}
}
return true;
}
}
download download download
Posted by yachtie_leo