Back to project page project2.
The source code is released under:
MIT License
If you think the Android project project2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package team2.scdm; // w w w .j a va2 s . c o m import java.io.IOException; import android.app.Activity; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.media.AudioManager; // for AudiManager, missed it? import android.media.SoundPool; import team2.scdm.Audio; import team2.scdm.Media; import team2.scdm.Sound; public class GameAudio implements Audio{ AssetManager assets; SoundPool soundPool; public GameAudio(Activity activity) { activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.assets = activity.getAssets(); this.soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0); } @Override public Media newMusic(String fileName) { try{AssetFileDescriptor assetDescriptor = assets.openFd(fileName); return new GameMusic(assetDescriptor); }catch(IOException e) { throw new RuntimeException("Couldn't load music'" + fileName + "'"); } } @Override public Sound newSound(String fileName) { try{AssetFileDescriptor assetDescriptor = assets.openFd(fileName); int soundID = soundPool.load(assetDescriptor, 0); return new GameSound(soundPool, soundID); }catch(IOException e) { throw new RuntimeException("Couldn't load sound'" + fileName + "'"); } } }