안녕하세요, 쓰레드를 중지한 후 다시 동작하려고 하는데 동작하지 않습니다.
MediaPlay play시 threadOperate();
MediaPlay pause시 아래와 같이 isPlaying이 false여서 쓰레드가 멈추고 다시 MediaPlay를 start했는데... 쓰레드는 동작을
하지 않는데... 왜 그런가요??
flag도 사용해보고 다시 play 버튼을 눌렀을 때 thread.start();
java.lang.IllegalThreadStateException: Thread already started
오류가 발생합니다.
public void threadOperate(){
System.out.println("isPlaying :" + mp.isPlaying());
if(thread == null) {
thread = new Thread(new Runnable() {
@Override
public void run() {
while (mp.isPlaying()) {
try {
Thread.sleep(500);
System.out.println("thread");
Message msg = timeHandler.obtainMessage();
timeHandler.sendMessage(msg);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
thread.start();
}
public class TimeHandler extends Handler {
@Override
public void handleMessage(Message msg) {
String t = DateFormat.format("mm:ss", mp.getCurrentPosition()) + " / " +
DateFormat.format("mm:ss", mp.getDuration());
int position = (int)(((float)mp.getCurrentPosition()/(float)mp.getDuration())*100);
mCallback.seekbarInfo(t,position);
}
}