안드로이드 개발 질문/답변
(글 수 45,052)
public class SoundClass {
static SoundPool soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
public static Context mContext;
static
int chvoice = soundPool.load(mContext,
R.raw.voice_pororo_1,1)
}
----------------------------------------------------------------------------
public class Asdwww extends Activity {
@Override
public void
onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_char);
SoundClass.soundPool.play(SoundClass.chvoice, 1, 1, 0, 0, 1);
}
}
--------------------------------------------------------------
이렇게 SoundClass 에서 soundpool을 load 시켜놓고
Asdwww 에서 바로 play만시켜주려고 합니다.
근데 SoundClass 에 mContext를 어떻게 해줘야 할까요..
클래스부분이 약해서 찾아봐도 잘모르겠네요..




쫒아가보면... mContext 의 초기화 및 대입이 빠져있네요.. context를 static 으로 선언해야만 하는 특별한 이유가 있나요..?
static method로 사용하실거면 차라리 이렇게 하시는게 좋을것 같네요
<Asdwww.java>
onCreate(){
..
...
SoundClass.play(this);
...
..
<SoundClass.java>
변수선언은 동일합니다.
public static void play(Context context){
if(soundPool == null){
soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
}
int voice = soundPool.load(context, R.raw.voice_pororo_1,1);
soundPool.play(voice, 1, 1, 0, 0, 1);
}
}