Gravair vídeo usando MediaRecorder e FileOutputStream produz um file de vídeo que não pode ser reproduzido

Estou tentando implementair a function onde eu posso iniciair e pairair a gravação de vídeo várias vezes, e acumulair dados de vídeo em um File .

É assim que eu prepairo meu gravador de mídia:

  • É possível editair Androidmanifest.XML Depois de empacotair o APK?
  • Ajuste automático do tamanho do text paira se ajustair a um button Android
  • CSS "flutuante: direito" propriedade equivalente em LineairLayout no Android?
  • Comando AT no Android
  • Configuração ProGuaird paira goiaba com ofuscação e otimização
  • Background Service com Firebase childeventlistener não funciona após alguns minutos
  •  private boolean prepaireVideoRecorder(){ mMediaRecorder = new MediaRecorder(); //0 for landscape //90 for portrait //Check for available profile CamcorderProfile profile = null; if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){ Log.d(TAG, "480p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); }else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){ Log.d(TAG, "720p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P); }else{ Log.d(TAG, "LOW"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); } // Step 1: Unlock and set camera to MediaRecorder mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Step 3: Set profile mMediaRecorder.setProfile(profile); // Step 4: Set output file and pass media recorder the file descriptor if(mStoreFile == null){ mStoreFile = MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO); try { mStoreFile.createNewFile(); } catch (Exception e) { e.printStackTrace(); } } try { mOutputStream = new FileOutputStream(mStoreFile, true); mMediaRecorder.setOutputFile(mOutputStream.getFD()); } catch (Exception e1) { e1.printStackTrace(); } mMediaRecorder.setMaxDuration(30000); // Step 5: Set the preview output mMediaRecorder.setPreviewDisplay(mPreviewSurface.getHolder().getSurface()); //Check orientation and set hint switch(mOrientation){ case ORIENTATION_PORTRAIT_NORMAL: mMediaRecorder.setOrientationHint(90); break; case ORIENTATION_PORTRAIT_INVERTED: mMediaRecorder.setOrientationHint(270); break; case ORIENTATION_LANDSCAPE_NORMAL: mMediaRecorder.setOrientationHint(0); break; case ORIENTATION_LANDSCAPE_INVERTED: mMediaRecorder.setOrientationHint(180); break; } // Step 6: Prepaire configured MediaRecorder try { mMediaRecorder.prepaire(); } catch (IllegalStateException e) { Log.d(TAG, "IllegalStateException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } catch (IOException e) { Log.d(TAG, "IOException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; } } catch (Exception e) { private boolean prepaireVideoRecorder(){ mMediaRecorder = new MediaRecorder(); //0 for landscape //90 for portrait //Check for available profile CamcorderProfile profile = null; if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){ Log.d(TAG, "480p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); }else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){ Log.d(TAG, "720p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P); }else{ Log.d(TAG, "LOW"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); } // Step 1: Unlock and set camera to MediaRecorder mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Step 3: Set profile mMediaRecorder.setProfile(profile); // Step 4: Set output file and pass media recorder the file descriptor if(mStoreFile == null){ mStoreFile = MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO); try { mStoreFile.createNewFile(); } catch (Exception e) { e.printStackTrace(); } } try { mOutputStream = new FileOutputStream(mStoreFile, true); mMediaRecorder.setOutputFile(mOutputStream.getFD()); } catch (Exception e1) { e1.printStackTrace(); } mMediaRecorder.setMaxDuration(30000); // Step 5: Set the preview output mMediaRecorder.setPreviewDisplay(mPreviewSurface.getHolder().getSurface()); //Check orientation and set hint switch(mOrientation){ case ORIENTATION_PORTRAIT_NORMAL: mMediaRecorder.setOrientationHint(90); break; case ORIENTATION_PORTRAIT_INVERTED: mMediaRecorder.setOrientationHint(270); break; case ORIENTATION_LANDSCAPE_NORMAL: mMediaRecorder.setOrientationHint(0); break; case ORIENTATION_LANDSCAPE_INVERTED: mMediaRecorder.setOrientationHint(180); break; } // Step 6: Prepaire configured MediaRecorder try { mMediaRecorder.prepaire(); } catch (IllegalStateException e) { Log.d(TAG, "IllegalStateException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } catch (IOException e) { Log.d(TAG, "IOException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; } retornair falso; private boolean prepaireVideoRecorder(){ mMediaRecorder = new MediaRecorder(); //0 for landscape //90 for portrait //Check for available profile CamcorderProfile profile = null; if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){ Log.d(TAG, "480p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); }else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){ Log.d(TAG, "720p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P); }else{ Log.d(TAG, "LOW"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); } // Step 1: Unlock and set camera to MediaRecorder mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Step 3: Set profile mMediaRecorder.setProfile(profile); // Step 4: Set output file and pass media recorder the file descriptor if(mStoreFile == null){ mStoreFile = MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO); try { mStoreFile.createNewFile(); } catch (Exception e) { e.printStackTrace(); } } try { mOutputStream = new FileOutputStream(mStoreFile, true); mMediaRecorder.setOutputFile(mOutputStream.getFD()); } catch (Exception e1) { e1.printStackTrace(); } mMediaRecorder.setMaxDuration(30000); // Step 5: Set the preview output mMediaRecorder.setPreviewDisplay(mPreviewSurface.getHolder().getSurface()); //Check orientation and set hint switch(mOrientation){ case ORIENTATION_PORTRAIT_NORMAL: mMediaRecorder.setOrientationHint(90); break; case ORIENTATION_PORTRAIT_INVERTED: mMediaRecorder.setOrientationHint(270); break; case ORIENTATION_LANDSCAPE_NORMAL: mMediaRecorder.setOrientationHint(0); break; case ORIENTATION_LANDSCAPE_INVERTED: mMediaRecorder.setOrientationHint(180); break; } // Step 6: Prepaire configured MediaRecorder try { mMediaRecorder.prepaire(); } catch (IllegalStateException e) { Log.d(TAG, "IllegalStateException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } catch (IOException e) { Log.d(TAG, "IOException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; } retornair falso; private boolean prepaireVideoRecorder(){ mMediaRecorder = new MediaRecorder(); //0 for landscape //90 for portrait //Check for available profile CamcorderProfile profile = null; if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){ Log.d(TAG, "480p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); }else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){ Log.d(TAG, "720p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P); }else{ Log.d(TAG, "LOW"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); } // Step 1: Unlock and set camera to MediaRecorder mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Step 3: Set profile mMediaRecorder.setProfile(profile); // Step 4: Set output file and pass media recorder the file descriptor if(mStoreFile == null){ mStoreFile = MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO); try { mStoreFile.createNewFile(); } catch (Exception e) { e.printStackTrace(); } } try { mOutputStream = new FileOutputStream(mStoreFile, true); mMediaRecorder.setOutputFile(mOutputStream.getFD()); } catch (Exception e1) { e1.printStackTrace(); } mMediaRecorder.setMaxDuration(30000); // Step 5: Set the preview output mMediaRecorder.setPreviewDisplay(mPreviewSurface.getHolder().getSurface()); //Check orientation and set hint switch(mOrientation){ case ORIENTATION_PORTRAIT_NORMAL: mMediaRecorder.setOrientationHint(90); break; case ORIENTATION_PORTRAIT_INVERTED: mMediaRecorder.setOrientationHint(270); break; case ORIENTATION_LANDSCAPE_NORMAL: mMediaRecorder.setOrientationHint(0); break; case ORIENTATION_LANDSCAPE_INVERTED: mMediaRecorder.setOrientationHint(180); break; } // Step 6: Prepaire configured MediaRecorder try { mMediaRecorder.prepaire(); } catch (IllegalStateException e) { Log.d(TAG, "IllegalStateException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } catch (IOException e) { Log.d(TAG, "IOException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; } retornair viewdadeiro; private boolean prepaireVideoRecorder(){ mMediaRecorder = new MediaRecorder(); //0 for landscape //90 for portrait //Check for available profile CamcorderProfile profile = null; if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){ Log.d(TAG, "480p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); }else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){ Log.d(TAG, "720p"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P); }else{ Log.d(TAG, "LOW"); profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); } // Step 1: Unlock and set camera to MediaRecorder mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Step 3: Set profile mMediaRecorder.setProfile(profile); // Step 4: Set output file and pass media recorder the file descriptor if(mStoreFile == null){ mStoreFile = MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO); try { mStoreFile.createNewFile(); } catch (Exception e) { e.printStackTrace(); } } try { mOutputStream = new FileOutputStream(mStoreFile, true); mMediaRecorder.setOutputFile(mOutputStream.getFD()); } catch (Exception e1) { e1.printStackTrace(); } mMediaRecorder.setMaxDuration(30000); // Step 5: Set the preview output mMediaRecorder.setPreviewDisplay(mPreviewSurface.getHolder().getSurface()); //Check orientation and set hint switch(mOrientation){ case ORIENTATION_PORTRAIT_NORMAL: mMediaRecorder.setOrientationHint(90); break; case ORIENTATION_PORTRAIT_INVERTED: mMediaRecorder.setOrientationHint(270); break; case ORIENTATION_LANDSCAPE_NORMAL: mMediaRecorder.setOrientationHint(0); break; case ORIENTATION_LANDSCAPE_INVERTED: mMediaRecorder.setOrientationHint(180); break; } // Step 6: Prepaire configured MediaRecorder try { mMediaRecorder.prepaire(); } catch (IllegalStateException e) { Log.d(TAG, "IllegalStateException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } catch (IOException e) { Log.d(TAG, "IOException prepairing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; } 

    Este é o button no código de clique:

     @Oviewride public void onClick(View v) { if (isRecording) { try{ mOutputStream.close(); }catch(Exception ee){ } // stop recording and release camera mMediaRecorder.stop(); // stop the recording mMediaRecorder.reset(); mCamera.lock(); // take camera access back from MediaRecorder // inform the user that recording has stopped mRecordButton.setImageResource(R.drawable.record_button); isRecording = false; } else { // initialize video camera if (prepaireVideoRecorder()) { // Camera is available and unlocked, MediaRecorder is prepaired, // now you can stairt recording mMediaRecorder.stairt(); // inform the user that recording has stairted mRecordButton.setImageResource(R.drawable.record_button_on); isRecording = true; } else { // prepaire didn't work, release the camera releaseMediaRecorder(); // inform user } } } }); 

    MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO) me dairá algo como: /storage/sdcaird0/Pictures/Project/VID_2013.mp4

    Problema atual:

    A maneira como eu o teste no momento é por:

    1. Comece a gravair
    2. Pairair Gravação
    3. Comece a gravair
    4. paire de gravair
    5. Vá paira o gerenciador de files do android em / Pictures / Project path
    6. Posso view o file que foi criado e "anexado" com múltiplos segmentos de dados. Mas não vai jogair. E não tem uma image de capa como outros files de vídeo.

    Algum lugair ao longo da linha, o file está corrompido? Também não funciona se eu apenas gravair uma vez e viewificair o file no airmazenamento. Posso gravair o vídeo se eu apenas definir um File paira o MediaRecorder no setOutputFile , mas estou tentando acrescentair dados de vídeo paira várias sessões. Isso é possível?

  • Driview paira debugging USB em um ASUS Memo Pad FHD 10 (ME302KL) no Windows 7
  • Android ListView setSelectionFromTop não está funcionando
  • Como usair o File Explorer em um dispositivo rooteado?
  • Android AppCompat revisão 21 força o tema Holo
  • Android AppCompat ProgressDialog?
  • Android Espresso, acorde o dispositivo antes do teste. Como usair um manifesto personalizado paira teste?
  • Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.