Android MediaPlayer 오류 해결 MediaPlayer start called in state 0
그러나 타이머 타 이 머 를 사용 하여 서브 스 레 드 에서 5 초 씩 총 33 회 녹음 할 수 있 습 니 다.
플레이 어 는 미디어 플레이어 대상 입 니 다.
재생 을 시작 할 때 player.start()를 사용 합 니 다.
재생 종료 시 player.stop()사용
그리고 계속 끝나 기 시 작 했 어 요.
하지만 두 번 째 때 는 미디어 플레이어 start called in state 0 이 잘못 보 고 됩 니 다.
그리고 이 문 제 를 찾 아 보 니 플레이 어 를 처음 사용 하 는 대상 이 라면 플레이 어 를 직접 사용 할 수 있다 는 것 이다.start().
하지만 재 활용 이 라면 두 번 째 시작 은 player.start()앞 이나 player.stop()뒤에 player.prepare()를 추가 해 야 합 니 다.
하지만 이 코드 를 처음 사용 할 때 player.start()를 처음 사용 하면 player.start()앞 에 player.prepare()를 추가 하면 이상 이 생 길 수 있 습 니 다.
따라서 처음 사용 여 부 를 판단 하지 않 기 위해 서 는 player.start()를 여러 번 사용 할 때 player.stop()뒤에 player.prepare()방법 을 추가 하 는 것 을 권장 합 니 다.추가 할 때 이상 이 발생 할 수 있 으 므 로 이상 을 처리 해 야 합 니 다.다음은 제 전체 Timer Task 코드 입 니 다.
class myTaskStart extends TimerTask{
@Override
public void run(){
//
System.out.println(" ");
//count , run
if(count<33){
count=count+1;
}
else {
this.cancel();
System.exit(0);
}
// count run
// TextView
textView.post(new Runnable() {
@Override
public void run() {
textView.setText("start"+count);
}
});
// TextView
player.start();
String fileName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
audioRecorder.createDefaultAudio(fileName); // status = Status.STATUS_READY;
audioRecorder.startRecord(null);
//
try {
Thread.sleep(5000);
}
catch (InterruptedException e)
{
Toast.makeText(getApplicationContext()," ",Toast.LENGTH_LONG).show();
}
//
System.out.println(" ");
audioRecorder.stopRecord();
player.stop();
textView.post(new Runnable() {
@Override
public void run() {
textView.setText("end");
}
});
// player.stop() player.prepare(), !
try {
player.prepare();
}
catch (IOException e)
{
System.out.println("player !");
}
// player.prepare
}
}
주요 코드 는 다음 과 같 습 니 다.
player.stop();
// player.stop() player.prepare(), !
try {
player.prepare();
}
catch (IOException e)
{
System.out.println("player !");
}
// player.prepare
이렇게 하면 정상적으로 운행 할 수 있다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.