android – 当媒体播放器完成播放时调用另一个活动

嗨我在音频播放结束时使用以下代码调用活动.但我想在当前活动中播放音频,当播放结束时,它必须跳转到下一个活动.但是在这里它跳转到下一个活动并播放音频.有什么建议么.

package com.fsp.mus;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;

public class MyRecording extends Activity{
    String mFileName;
     MediaPlayer mPlayer; 
     Boolean stopplay;
    @Override

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

        mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
        mFileName += "/audiorecordtest.3gp";
        mPlayer = new MediaPlayer(); 

         try {

            mPlayer.setDataSource(mFileName);
        } catch (IllegalArgumentException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
          try {
            mPlayer.prepare();
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        mPlayer.start();    
       if(mPlayer.getCurrentPosition()== mPlayer.getDuration())
       {
           Intent stopplay=new Intent(MyRecording.this,Recorded_Message.class);
            startActivity(stopplay); 
       }

    }
}
最佳答案
mPlayer.setOnCompletionListener(new
    OnCompletionListener() {        
        @Override
        public void onCompletion(MediaPlayer arg0) {
        Intent stopplay= new Intent(MyRecording.this,Recorded_Message.class);
        startActivity(stopplay);                
    }
});

转载注明原文:android – 当媒体播放器完成播放时调用另一个活动 - 代码日志