Add pref switch for HW offload

This commit is contained in:
tzugen 2022-04-05 20:58:11 +02:00
parent 1a69507e34
commit 7742f67796
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
5 changed files with 18 additions and 6 deletions

View File

@ -35,6 +35,7 @@ import org.moire.ultrasonic.activity.NavigationActivity
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
import org.moire.ultrasonic.app.UApp
import org.moire.ultrasonic.util.Constants
import org.moire.ultrasonic.util.Settings
class PlaybackService : MediaLibraryService(), KoinComponent {
private lateinit var player: ExoPlayer
@ -92,7 +93,8 @@ class PlaybackService : MediaLibraryService(), KoinComponent {
// Create a renderer with HW rendering support
val renderer = DefaultRenderersFactory(this)
renderer.setEnableAudioOffload(true)
if (Settings.useHwOffload) renderer.setEnableAudioOffload(true)
// Create the player
player = ExoPlayer.Builder(this)
@ -104,7 +106,8 @@ class PlaybackService : MediaLibraryService(), KoinComponent {
.build()
// Enable audio offload
player.experimentalSetOffloadSchedulingEnabled(true)
if (Settings.useHwOffload)
player.experimentalSetOffloadSchedulingEnabled(true)
// Create browser interface
librarySessionCallback = AutoMediaBrowserCallback(player)

View File

@ -71,7 +71,6 @@ object Constants {
const val PREFERENCES_KEY_MEDIA_BUTTONS = "mediaButtons"
const val PREFERENCES_KEY_SCROBBLE = "scrobble"
const val PREFERENCES_KEY_SERVER_SCALING = "serverScaling"
const val PREFERENCES_KEY_REPEAT_MODE = "repeatMode"
const val PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD = "wifiRequiredForDownload"
const val PREFERENCES_KEY_BUFFER_LENGTH = "bufferLength"
const val PREFERENCES_KEY_NETWORK_TIMEOUT = "networkTimeout"
@ -105,13 +104,11 @@ object Constants {
const val PREFERENCES_KEY_SHARE_ON_SERVER = "sharingCreateOnServer"
const val PREFERENCES_KEY_DEFAULT_SHARE_EXPIRATION = "sharingDefaultExpiration"
const val PREFERENCES_KEY_USE_FIVE_STAR_RATING = "use_five_star_rating"
const val PREFERENCES_KEY_HARDWARE_OFFLOAD = "use_hw_offload"
const val PREFERENCES_KEY_CATEGORY_NOTIFICATIONS = "notificationsCategory"
const val PREFERENCES_KEY_FIRST_RUN_EXECUTED = "firstRunExecuted"
const val PREFERENCES_KEY_DEBUG_LOG_TO_FILE = "debugLogToFile"
const val PREFERENCES_KEY_OVERRIDE_LANGUAGE = "overrideLanguage"
const val PREFERENCE_VALUE_ALL = 0
const val PREFERENCE_VALUE_A2DP = 1
const val PREFERENCE_VALUE_DISABLED = 2
const val FILENAME_PLAYLIST_SER = "downloadstate.ser"
const val ALBUM_ART_FILE = "folder.jpeg"
const val STARRED = "starred"

View File

@ -243,6 +243,8 @@ object Settings {
var useFiveStarRating by BooleanSetting(Constants.PREFERENCES_KEY_USE_FIVE_STAR_RATING, false)
var useHwOffload by BooleanSetting(Constants.PREFERENCES_KEY_HARDWARE_OFFLOAD, false)
// TODO: Remove in December 2022
fun migrateFeatureStorage() {
val sp = appContext.getSharedPreferences("feature_flags", Context.MODE_PRIVATE)

View File

@ -484,4 +484,8 @@
<string name="settings.five_star_rating_title">Use five star rating for songs</string>
<string name="settings.five_star_rating_description">Use five star rating system for songs instead of simply starring/unstarring items.</string>
<string name="settings.use_hw_offload_title">Use hardware playback (experimental)</string>
<string name="settings.use_hw_offload_description">Try to play the media using the media decoder chip on your phone. This can improve battery usage.</string>
</resources>

View File

@ -96,6 +96,12 @@
a:summary="@string/settings.five_star_rating_description"
a:title="@string/settings.five_star_rating_title"
app:iconSpaceReserved="false" />
<CheckBoxPreference
a:defaultValue="false"
a:key="use_hw_offload"
a:summary="@string/settings.use_hw_offload_description"
a:title="@string/settings.use_hw_offload_title"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
a:title="@string/settings.notifications_title"