Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to dot not cancel notification when player is paused and you close the app? #1353

Closed
xianyvbang opened this issue May 8, 2024 · 2 comments

Comments

@xianyvbang
Copy link

when i press pause and close the app, notification Invisible how to dot not cancel notification in code in this situation.

my code:

class ExampleLibraryPlaybackService : MediaLibraryService() {

    private var exoPlayer: ExoPlayer? = null
    private var mediaSession: MediaLibrarySession? = null
    @OptIn(DelicateCoroutinesApi::class)
    override fun onCreate() {
        super.onCreate()
        setMediaNotificationProvider(ExampleMediaNotificationProvider(this))
        val exoPlayerBuilder = ExoPlayer.Builder(this)
        exoPlayer = exoPlayerBuilder.build()
        val commandButtonExtras = Bundle()
        commandButtonExtras.putInt(
            DefaultMediaNotificationProvider.COMMAND_KEY_COMPACT_VIEW_INDEX,
            0
        )
        val sessionCommand = SessionCommand(SAVE_TO_FAVORITES, Bundle.EMPTY)
        val favoriteButton =
            CommandButton.Builder()
                .setEnabled(true)
                .setDisplayName("favorites")
                .setExtras(commandButtonExtras)
                .setIconResId(R.drawable.favorite)
                .setSessionCommand(sessionCommand)
                .build()

        val intent = packageManager.getLaunchIntentForPackage(packageName)
        intent?.putExtra("DESTINATION", "player")
        val pendingIntent = PendingIntent.getActivity(this, 0, intent, FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT)

        mediaSession =
            MediaLibrarySession.Builder(
                this,
                exoPlayer!!,
                object : MediaLibrarySession.Callback {
                  //......
                    
                })
                .setCustomLayout(ImmutableList.of(favoriteButton))
                .setSessionActivity(pendingIntent)
                .build()

    }
    override fun onDestroy() {
        exoPlayer?.stop()
        exoPlayer?.release()
        exoPlayer = null
        mediaSession?.release()
        mediaSession = null
        CacheController.release()

        super.onDestroy()
    }

    override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? {
        return mediaSession
    }
}

AndroidManifest.xml code:

<service
            android:name="cn.xybbz.common.music.ExampleLibraryPlaybackService"
            android:exported="true"
            android:foregroundServiceType="mediaPlayback">
            <intent-filter>
                <action android:name="androidx.media3.session.MediaSessionService" />
                <action android:name="android.media.browse.MediaBrowserService"/>
            </intent-filter>
        </service>
@icbaker
Copy link
Collaborator

icbaker commented May 8, 2024

Please can you provide more information:

  • What version of media3 are you using?
  • What versions of Android are you testing/observing on?
  • Please provide screenshots showing what you observe

@google-oss-bot
Copy link
Collaborator

Hey @xianyvbang. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants