2014-06-09 1 views
0

비디오가 끝난 후 내 비디오를 다음 활동으로 보내려고합니다. 다른 게시물이 동일한 작업을 수행하는 것을 보았습니다. 코드를 구현하려고 할 때 나머지 코드 전체에 오류가 계속 발생합니다. 이 마지막 부분을 추가하기 전에 내 비디오가 정상적으로 재생되었습니다. 누구든지 내 코드에 어떤 문제가 보이나요? 미리 감사드립니다.videoview에서 setOnCompletionListener를 사용하려고하면 왜 오류가 발생합니까?

import android.app.Activity; 
import android.content.Intent; 
import android.media.MediaPlayer; 
import android.media.MediaPlayer.OnPreparedListener; 
import android.net.Uri; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ProgressBar; 
import android.widget.VideoView; 


public class ThirdActivity extends Activity { 

    ProgressBar mProgressBar; 
    VideoView mVideoView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.fragment_third); 

     String fileName = "android.resource://" + getPackageName() + "/" + R.raw.leftwrist; 

     mProgressBar = (ProgressBar) findViewById(R.id.Progressbar); 
     mProgressBar.setProgress(0); 
     mProgressBar.setMax(100); 

     mVideoView = (VideoView) findViewById(R.id.video_view); 
     mVideoView.setVideoURI(Uri.parse(fileName)); 
     new myAsync().execute(); 
    } 

    private class myAsync extends AsyncTask<Void, Integer, Void> 
    { 
     int duration = 0; 
     int current = 0; 
     @Override 
     protected Void doInBackground(Void... params) { 

      mVideoView.start(); 
      mVideoView.setOnPreparedListener(new OnPreparedListener() { 

       public void onPrepared(MediaPlayer mp) { 
        duration = mVideoView.getDuration(); 
       } 
      }); 

      do { 
       current = mVideoView.getCurrentPosition(); 
       System.out.println("duration - " + duration + " current- " 
         + current); 
       try { 
        publishProgress((int) (current * 100/duration)); 
        if(mProgressBar.getProgress() >= 100){ 
         break; 
        } 
       } catch (Exception e) { 
       } 
      } while (mProgressBar.getProgress() <= 100); 

      return null; 
     } 

     @Override 
     protected void onProgressUpdate(Integer... values) { 
      super.onProgressUpdate(values); 
      System.out.println(values[0]); 
      mProgressBar.setProgress(values[0]); 
     } 

     mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){ 
      @Override 
      public void onCompletion(MediaPlayer mp){ 
       Intent intent = new Intent(this, FourthActivity.class); 
       startActivity(intent); 
      } 
     }); 

} 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 

     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.third, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

    /** 
    * A placeholder fragment containing a simple view. 
    */ 
    public static class PlaceholderFragment extends Fragment { 

     public PlaceholderFragment() { 
     } 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      View rootView = inflater.inflate(R.layout.fragment_third, container, false); 
      return rootView; 
     } 
    } 

} 

답변

0

변화

Intent intent = new Intent(this, FourthActivity.class); 

귀하의 경우

Intent intent = new Intent(ThirdActivity.this, FourthActivity.class); 

thisOnCompletionListener없는 활동을 의미한다. AsyncTask를에서 전직에 대한 onCreate

mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){ 
      @Override 
      public void onCompletion(MediaPlayer mp){ 
       Intent intent = new Intent(this, FourthActivity.class); 
       startActivity(intent); 
      } 
     }); 

에 다음

이동 :

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fragment_third); 

    String fileName = "android.resource://" + getPackageName() + "/" + R.raw.leftwrist; 

    mProgressBar = (ProgressBar) findViewById(R.id.Progressbar); 
    mProgressBar.setProgress(0); 
    mProgressBar.setMax(100); 

    mVideoView = (VideoView) findViewById(R.id.video_view); 
    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){ 
      @Override 
      public void onCompletion(MediaPlayer mp){ 
       Intent intent = new Intent(this, FourthActivity.class); 
       startActivity(intent); 
      } 
     }); 
    mVideoView.setVideoURI(Uri.parse(fileName)); 
    new myAsync().execute(); 
} 
+0

나는 아직도 불행하게도, 같은 오류를 얻고있다. – dy19

+0

편집을 시도한 후에 작동했습니다. 대단히 감사합니다 !! – dy19