mirror of
https://github.com/IllusionMan1212/lyrics-grabbr.git
synced 2026-10-24 18:12:27 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
100157a8d4 |
+10
-11
@@ -56,10 +56,8 @@ class NotificationListener : NotificationListenerService() {
|
||||
}
|
||||
|
||||
override fun onNotificationPosted(sbn: StatusBarNotification) {
|
||||
if (sbn.packageName == SPOTIFY_PACKAGE) {
|
||||
sendNotificationBroadcast(sbn, applicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStopServiceNotificationAction(): PendingIntent {
|
||||
val intent = Intent(MainActivity.ACTION_NOTIFICATION_LISTENER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
@@ -70,7 +68,7 @@ class NotificationListener : NotificationListenerService() {
|
||||
private fun startForegroundService() {
|
||||
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle("Service Running")
|
||||
.setContentText("Play some songs on spotify to get lyrics")
|
||||
.setContentText("Play some songs on a supported player to get lyrics")
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setShowWhen(false)
|
||||
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
||||
@@ -103,19 +101,21 @@ class NotificationListener : NotificationListenerService() {
|
||||
private fun getCurrentNotifications(context: Context) {
|
||||
val sbns = activeNotifications
|
||||
for (sbn in sbns) {
|
||||
if (sbn.packageName == SPOTIFY_PACKAGE) {
|
||||
sendNotificationBroadcast(sbn, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendNotificationBroadcast(sbn: StatusBarNotification, context: Context) {
|
||||
// get the media session stuff
|
||||
val mediaSessionToken = sbn.notification.extras.getParcelable<MediaSession.Token>(Notification.EXTRA_MEDIA_SESSION)
|
||||
val mediaCtrl = mediaSessionToken?.let { MediaController(context, it) }
|
||||
val duration = mediaCtrl?.metadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.div(1000)
|
||||
val playbackState = mediaCtrl?.playbackState?.state
|
||||
val albumArt = mediaCtrl?.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||
if (mediaSessionToken == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val mediaCtrl = mediaSessionToken.let { MediaController(context, it) }
|
||||
val duration = mediaCtrl.metadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.div(1000)
|
||||
val playbackState = mediaCtrl.playbackState?.state
|
||||
val albumArt = mediaCtrl.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||
|
||||
// Retrieve package name to set as title.
|
||||
val packageName = sbn.packageName
|
||||
@@ -134,7 +134,7 @@ class NotificationListener : NotificationListenerService() {
|
||||
if (playbackState == PlaybackState.STATE_PAUSED) {
|
||||
val notification: Notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle("Service Running")
|
||||
.setContentText("Play some songs on spotify to get lyrics")
|
||||
.setContentText("Play some songs on a supported player to get lyrics")
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setShowWhen(false)
|
||||
.addAction(R.drawable.ic_notification, "Stop Service", getStopServiceNotificationAction())
|
||||
@@ -173,7 +173,6 @@ class NotificationListener : NotificationListenerService() {
|
||||
const val NOTIFICATION_PACKAGE_DURATION = "package_duration"
|
||||
const val NOTIFICATION_ID = 12251999
|
||||
const val NOTIFICATION_CHANNEL_ID = "Lyrics"
|
||||
const val SPOTIFY_PACKAGE = "com.spotify.music"
|
||||
const val START_FOREGROUND_SERVICE_ACTION = "START_SERVICE"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
|
||||
# Read more about iOS versioning at
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
version: 0.1.1+1
|
||||
version: 0.2.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.16.1 <3.0.0"
|
||||
|
||||
Reference in New Issue
Block a user