2011-08-01 1 views
0

URL에서 1.5-4 시간 오디오 파일을 스트리밍하려고합니다. 나는 MP3 파일에 대한 링크가 브라우저에서 클릭 내 서비스 실행을하고 난 그것을 재생하려면이 코드를 사용MediaPlayer 스트림이 임의로 자름

 String sData = intent.getDataString(); 

     if (sData != null && sData.startsWith("http:") && sData.endsWith(".mp3")) 
     { 
      if (p_oPlayer == null) 
      { 
       CreateMediaPlayer(); // sets p_oPlayer = new MediaPlayer() and creates callbacks for OnPreparedListener, OnErrorListener, OnInfoListener & OnCompletionListener 
      } 
      else 
      { 
       if (p_oPlayer.isPlaying()) 
        p_oPlayer.stop(); 
       p_oPlayer.reset(); 
      } 

      // The next 5 lines are just to make a title out of a filename 
      String sFile = ""; 
      Pattern p = Pattern.compile("([^/]*)\\.mp3"); 
      Matcher m = p.matcher(sData); 
      if (m.find()) 
       sFile = m.group(1).replace("%20", " "); 

      p_oPlayer.setDataSource(sData); 
      p_oPlayer.prepareAsync(); // OnPreparedListener callback just calls start() on the MediaPlayer 

      Intent i = new Intent(this, Main.class); 
      i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
      PendingIntent pIntent = PendingIntent.getActivity(this, 0, i, 0); 

      Notification notice = new Notification(R.drawable.icon2, "WFKO stream is playing", System.currentTimeMillis()); 

      notice.setLatestEventInfo(this, "WFKO Radio", sFile, pIntent); 
      notice.flags |= Notification.FLAG_NO_CLEAR; 
      startForeground(myID, notice); 
     } 

그래서 당신은 내가하지 알고있는 안드로이드 시스템에 전경 서비스를 사용하고 볼 수 있습니다 절대적으로 필요한 경우가 아니라면 서비스를 휴지통에 버려야합니다. 문제는 스트림을 무작위로 10-20 분 동안 재생하지 못하게하는 것입니다. 특정 스트림을 여러 번 재생할 때마다 매번 다른 위치에서 잘라 내기 때문에 특정 데이터 청크와 충돌하는 것이 아닙니다. OnCompletionListener, OnErrorListener 및 OnInfoListener는 모두 아무 작업도 수행하지 않습니다. 나는 방금 그들을 만들었고 그들에게 무슨 일이 일어나고 있는지보기 위해 중단 점을 두었습니다. 스트림이 끊어지면 곧바로 OnCompletionListener로갑니다. 정보 또는 오류 메서드를 호출하지 않습니다.

전경 서비스에 대한 알림은 스트림이 중지 될 때 알림 바에 남기 때문에 안드로이드 시스템이 살인을 저지르고있을 것이라고 확신합니다. 나는 여기서 어디로 가야할지 모르겠다.

누구에게 잘못된 아이디어가 있습니까?

답변

0

내 전화가 진저 브레드 (2.3.4) 업데이트를받은 후 더 이상 문제가되지 않습니다. 업데이트에 MediaPlayer 픽스가 있다는 것을 알고 있으므로, 문제가 해결 된 MediaPlayer의 버그라고 가정해야 할 것입니다.