From d6d4eed1a809dc875fe4c8c85a5bfa5e36912378 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 3 Feb 2021 20:48:21 +0100 Subject: [PATCH] the equalizer will apparently have to be set up dynamically --- .../musicplayer/activities/EqualizerActivity.kt | 12 ++++++++++++ .../musicplayer/services/MusicService.kt | 2 -- app/src/main/res/layout/activity_equalizer.xml | 9 ++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/EqualizerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/EqualizerActivity.kt index 8e140a56..a947326f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/EqualizerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/EqualizerActivity.kt @@ -1,5 +1,8 @@ package com.simplemobiletools.musicplayer.activities +import android.annotation.SuppressLint +import android.media.MediaPlayer +import android.media.audiofx.Equalizer import android.os.Bundle import android.view.Menu import com.simplemobiletools.commons.extensions.updateTextColors @@ -11,10 +14,19 @@ class EqualizerActivity : SimpleActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_equalizer) updateTextColors(equalizer_holder) + initMediaPlayer() } override fun onCreateOptionsMenu(menu: Menu): Boolean { updateMenuItemColors(menu) return super.onCreateOptionsMenu(menu) } + + @SuppressLint("SetTextI18n") + private fun initMediaPlayer() { + val player = MediaPlayer() + val equalizer = Equalizer(0, player.audioSessionId) + equalizer_label_bottom.text = (equalizer.bandLevelRange[0] / 100).toString() + equalizer_label_top.text = "+${equalizer.bandLevelRange[1] / 100}" + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt index 2db74152..47672e79 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -12,7 +12,6 @@ import android.media.AudioManager import android.media.AudioManager.* import android.media.MediaMetadataRetriever import android.media.MediaPlayer -import android.media.audiofx.Equalizer import android.media.session.PlaybackState.PLAYBACK_POSITION_UNKNOWN import android.net.Uri import android.os.CountDownTimer @@ -31,7 +30,6 @@ import androidx.media.session.MediaButtonReceiver import com.simplemobiletools.commons.extensions.getColoredBitmap import com.simplemobiletools.commons.extensions.getRealPathFromURI import com.simplemobiletools.commons.extensions.hasPermission -import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.musicplayer.R import com.simplemobiletools.musicplayer.activities.MainActivity diff --git a/app/src/main/res/layout/activity_equalizer.xml b/app/src/main/res/layout/activity_equalizer.xml index 423db372..d4f839e9 100644 --- a/app/src/main/res/layout/activity_equalizer.xml +++ b/app/src/main/res/layout/activity_equalizer.xml @@ -24,7 +24,7 @@ app:layout_constraintTop_toTopOf="parent">