본문 바로가기
프로그래밍/Android(Java)

[Android] 소리 재생

by 쿼카퀀트 2019. 9. 29.
728x90

소리 파일은 res - raw 폴더에 넣어둔다.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     mSoundPool = new SoundPool.Builder()
            .setMaxStreams(10)
            .build();
} else {
    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 1);
}

mSoundId = mSoundPool.load(this, R.raw.somesound, 1);

// ...

mSoundPool.play(mSoundId, 1, 1, 1, 0, 1);

728x90

댓글