2014-06-14 2 views
6

비디오를 레코딩하려고하는데 녹화 중 초를 표시하려고합니다.진행중인 레코딩 기간을 얻을 수있는 방법이 있습니까

어떻게해야합니까?

공공 무효 startRecording (보기 V) {

flipCamera.setVisibility(View.GONE); 
    captureImage.setVisibility(View.GONE); 
    String deviceMan = android.os.Build.MANUFACTURER; 
    this.mediaRecorder = new MediaRecorder(); 
    this.mediaRecorder.setCamera(this.camera); 

    camera.unlock(); 
    this.mediaRecorder.setCamera(camera); 
    this.mediaRecorder.setOrientationHint(90); 

    this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
    this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
    CamcorderProfile camcorderProfile_HQ = CamcorderProfile 
      .get(CamcorderProfile.QUALITY_480P); 
    this.mediaRecorder.setProfile(camcorderProfile_HQ); 
    this.mediaRecorder.setOutputFile(this.initFile().getAbsolutePath()); 
    this.mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec. 
    this.mediaRecorder.setMaxFileSize(5000000); 
    this.mediaRecorder.setPreviewDisplay(this.cameraPreview.getHolder() 
      .getSurface()); 

    this.mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); 

    try { 
     this.mediaRecorder.prepare(); 
     // start the actual recording 
     // throws IllegalStateException if not prepared 
     this.mediaRecorder.start(); 
     Toast.makeText(this, R.string.recording, Toast.LENGTH_SHORT).show(); 

     this.toggleButtons(true); 

    } catch (Exception e) { 
     Log.wtf(TAG, "Failed to prepare MediaRecorder", e); 
     Toast.makeText(this, R.string.cannot_record, Toast.LENGTH_SHORT) 
       .show(); 
     this.releaseMediaRecorder(); 
    } 
} 

내가 하나가 도울 수 있다면 그렇게하십시오 안드로이드 아주 새로운 오전.

답변

10

타이머와 처리기를 사용하여이를 달성 할 수 있습니다. 아래 예제에서 텍스트보기는 00min : 00sec 형식으로 기간을 표시하는 데 사용됩니다. 나는 이것을 백그라운드 서비스에서 사용하지만 당신도 활동에서 사용할 수 있습니다.

public TextView timerTextView; 
private long startHTime = 0L; 
private Handler customHandler = new Handler(); 
long timeInMilliseconds = 0L; 
long timeSwapBuff = 0L; 
long updatedTime = 0L; 


private Runnable updateTimerThread = new Runnable() { 

      public void run() { 

       timeInMilliseconds = SystemClock.uptimeMillis() - startHTime; 

       updatedTime = timeSwapBuff + timeInMilliseconds; 

       int secs = (int) (updatedTime/1000); 
       int mins = secs/60; 
       secs = secs % 60; 
       if (timerTextView != null) 
       timerTextView.setText("" + String.format("%02d", mins) + ":" 
         + String.format("%02d", secs)); 
       customHandler.postDelayed(this, 0); 
      } 

     }; 

당신이 녹화 시작 장소 :

 ...... 
      this.mediaRecorder.start() 
      startHTime = SystemClock.uptimeMillis(); 
      customHandler.postDelayed(updateTimerThread, 0); 

당신이 기록 중지 :

이 이
+0

Heyy @Nana Ghartey 솔루션 작동

 mediaRecorder.stop() timeSwapBuff += timeInMilliseconds; customHandler.removeCallbacks(updateTimerThread); 
..하지만 것입니다 ... 때마다 나는 기록 동영상이 추가됩니다. 예를 들어 첫 번째 동영상을 3 초 동안 5 초 및 두 번째 동영상으로 녹화 한 다음 첫 번째 동영상은 00:00 - 00:05, 두 번째 동영상은 00:00 - 00:08으로 표시하고 대신 00:00을 표시해야합니다 - 첫 번째 동영상은 00:05이고 두 번째 동영상은 00:00 - 00:03입니다. 여기 좀 도와주세요. 모든 도움을 주시면 감사하겠습니다. 미리 감사드립니다;) :) – MashukKhan

+0

각 비디오 단계가 기록 된 후 타이머를 중지/시작하기 만하면됩니다. –

관련 문제