2013-07-28 4 views
0

나는 안드로이드 응용 프로그램을 가지고 있으며 비디오 파일, 특히 하나의 웹 미디어 자원과 다른 시리즈의 에피소드를 재생할 수 있습니다.android, 어떻게 비디오 파일을 재생할 수 있습니까?

videofile 다음 방법을 재생하고 있습니다 :

mp4url
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse(mp4url), "video/mp4"); 
startActivity(intent); 

-

지금은 programm에이 videofiles의 큐를 재생 허용 할

변수 문자열입니다. arg2 선택한 videofile 및 episodes의 위치를 ​​도시

for(int iteration=arg2;iteration<episodes.size(); iteration++){ 
    Intent intent1 = new Intent(Intent.ACTION_VIEW); 
    intent1.setDataAndType(Uri.parse(mp4Url1), "video/mp4"); 
    startActivity(intent1); 
} 

후 선택 videofile를 재생할 videofile의 큐에 대한 ArrayList를 변수이다

는 I는 다음의 방법을 만들기 위해 tryed.

하지만 작동하지 않았습니다. 실제로 모든 비디오 파일은 재생 가능하지만
을 동시에 지원합니다. 나는 그들을 차례대로해야한다. 내 코드를 효과적으로 재구성하려면 어떻게해야합니까?

감사합니다.

static int VIDEO_RUNNING = 0 

이 만들기 :

+0

ur 비디오가 끝날 때 이벤트를 듣고 다음 재생을 시작할 수 있습니다. – KOTIOS

+0

나는 언변합니다. 예제에서 이것을 볼 수 있습니까? – Rinomancer

+0

ur MediaPlayer 사용 하시겠습니까? – KOTIOS

답변

0

당신은 추적 할 수를 유지할 수있는 int 일정

static final int VIDEO_PLAYBACK_FINISHED = 32으로 (예를 들어 yourURLList) 가 정의 영화, URL의 ArrayList를 만들기있는 비디오처럼 재생되고 호출자 활동 내에서 이와 같은 메소드를 호출하십시오.

private void startMovie(int serialOfMovie){ 
     String vdoURL= yourURLList.get(serialOfMovie);//array list of movie urls 
     if(vdoURL != null) 
     { 
      //video url for that index is found,if not then it would not enter here 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setDataAndType(Uri.parse(vdoURL), "video/mp4"); 
      startActivityForResult(intent, 
        VIDEO_PLAYBACK_FINISHED); 
     } 

} 

내부 통화 어 활동이 조각 추가하는 것을 잊지 마세요 (당신이 만들고있는 의도를 호출되어있는 것) : 당신이 영화의이 시리즈 (처음부터 시작)를 재생하려고 할 때 이제

protected void onActivityResult(int requestCode, int resultCode, 
      Intent data) { 
     if (requestCode == VIDEO_PLAYBACK_FINISHED) { 

      if (resultCode == RESULT_OK) { 
       //one video is finished 
       VIDEO_RUNNING++; //increase which vdo is running count 
       startMovie(VIDEO_RUNNING); 
      } 
     } 
    } 

을, 당신은 활동 (이 영화의 URL과 의도를 사용하여 호출 한)에서 동영상을 재생 MediaPlayer를를 사용하는 경우 동영상이 그 활동을 finish해야 재생 완료되면 바로 다음

startMovie(VIDEO_RUNNING);//VIDEO_RUNNING is 0 initially,so it will point the first url in url list. 기억 호출합니다. 당신이 그 활동에 mPlayer라는 MediaPlayer를 인스턴스가있는 경우처럼 당신은이 작업을 수행해야한다 : 당신이 영화를 큐 효과가 있어야

mPlayer.setOnCompletionListener(new 
    OnCompletionListener() {   
     @Override 
     public void onCompletion(MediaPlayer arg0) { 
     finish();    
    } 
}); 

이 방법을 차례대로 재생되는.

+0

불행하게도 모든 비디오 파일은 스스로 끝나도 (에피소드가 끝났음) 결과 0 (RESULT_CANCELLED)로 끝납니다. – Rinomancer

+0

resultcode를 RESULT_OK에서 RESULT_CANCELL로 변경하면 다음 에피소드가 재생됩니다. – Rinomancer

관련 문제