录制视频和播放时在视频视图中显示录制日期和时间:android

时间:2012-05-18 05:57:34

标签: android

我能够在SD卡中录制和保存视频,并能够从视频视频播放视频,但现在我想在视频视图顶部/底部的侧视频视图中显示录制日期和时间,所以我现在卡在这里,我现在应该做什么..请任何一个完成这个帮助的人,努力在这里会非常感激..

我在下面的代码中使用的录音..:

   public class VideoRecorder extends Activity{

//Create objects of MediaRecorder and Preview class  
     private MediaRecorder recorder;
private Preview mPreview;

boolean flag=false; 
boolean startedRecording=false;
boolean stoppedRecording=false;

// In this method, create an object of MediaRecorder class. Create an object of 
// RecorderPreview class(Customized View). Add RecorderPreview class object
// as content of UI.     
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    recorder = new MediaRecorder();
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    mPreview = new Preview(VideoRecorder.this,recorder);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentView(mPreview);

    }


  @Override
  public boolean onPrepareOptionsMenu(Menu menu) 
{
    super.onPrepareOptionsMenu(menu);
    menu.clear(); 
    menu.add(0, 0, 0, "Start Recording"); 
    menu.add(1, 1, 0, "Stop Recording");

    menu.setGroupVisible(0, false);
    menu.setGroupVisible(1, false);

    if(startedRecording==false)
        menu.setGroupVisible(0, true);
    else if(startedRecording==true&&stoppedRecording==false)
        menu.setGroupVisible(1, true);

    return true;
}


 /*!
    <p>
    This method receives control when Item in menu option is selected. It contains implementations
    to be performed on selection of menu item. 
    </p>*/

@Override
public boolean onOptionsItemSelected(MenuItem item) 
{
    switch (item.getItemId()) 
    {
    case 0:
        //start the recorder
            recorder.start();
            startedRecording=true;

        break;

    case 1: 
        //stop the recorder
        recorder.stop();
        recorder.release();
        recorder = null;
        stoppedRecording=true;
        break;


    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

class Preview extends SurfaceView implements SurfaceHolder.Callback
{
    //Create objects for MediaRecorder and SurfaceHolder.
    SurfaceHolder mHolder;
    MediaRecorder tempRecorder;


    public Preview(Context context,MediaRecorder recorder) {
        super(context);
        tempRecorder=recorder;
        mHolder=getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        // TODO Auto-generated constructor stub
    }

    public Surface getSurface()
    {
        return mHolder.getSurface();
    }

    // Implement the methods of SurfaceHolder.Callback interface

    // SurfaceCreated : This method gets called when surface is created.
    // In this, initialize all parameters of MediaRecorder object.
    //The output file will be stored in SD Card.

    public void surfaceCreated(SurfaceHolder holder){
        tempRecorder.setOutputFile("/sdcard/recordvideooutput.3gpp");
        tempRecorder.setPreviewDisplay(mHolder.getSurface());
        try{
            tempRecorder.prepare();
        } catch (Exception e) {
            String message = e.getMessage();
            tempRecorder.release();
            tempRecorder = null;
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) 
    {
        if(tempRecorder!=null)
        {
            tempRecorder.release();
            tempRecorder = null;
        }
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) 
    {

    }

0 个答案:

没有答案