@@ -33,7 +33,6 @@ import android.media.audiofx.AudioEffect
3333import android.net.Uri
3434import android.os.Build
3535import android.os.Bundle
36- import android.os.Bundle.EMPTY
3736import android.os.Handler
3837import android.os.HandlerThread
3938import android.os.Looper
@@ -243,6 +242,7 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
243242 }
244243
245244 override fun onCreate () {
245+ Log .i(TAG , " onCreate()" )
246246 super .onCreate()
247247 instanceForWidgetAndLyricsOnly = this
248248 internalPlaybackThread.start()
@@ -316,8 +316,8 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
316316 afFormatTracker = AfFormatTracker (this , playbackHandler, handler)
317317 afFormatTracker.formatChangedCallback = {
318318 mediaSession?.broadcastCustomCommand(
319- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
320- EMPTY
319+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
320+ Bundle . EMPTY
321321 )
322322 }
323323 val player = EndedWorkaroundPlayer (
@@ -450,8 +450,8 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
450450 Log .d(TAG , " first bluetooth codec config $btInfo " )
451451 btInfo = it
452452 mediaSession?.broadcastCustomCommand(
453- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
454- EMPTY
453+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
454+ Bundle . EMPTY
455455 )
456456 }
457457 }
@@ -495,6 +495,7 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
495495 // When destroying, we should release server side player
496496 // alongside with the mediaSession.
497497 override fun onDestroy () {
498+ Log .i(TAG , " onDestroy()" )
498499 instanceForWidgetAndLyricsOnly = null
499500 unregisterReceiver(headSetReceiver)
500501 unregisterReceiver(seekReceiver)
@@ -551,8 +552,8 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
551552 Bundle .EMPTY
552553 )
553554 mediaSession?.broadcastCustomCommand(
554- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
555- EMPTY
555+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
556+ Bundle . EMPTY
556557 )
557558 }
558559
@@ -701,13 +702,33 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
701702 settable.setException(
702703 IndexOutOfBoundsException (
703704 " LastPlayedManager restored empty MediaItemsWithStartPosition"
704- ). also { Log .e( TAG , Log .getStackTraceString(it)) }
705+ )
705706 )
706707 }
707708 }
708709 return settable
709710 }
710711
712+ /* override fun onGetLibraryRoot(
713+ session: MediaLibrarySession,
714+ browser: MediaSession.ControllerInfo,
715+ params: LibraryParams?
716+ ): ListenableFuture<LibraryResult<MediaItem>> {
717+ val outParams = LibraryParams.Builder()
718+ .setOffline(true)
719+ .setSuggested(false)
720+ .setRecent(false)
721+ .build()
722+ val item = MediaItem.Builder()
723+ .setMediaId("root")
724+ .setMediaMetadata(MediaMetadata.Builder()
725+ .setIsBrowsable(true)
726+ .setIsPlayable(false)
727+ .build())
728+ .build()
729+ return Futures.immediateFuture(LibraryResult.ofItem(item, outParams))
730+ }*/
731+
711732 override fun onTracksChanged (eventTime : AnalyticsListener .EventTime , tracks : Tracks ) {
712733 val mediaItem = controller!! .currentMediaItem
713734
@@ -780,8 +801,8 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
780801 audioTrackInfoCounter++
781802 audioTrackInfo = AudioTrackInfo .fromMedia3AudioTrackConfig(audioTrackConfig)
782803 mediaSession?.broadcastCustomCommand(
783- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
784- EMPTY
804+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
805+ Bundle . EMPTY
785806 )
786807 }
787808
@@ -794,8 +815,8 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
794815 if (++ audioTrackReleaseCounter == audioTrackInfoCounter) {
795816 audioTrackInfo = null
796817 mediaSession?.broadcastCustomCommand(
797- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
798- EMPTY
818+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
819+ Bundle . EMPTY
799820 )
800821 }
801822 }
@@ -806,25 +827,25 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
806827 ) {
807828 downstreamFormat = mediaLoadData.trackFormat
808829 mediaSession?.broadcastCustomCommand(
809- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
810- EMPTY
830+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
831+ Bundle . EMPTY
811832 )
812833 }
813834
814835 private fun onAudioSinkInputFormatChanged (inputFormat : Format ? ) {
815836 audioSinkInputFormat = inputFormat
816837 mediaSession?.broadcastCustomCommand(
817- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
818- EMPTY
838+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
839+ Bundle . EMPTY
819840 )
820841 }
821842
822843 override fun onPlaybackStateChanged (eventTime : AnalyticsListener .EventTime , state : Int ) {
823844 if (state == Player .STATE_IDLE ) {
824845 downstreamFormat = null
825846 mediaSession?.broadcastCustomCommand(
826- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
827- EMPTY
847+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
848+ Bundle . EMPTY
828849 )
829850 }
830851 }
@@ -838,8 +859,8 @@ class GramophonePlaybackService : MediaLibraryService(), MediaSessionService.Lis
838859 bitrateFetcher.launch {
839860 bitrate = mediaItem?.getBitrate() // TODO subtract cover size
840861 this @GramophonePlaybackService.mediaSession?.broadcastCustomCommand(
841- SessionCommand (SERVICE_GET_AUDIO_FORMAT , EMPTY ),
842- EMPTY
862+ SessionCommand (SERVICE_GET_AUDIO_FORMAT , Bundle . EMPTY ),
863+ Bundle . EMPTY
843864 )
844865 }
845866 lyrics = null
0 commit comments