Skip to content

Commit

Permalink
dashboard: stabler audio recorder (fixes #4470) (#4507)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Sep 30, 2024
1 parent f9972cc commit 87a9364
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1967
versionName "0.19.67"
versionCode 1968
versionName "0.19.68"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ class AudioRecorderService {
@RequiresApi(Build.VERSION_CODES.S)
fun startRecording() {
outputFile = createAudioFile()
myAudioRecorder = MediaRecorder(context).apply {
myAudioRecorder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
MediaRecorder(context)
} else {
@Suppress("DEPRECATION")
MediaRecorder()
}

myAudioRecorder?.apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS)
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
Expand All @@ -51,11 +58,8 @@ class AudioRecorderService {
var audioFile: File
var attempt = 0
do {
audioFileName = UUID.randomUUID().toString() + ".aac"
audioFile = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
audioFileName
)
audioFileName = "${UUID.randomUUID()}.aac"
audioFile = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), audioFileName)
attempt++
} while (audioFile.exists() && attempt < 100)
if (attempt >= 100) {
Expand Down

0 comments on commit 87a9364

Please sign in to comment.