From 6f12fdd72620dae59a9a19b1676587b37cc18aca Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 3 Jan 2019 11:46:21 +0100 Subject: [PATCH] Volume boost with appropriate settings (gain in dB) --- README.md | 5 ++-- app/build.gradle | 4 +-- .../eu/zderadicka/audioserve/AudioService.kt | 26 ++++++++++++++----- .../zderadicka/audioserve/SettingsActivity.kt | 25 ++++++++++++++++++ app/src/main/res/values/strings.xml | 7 ++++- app/src/main/res/xml/settings.xml | 13 ++++++++++ 6 files changed, 68 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 90b7386..275f2a7 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,14 @@ Available features * Downloads part of or whole folder to cache (swipe playable item to left to see download button) * Offline mode - plays only from cache * Remembers up to 100 recently listened positions -* Bookmarks +* Bookmarks (on folder or file) * Search (for folder names) * Folder details - with picture and text (if present in the folder) and summary * Intenet search - search author, boook ... (uses folder name and optional prefix to search on google) -* Notifications +* Notifications - Media notification with controls, plus notification for other features (sleep timer, downloads) * Supports Android lifecycle - rotations, back, stop activity etc... * Supports Android audio focus (pauses when call comes in etc.) +* Advanced playback features - playback speed, skip silence, boost volume KISS Design Principles diff --git a/app/build.gradle b/app/build.gradle index ac04569..cb2650b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,8 +18,8 @@ android { applicationId "eu.zderadicka.audioserve" minSdkVersion 21 targetSdkVersion 28 - versionCode 22 - versionName "0.7.2" + versionCode 23 + versionName "0.7.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt b/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt index 7dbc462..79bada7 100644 --- a/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt +++ b/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt @@ -82,7 +82,14 @@ private class ResultWrapper(val result: MediaBrowserServiceCompat.Result { volumeBooster.enabled = sharedPreferences.getBoolean("pref_volume_boost", false) } + "pref_volume_boost_db" -> { + volumeBooster.gain = sharedPreferences.getString("pref_volume_boost_db", "0").toInt() * 100 + } } } @@ -566,8 +579,7 @@ class AudioService : MediaBrowserServiceCompat() { session = MediaSessionCompat(this, LOG_TAG) session.controller.registerCallback(sessionCallback) player = ExoPlayerFactory.newSimpleInstance(this, DefaultTrackSelector()) - val boostEnabled = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_volume_boost", false) - volumeBooster = VolumeBooster(boostEnabled) + volumeBooster = VolumeBooster(this) player.audioComponent?.addAudioListener(volumeBooster) setPlaybackParams() diff --git a/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt b/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt index 1a933c4..b39436c 100644 --- a/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt +++ b/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt @@ -106,6 +106,15 @@ class SettingsFragment: PreferenceFragment(), SharedPreferences.OnSharedPreferen } } + findPreference("pref_volume_boost_db").setOnPreferenceChangeListener{_, newValue -> + try { + val n = (newValue as String).toInt(); + n>=1 && n <= 30 + } catch (e: Exception) { + false + } + } + findPreference("pref_clear_cache").setOnPreferenceClickListener { Thread { @@ -272,6 +281,22 @@ class SettingsFragment: PreferenceFragment(), SharedPreferences.OnSharedPreferen "pref_playback_speed" -> { } + "pref_volume_boost" -> { + if (pref !is CheckBoxPreference) return + val checked = sps.getBoolean( "pref_volume_boost", false) + if (checked) { + pref.summary=getString(R.string.pref_volume_boost_on_summary) + + } else { + pref.summary=getString(R.string.pref_volume_boost_off_summary) + } + } + + "pref_volume_boost_db" -> { + val v = sps.getString(pref.key, "1") + pref.summary = getString(R.string.pref_volume_boost_db_summary, v) + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fbcce78..dff8082 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -84,7 +84,7 @@ PLAYBACK Auto Rewind No auto rewind, playback will start exactly where it was paused - Before continuing playback track\'\'ll be rewound by a small amount (2s-30s), depending how long it was paused + Before continuing playback track\'\'ll be rewound by a small amount (2s-30s), depending on how long it was paused Rewind Forward Web search prefix @@ -103,4 +103,9 @@ Skip Silence: Speed: Boost Volume: + Volume boost + Volume boost gain + Volume is boosted + Normal volume limits + If Volume boost switch is on volume will be amplified by %1$s dB (valid values are 1 - 30 dB) diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index e9ebd0a..1fb5acb 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -95,6 +95,19 @@ android:defaultValue="false" /> + + + +