Skip to content

Commit 0f1c47b

Browse files
fix(widget): clean leftover unused methods and restore notification lyric strings
1 parent 2637746 commit 0f1c47b

2 files changed

Lines changed: 4 additions & 130 deletions

File tree

app/src/main/java/org/akanework/gramophone/logic/GramophonePlaybackService.kt

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -890,136 +890,6 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
890890
}
891891
}
892892

893-
private fun createErrorNotificationChannel() {
894-
nm.createNotificationChannel(
895-
NotificationChannelCompat.Builder(
896-
NOTIFY_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_HIGH
897-
).apply {
898-
setName(getString(R.string.error_in_bg))
899-
setVibrationEnabled(true)
900-
setVibrationPattern(longArrayOf(0L, 200L))
901-
setLightsEnabled(false)
902-
setShowBadge(false)
903-
setSound(null, null)
904-
}.build()
905-
)
906-
}
907-
908-
private fun initCustomCommands(): List<CommandButton> = listOf(
909-
CommandButton.Builder(CommandButton.ICON_SHUFFLE_OFF)
910-
.setDisplayName(getString(R.string.shuffle))
911-
.setPlayerCommand(Player.COMMAND_SET_SHUFFLE_MODE, true)
912-
.build(),
913-
CommandButton.Builder(CommandButton.ICON_SHUFFLE_ON)
914-
.setDisplayName(getString(R.string.shuffle))
915-
.setPlayerCommand(Player.COMMAND_SET_SHUFFLE_MODE, false)
916-
.build(),
917-
CommandButton.Builder(CommandButton.ICON_REPEAT_OFF)
918-
.setDisplayName(getString(R.string.repeat_mode))
919-
.setPlayerCommand(Player.COMMAND_SET_REPEAT_MODE, Player.REPEAT_MODE_ALL)
920-
.build(),
921-
CommandButton.Builder(CommandButton.ICON_REPEAT_ALL)
922-
.setDisplayName(getString(R.string.repeat_mode))
923-
.setPlayerCommand(Player.COMMAND_SET_REPEAT_MODE, Player.REPEAT_MODE_ONE)
924-
.build(),
925-
CommandButton.Builder(CommandButton.ICON_REPEAT_ONE)
926-
.setDisplayName(getString(R.string.repeat_mode))
927-
.setPlayerCommand(Player.COMMAND_SET_REPEAT_MODE, Player.REPEAT_MODE_OFF)
928-
.build(),
929-
CommandButton.Builder(CommandButton.ICON_HEART_UNFILLED)
930-
.setDisplayName(getString(R.string.favorite))
931-
.setSessionCommand(SessionCommand(SessionCommand.COMMAND_CODE_SESSION_SET_RATING), HeartRating(true))
932-
.build(),
933-
CommandButton.Builder(CommandButton.ICON_HEART_FILLED)
934-
.setDisplayName(getString(R.string.unfavorite))
935-
.setSessionCommand(SessionCommand(SessionCommand.COMMAND_CODE_SESSION_SET_RATING), HeartRating(false))
936-
.build(),
937-
)
938-
939-
private fun initAfFormatTracker(): AfFormatTracker {
940-
return AfFormatTracker(this, playbackHandler, handler).apply {
941-
formatChangedCallback = { format, period ->
942-
if (period != null) {
943-
handler.post {
944-
val currentPeriod = endedWorkaroundPlayer?.exoPlayer?.currentPeriodIndex
945-
?.takeIf { it != C.INDEX_UNSET && (endedWorkaroundPlayer?.exoPlayer?.currentTimeline?.periodCount ?: 0) > it }
946-
?.let { endedWorkaroundPlayer!!.exoPlayer.currentTimeline.getUidOfPeriod(it) }
947-
if (currentPeriod != period) {
948-
if (format != null) pendingAfTrackFormats[period] = format
949-
else pendingAfTrackFormats.remove(period)
950-
} else {
951-
afTrackFormat = format?.let { period to it }
952-
mediaSession?.broadcastCustomCommand(
953-
SessionCommand(SERVICE_GET_AUDIO_FORMAT, Bundle.EMPTY),
954-
Bundle.EMPTY
955-
)
956-
}
957-
}
958-
} else {
959-
Log.e(TAG, "mediaPeriodId is NULL in formatChangedCallback!!")
960-
}
961-
}
962-
}
963-
}
964-
965-
private fun buildEndedWorkaroundPlayer(): EndedWorkaroundPlayer {
966-
val player = EndedWorkaroundPlayer(
967-
this,
968-
prefs,
969-
exoPlayer = ExoPlayer.Builder(
970-
this,
971-
GramophoneRenderFactory(
972-
this, rgAp, this::onAudioSinkInputFormatChanged,
973-
afFormatTracker::setAudioSink
974-
)
975-
.setEnableHighResolutionPcmOutput(true)
976-
.setEnableDecoderFallback(true)
977-
.setEnableAudioOutputPlaybackParameters(true)
978-
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON),
979-
GramophoneMediaSourceFactory(
980-
DefaultDataSource.Factory(this),
981-
GramophoneExtractorsFactory().also {
982-
it.setConstantBitrateSeekingEnabled(true)
983-
it.setMp3ExtractorFlags(Mp3Extractor.FLAG_ENABLE_INDEX_SEEKING)
984-
})
985-
)
986-
.setWakeMode(C.WAKE_MODE_LOCAL)
987-
.setAudioAttributes(
988-
AudioAttributes.Builder()
989-
.setUsage(C.USAGE_MEDIA)
990-
.setContentType(C.AUDIO_CONTENT_TYPE_MUSIC)
991-
.build(), true
992-
)
993-
.setHandleAudioBecomingNoisy(true)
994-
.setTrackSelector(DefaultTrackSelector(this).apply {
995-
setParameters(
996-
buildUponParameters()
997-
.setAllowInvalidateSelectionsOnRendererCapabilitiesChange(true)
998-
.setAudioOffloadPreferences(
999-
TrackSelectionParameters.AudioOffloadPreferences.Builder()
1000-
.apply {
1001-
val config = prefs.getStringStrict("offload", "0")?.toIntOrNull()
1002-
if (config != null && config > 0 && Flags.OFFLOAD) {
1003-
rgAp.setOffloadEnabled(true)
1004-
setAudioOffloadMode(TrackSelectionParameters.AudioOffloadPreferences.AUDIO_OFFLOAD_MODE_ENABLED)
1005-
setIsGaplessSupportRequired(config == 2)
1006-
}
1007-
}
1008-
.build()))
1009-
})
1010-
.setPlaybackLooper(internalPlaybackThread.looper)
1011-
.build(),
1012-
{ lyrics },
1013-
queueBoard = qb,
1014-
getNotificationLyric = { lastSentNotificationLyric }
1015-
)
1016-
player.exoPlayer.addAnalyticsListener(EventLogger())
1017-
player.exoPlayer.addAnalyticsListener(afFormatTracker)
1018-
player.exoPlayer.addAnalyticsListener(this)
1019-
player.exoPlayer.setShuffleOrder(CircularShuffleOrder(player, 0, 0, Random.nextLong()))
1020-
return player
1021-
}
1022-
1023893
// When destroying, we should release server side player
1024894
// alongside with the mediaSession.
1025895
override fun onDestroy() {

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@
392392
<string name="settings_status_bar_lyrics_title">Status bar lyrics</string>
393393
<!-- Settings toggle to enable showing lyrics in status bar (requires meizu phone). Subtext -->
394394
<string name="settings_status_bar_lyrics_summary">Enable MeiZu method of displaying lyrics in status bar (only available on some devices)</string>
395+
<!-- Settings toggle to enable showing lyrics in media notification. Title -->
396+
<string name="settings_notification_lyrics_title">Notification lyrics</string>
397+
<!-- Settings toggle to enable showing lyrics in media notification. Subtext -->
398+
<string name="settings_notification_lyrics_summary">Display lyrics as the notification title and artist - title as subtitle</string>
395399
<!-- Description shown about lyric widget in Android launcher / home screen's widget selector on Android 12+ -->
396400
<string name="lyric_widget_description">Widget that shows lyrics of currently playing media</string>
397401
<string name="card_widget_title">Card widget</string>

0 commit comments

Comments
 (0)