title: Why is my CameraX CameraView showing a blackscreen?
body: <p><strong>I have been implementing CameraView for my app and it used to work few weeks ago, but now it is just showing a black screen, meaning the preview is not shown. As a result, it seems like the videos being recorded aren't being saved either.</strong></p>
  <p>Can someone correct my code please?</p>
  <p><strong>Manifest:</strong></p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  </code></pre>
  <p><strong>build.gradle(app)</strong></p>
  <pre><code> def camerax_version = &quot;1.0.0-beta07&quot;
      implementation &quot;androidx.camera:camera-core:$camerax_version&quot;
      implementation &quot;androidx.camera:camera-camera2:$camerax_version&quot;
      implementation &quot;androidx.camera:camera-lifecycle:$camerax_version&quot;
      implementation &quot;androidx.camera:camera-view:1.0.0-alpha14&quot;
  </code></pre>
  <p><strong>xml</strong></p>
  <pre><code>&lt;androidx.camera.view.CameraView
          android:id=&quot;@+id/CameraView_cameraPreview&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;500dp&quot;
          app:captureMode=&quot;mixed&quot;
          app:flash=&quot;auto&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:layout_constraintVertical_bias=&quot;0.4&quot;
          app:lensFacing=&quot;back&quot;
          app:pinchToZoomEnabled=&quot;true&quot;
          app:scaleType=&quot;fitCenter&quot; /&gt;
  
  **p.s: I have implemented this button in build.gradle**
  &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id=&quot;@+id/Button_cameraRecord&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:src=&quot;@drawable/camera_record_vector&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;0.5&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/CameraView_cameraPreview&quot;
          app:layout_constraintVertical_bias=&quot;0.5&quot; /&gt;
  </code></pre>
  <p><strong>Kotlin Activity</strong></p>
  <pre><code>package com.example.iambeta.camera
  
  import android.Manifest
  import android.content.Intent
  import android.content.pm.PackageManager
  import android.os.Bundle
  import android.os.SystemClock
  import android.util.Log
  import android.view.View
  import android.widget.SeekBar
  import android.widget.Toast
  import androidx.appcompat.app.AlertDialog
  import androidx.appcompat.app.AppCompatActivity
  import androidx.camera.core.CameraSelector
  import androidx.camera.core.VideoCapture
  import androidx.core.app.ActivityCompat
  import androidx.core.content.ContextCompat
  import com.example.iambeta.R
  import com.example.iambeta.storage.UploadActivity
  import kotlinx.android.synthetic.main.activity_camera.*
  import java.io.File
  
  //variables for requesting permission
  private const val REQUEST_CODE_PERMISSION = 101
  var CAMERA_PERMISSION = Manifest.permission.CAMERA
  var RECORD_AUDIO_PERMISSION = Manifest.permission.RECORD_AUDIO
  private val REQUIRED_PERMISSION = arrayOf(CAMERA_PERMISSION, RECORD_AUDIO_PERMISSION)
  val TAG = Camera::class.java.simpleName
  
  class Camera : AppCompatActivity() {
  
      //declaring variables for camera
      private var recordingStatus: recordingState? = null
  
      override fun onCreate(savedInstanceState: Bundle?){
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_camera)
  
          //initializing variables for camera
          recordingStatus = recordingState.NOTRECORDING
  
          //if record button is clicked
          Button_cameraRecord.setOnClickListener{
              if(recordingStatus == recordingState.NOTRECORDING) {
                  recordingStatus = recordingState.RECORDING
                  startRecord()
              }else if(recordingStatus == recordingState.RECORDING){
                  recordingStatus = recordingState.NOTRECORDING
                  stopRecord()
              }
          }
  
      }
  
      //start recording
      fun startRecord(){
          //variable for storing the video/recording
          val fileStorage = &quot;${System.currentTimeMillis()}.mp4&quot;
  
          CameraView_cameraPreview.startRecording(File(externalMediaDirs.first(), fileStorage), ContextCompat.getMainExecutor(this), object: VideoCapture.OnVideoSavedCallback {
              override fun onVideoSaved(file: File) {
                  Log.d(TAG, &quot;onVideoSaved $fileStorage&quot;)
              }
  
              override fun onError(videoCaptureError: Int, message: String, cause: Throwable?) {
                  Toast.makeText(applicationContext, &quot;Recording Failed&quot;, Toast.LENGTH_SHORT).show()
                  Log.e(TAG, &quot;onError $videoCaptureError $message&quot;)
              }
          })
      }
  
      //stop recording
      fun stopRecord(){
          CameraView_cameraPreview.stopRecording()
          Toast.makeText(this, &quot;Saved to /internalstorage/Android/media/...&quot;, Toast.LENGTH_SHORT).show()
          Log.i(TAG, &quot;Video File Stopped&quot;)
      }
  
      //returns the result of requesting permission (i.e. failed obtaining permission)
      override fun onRequestPermissionsResult(requestCode: Int, permissions: Array&lt;out String&gt;, grantResults: IntArray) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults)
          if (requestCode == REQUEST_CODE_PERMISSION) {
              if (allPermissionsGranted()) {
                  openCamera()
              } else {
                  Toast.makeText(this, &quot;Permissions not granted by the user.&quot;, Toast.LENGTH_SHORT)
                      .show()
                  finish()
              }
          }
      }
  
      //checking if all permissions are granted
      private fun allPermissionsGranted(): Boolean {
          for (permission in REQUIRED_PERMISSION) {
              if (ContextCompat.checkSelfPermission(
                      this,
                      permission
                  ) != PackageManager.PERMISSION_GRANTED
              ) {
                  return false
              }
          }
          return true
      }
  
      //starting camera
      private fun openCamera(){
          if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
              CameraView_cameraPreview.bindToLifecycle(this)
          }
      }
  
      //Enum class to see if the record button is recording or not
      enum class recordingState{
          RECORDING, NOTRECORDING
      }
  
      override fun onStart() {
          super.onStart()
          //check if all permission has been give, else request permission
          if(allPermissionsGranted()){
              openCamera()
          }else{
              ActivityCompat.requestPermissions(this, REQUIRED_PERMISSION, REQUEST_CODE_PERMISSION)
          }
      }
  }
  </code></pre>