@@ -86,7 +86,7 @@ class MediaNotificationListener : NotificationListenerService() {
8686 fun getMediaInfo (context : Context ): MediaInfo {
8787 // Respect global toggle; if disabled, return empty media
8888 if (! isNowPlayingEnabled) {
89- return MediaInfo (false , " " , " " , null , " none" )
89+ return MediaInfo (false , " " , " " , null , null , 0L , 0L , 0L , false , " none" )
9090 }
9191 return try {
9292 val mediaSessionManager =
@@ -119,6 +119,14 @@ class MediaNotificationListener : NotificationListenerService() {
119119 val title = metadata?.getString(MediaMetadata .METADATA_KEY_TITLE ) ? : " "
120120 val artist = metadata?.getString(MediaMetadata .METADATA_KEY_ARTIST ) ? : " "
121121 val isPlaying = playbackState?.state == PlaybackState .STATE_PLAYING
122+ val durationMs = metadata?.getLong(MediaMetadata .METADATA_KEY_DURATION ) ? : 0L
123+ val positionMs = playbackState?.position ? : 0L
124+ val positionTimestampMs = System .currentTimeMillis()
125+ val isBuffering = when (playbackState?.state) {
126+ PlaybackState .STATE_BUFFERING ,
127+ PlaybackState .STATE_CONNECTING -> true
128+ else -> false
129+ }
122130
123131 val albumArtBitmap =
124132 metadata?.getBitmap(MediaMetadata .METADATA_KEY_ALBUM_ART )
@@ -166,6 +174,10 @@ class MediaNotificationListener : NotificationListenerService() {
166174 artist = artist,
167175 albumArt = albumArtBase64,
168176 albumArtLite = albumArtLiteBase64,
177+ durationMs = durationMs,
178+ positionMs = positionMs,
179+ positionTimestampMs = positionTimestampMs,
180+ isBuffering = isBuffering,
169181 likeStatus = likeStatus
170182 )
171183 }
@@ -181,10 +193,10 @@ class MediaNotificationListener : NotificationListenerService() {
181193 }
182194
183195 // Log.d(TAG, "No media info found")
184- MediaInfo (false , " " , " " , null , " none" )
196+ MediaInfo (false , " " , " " , null , null , 0L , 0L , 0L , false , " none" )
185197 } catch (e: Exception ) {
186198 Log .e(TAG , " Error getting media info: ${e.message} " )
187- MediaInfo (false , " " , " " , null , " none" )
199+ MediaInfo (false , " " , " " , null , null , 0L , 0L , 0L , false , " none" )
188200 }
189201 }
190202
0 commit comments