title: Android MediaRecorder Video - Audio and Video track playing subsequently
body: <p>I came a across a bug, mostly present on samsung devices.
  I record a video with media recorder (code shown below). It worked flawlessly, on all devices, but now on some Android Devices the Audio and Video track are separated.</p>
  
  <p>Say I'm capturing 5 sec of Video.
  The Video will be 5 sec long, playing the video will play the first frame of the video and the 5 secs of Audio.
  After that, the 5 secs of Video are being played.
  The default video player shows that the video is over after 5 sec, but in fact its only the audio...</p>
  
  <p>Is there anything newly introduced to 8.0 Oreo, so that I have to adapt my MediaRecorder?</p>
  
  <p>My media recorder setup:</p>
  
  <pre><code>private void SetUpMediaRecorder()
          {
              MediaRecorder.SetAudioSource(AudioSource.Mic);
              MediaRecorder.SetVideoSource(VideoSource.Surface);
              MediaRecorder.SetOutputFormat(OutputFormat.Mpeg4);
  
              MediaRecorder.SetVideoEncoder(VideoEncoder.H264);
              MediaRecorder.SetAudioEncoder(AudioEncoder.Aac);
              MediaRecorder.SetOutputFile(outputURL);
              MediaRecorder.SetVideoSize(1280, 720);
  
              MediaRecorder.SetVideoFrameRate(30);
              MediaRecorder.SetVideoEncodingBitRate(2000000);
              MediaRecorder.SetMaxDuration(VideoManager.MAX_VIDEODURATION_MS);
  
              //Set audio bitrate
              int bitDepth = 16;
              int sampleRate = 44100;
              int bitRate = sampleRate * bitDepth;
              MediaRecorder.SetAudioEncodingBitRate(bitRate);
              MediaRecorder.SetAudioSamplingRate(sampleRate);
  
              int rotation = (int)ThisActivity.WindowManager.DefaultDisplay.Rotation;
              int orientation = orientations[rotation];
              MediaRecorder.SetOrientationHint(orientation);
              MediaRecorder.Prepare();
          }
  </code></pre>
  
  <p>EDIT: I'm using the Camera2 API</p>
  
  <p>EDIT2: It seems to be an issue for some samsung devices. The deep sleep will cause the presentation timestamp of the first frame to be too long. Setting the timestamp to 1/30th of a second (if your video was captured at 30fps) will fix this issue.
  Here is a corresponding bug thread: 
  <a href="https://github.com/googlesamples/android-Camera2Video/issues/24" rel="nofollow noreferrer">https://github.com/googlesamples/android-Camera2Video/issues/24</a></p>