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