안드로이드 개발 질문/답변
(글 수 45,052)
Button.OnClickListener stopbut = new View.OnClickListener() {
public void onClick(View v) {
if (audio_play != null) {
audio_play.stop(); // 중지
audio_play.release(); // 자원 반환
audio_play = null;
}
startButton.setText("재생");
//stop();
}
};
Button.OnClickListener startbut = new View.OnClickListener() {
public void onClick(View v){
//if(audio_play == null);
LoadMedia();
audio_play.start(); // 시작
startButton.setText("일시정지");
athread thread = new athread();
thread.start();
//}else{
// audio_play.pause();
// startButton.setText("재생");
//}
}
};
public void LoadMedia(){
try{
audio_play.setDataSource("/sdcard/Kalimba.mp3");<<<<<<<<<<<<<<<<<<<<<<<<<이부분
}catch(IllegalArgumentException e){
}catch(IllegalStateException e){
}catch(IOException e){
Toast.makeText(in.this, "Error!!",
Toast.LENGTH_SHORT).show();
}
if(Prepare()==false){
}
mSeekBar.setMax(audio_play.getDuration());
audio_play.setLooping(false); // 반복재생 false
Prepare();
}
재생까지는 잘 되는데 정지했다가 다시 재생하면은 화살표 부분이 널값이 들어간다고 하네요.. 우째 바꺼야 할까요??
public void onClick(View v) {
if (audio_play != null) {
audio_play.stop(); // 중지
audio_play.release(); // 자원 반환
audio_play = null;
}
startButton.setText("재생");
//stop();
}
};
Button.OnClickListener startbut = new View.OnClickListener() {
public void onClick(View v){
//if(audio_play == null);
LoadMedia();
audio_play.start(); // 시작
startButton.setText("일시정지");
athread thread = new athread();
thread.start();
//}else{
// audio_play.pause();
// startButton.setText("재생");
//}
}
};
public void LoadMedia(){
try{
audio_play.setDataSource("/sdcard/Kalimba.mp3");<<<<<<<<<<<<<<<<<<<<<<<<<이부분
}catch(IllegalArgumentException e){
}catch(IllegalStateException e){
}catch(IOException e){
Toast.makeText(in.this, "Error!!",
Toast.LENGTH_SHORT).show();
}
if(Prepare()==false){
}
mSeekBar.setMax(audio_play.getDuration());
audio_play.setLooping(false); // 반복재생 false
Prepare();
}
재생까지는 잘 되는데 정지했다가 다시 재생하면은 화살표 부분이 널값이 들어간다고 하네요.. 우째 바꺼야 할까요??




정지할 때 auto_play = null 한 후 다시 재생시의 null객체의 메소드를 호출하면 null point exception이 떨어지겠지요.