@@ -361,7 +361,7 @@ class CamConfig(private val mActivity: MainActivity) {
361361 modePref.getString(videoFrameRateKey, " " )!!
362362 )
363363 } else {
364- SettingValues . Default . VIDEO_FRAME_RATE
364+ defaultVideoFrameRate
365365 }
366366 }
367367 set(value) {
@@ -383,6 +383,14 @@ class CamConfig(private val mActivity: MainActivity) {
383383 return " ${SettingValues .Key .VIDEO_FRAME_RATE } _$pf "
384384 }
385385
386+ val defaultVideoFrameRate : Range <Int >
387+ get() {
388+ val availableFrameRates = getAvailableVideoFrameRates()
389+ if (availableFrameRates.contains(SettingValues .Default .VIDEO_FRAME_RATE ))
390+ return SettingValues .Default .VIDEO_FRAME_RATE
391+ return availableFrameRates[0 ]
392+ }
393+
386394 var flashMode: Int
387395 get() = if (imageCapture != null ) imageCapture!! .flashMode else
388396 SettingValues .Default .FLASH_MODE
@@ -956,6 +964,19 @@ class CamConfig(private val mActivity: MainActivity) {
956964 else frontCameraInfo!!
957965 }
958966
967+ fun getAvailableVideoFrameRates (): List <Range <Int >> {
968+ val resSet = getCurrentCameraInfo().supportedFrameRateRanges
969+
970+ // Individual fps -> Ranged fps (sorted by lower value of range and then upper for each lower value)
971+ val resList = resSet.sortedWith(compareBy<Range <Int >> { it.lower != it.upper }.thenBy { it.lower }.thenBy { it.upper })
972+
973+ // If the supportedFrameRateRange list is somehow empty due to device/library implementation
974+ // go with the most likely default rate
975+ if (resList.isEmpty()) return listOf (SettingValues .Default .VIDEO_FRAME_RATE )
976+
977+ return resList
978+ }
979+
959980 fun toggleCameraSelector () {
960981
961982 // Manually switch to the opposite lens facing
@@ -1060,7 +1081,6 @@ class CamConfig(private val mActivity: MainActivity) {
10601081 if (mActivity.isDestroyed || mActivity.isFinishing) return
10611082
10621083 cameraSelector = CameraSelector .Builder ()
1063- .requireLensFacing(lensFacing)
10641084 .addCameraFilter {
10651085 return @addCameraFilter listOf (
10661086 if (lensFacing == CameraSelector .LENS_FACING_BACK ) {
0 commit comments