2012-06-04 5 views
0

내 질문에 너무 많은 MediaPlayers가 IOException을 일으켜서 preparefailed가 발생합니까? status = 0x1 to log?MediaPlayer 준비가 실패 IOException

내 프로그램이 실행되는 방식은 내가 재생할 각 비디오에 대해 Media Player의 별도 인스턴스를 사용하고 있습니다. 실행이 끝나면 videoPlayer를 중지하고 놓은 다음 null로 설정합니다. 이 때로는 괜찮지 만 다른 시간에 비디오를 너무 빨리 움직일 때 IO 예외가 발생하고 비디오가 재생되지 않습니다. 또한 서비스에서 일부 배경 음악을 재생하는 mediaPlayer가 있습니다.

기본적으로 내 비디오 활동은 파일 재생이 끝날 때마다 새로운 전화를받습니다. 이 오류가있을 수 및 다른 파일을 사용하여 동일한 미디어 플레이어를 그냥 다시 시도해야합니까?

미리 감사드립니다.

답변

1

나는 내 자신의 대답을 발견했습니다. 이것이 좋은 방법인지는 모르겠지만 :

if(videoFile != null) 
     { 
      Log.i("INITPLAYER", videoFile); 
      afd = getAssets().openFd(videoFile); 

      instructionVideoPlayer = new MediaPlayer(); 

      instructionVideoPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength()); 

      instructionVideoPlayer.setDisplay(holder); 

      instructionVideoPlayer.prepare(); 

      instructionVideoPlayer.setOnCompletionListener(instructionVideoComplete); 
      instructionVideoPlayer.setOnPreparedListener(this); 
     } 
     else 
      Log.i("VideoPlayer", "noVideoFile"); 

    } catch (IllegalArgumentException e) { 
     e.printStackTrace(); 
    } catch (IllegalStateException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     Log.i(this.toString(), "IOEXception"); 
     e.printStackTrace(); 

//Here is the fix: 
     instructionVideoPlayer.release(); 
     instructionVideoPlayer = null; 
     initPlayer(); 
// reinit after prepare failed. although this can bring in an infinte loop if video file does not exits 
    } catch (Exception e) 
    { 
     Log.i("InitPlayer", e.getClass().toString()); 
     e.printStackTrace(); 
    } 
+0

정말 도움이되었습니다. 그냥 릴리스를 호출합니다. ! – png