diff --git a/new-player/src/main/java/net/newpipe/newplayer/NewPlayer.kt b/new-player/src/main/java/net/newpipe/newplayer/NewPlayer.kt index bad5b80..b5051d7 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/NewPlayer.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/NewPlayer.kt @@ -20,6 +20,7 @@ package net.newpipe.newplayer +import android.app.Activity import androidx.core.graphics.drawable.IconCompat import androidx.media3.common.MediaItem import androidx.media3.common.Player @@ -56,6 +57,7 @@ interface NewPlayer { val preferredAudioVariants: List val preferredStreamLanguage: List val notificationIcon: IconCompat + val playerActivityClass: Class val exoPlayer: StateFlow var playWhenReady: Boolean diff --git a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt index 9a39d0b..3a9390b 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt @@ -20,6 +20,7 @@ package net.newpipe.newplayer +import android.app.Activity import android.app.Application import android.content.ComponentName import android.util.Log @@ -59,6 +60,7 @@ private const val TAG = "NewPlayerImpl" class NewPlayerImpl( val app: Application, + override val playerActivityClass: Class, private val repository: MediaRepository, override val preferredVideoVariants: List = emptyList(), override val preferredStreamLanguage: List = emptyList(), @@ -69,7 +71,6 @@ class NewPlayerImpl( R.drawable.new_player_tiny_icon ), ) : NewPlayer { - private val mutableExoPlayer = MutableStateFlow(null) override val exoPlayer = mutableExoPlayer.asStateFlow() diff --git a/new-player/src/main/java/net/newpipe/newplayer/service/MediaNotification.kt b/new-player/src/main/java/net/newpipe/newplayer/service/MediaNotification.kt index d7aa95d..5a8e881 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/service/MediaNotification.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/service/MediaNotification.kt @@ -1,8 +1,11 @@ package net.newpipe.newplayer.service +import android.app.Activity import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager +import android.app.PendingIntent +import android.content.Intent import android.os.Build import androidx.annotation.OptIn import androidx.core.app.NotificationCompat @@ -15,12 +18,15 @@ import net.newpipe.newplayer.R const val NEW_PLAYER_MEDIA_NOTIFICATION_ID = 17480 const val NEW_PLAYER_MEDIA_NOTIFICATION_CHANNEL_NAME = "Player" +const val NEW_PLAYER_REQUEST_CODE_OPEN_ACTIVITY = 0 + @OptIn(UnstableApi::class) fun createNewPlayerNotification( service: NewPlayerService, session: MediaSession, notificationManager: NotificationManager, - notificationIcon: IconCompat + notificationIcon: IconCompat, + playerActivity: Class ): Notification { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -34,11 +40,21 @@ fun createNewPlayerNotification( } + val onNotificationClickIntent = Intent(service, playerActivity) + val onNotificationClickPendingIntent = + PendingIntent.getActivity( + service, + NEW_PLAYER_REQUEST_CODE_OPEN_ACTIVITY, + onNotificationClickIntent, + PendingIntent.FLAG_IMMUTABLE + ) + val notificationBuilder = NotificationCompat.Builder(service, NEW_PLAYER_MEDIA_NOTIFICATION_CHANNEL_NAME) .setContentTitle(service.resources.getString(R.string.new_player_name)) .setContentText(service.resources.getString(R.string.playing_in_background)) .setStyle(MediaStyleNotificationHelper.MediaStyle(session)) + .setContentIntent(onNotificationClickPendingIntent) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { notificationBuilder.setSmallIcon(notificationIcon) diff --git a/new-player/src/main/java/net/newpipe/newplayer/service/NewPlayerService.kt b/new-player/src/main/java/net/newpipe/newplayer/service/NewPlayerService.kt index 61a104b..f673f44 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/service/NewPlayerService.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/service/NewPlayerService.kt @@ -78,7 +78,8 @@ class NewPlayerService : MediaSessionService() { notificationManager = getSystemService( Context.NOTIFICATION_SERVICE ) as NotificationManager, - notificationIcon = newPlayer.notificationIcon + notificationIcon = newPlayer.notificationIcon, + playerActivity = newPlayer.playerActivityClass ) return MediaNotification(NEW_PLAYER_MEDIA_NOTIFICATION_ID, notification) diff --git a/test-app/src/main/java/net/newpipe/newplayer/testapp/NewPlayerComponent.kt b/test-app/src/main/java/net/newpipe/newplayer/testapp/NewPlayerComponent.kt index 46200bc..debf8ce 100644 --- a/test-app/src/main/java/net/newpipe/newplayer/testapp/NewPlayerComponent.kt +++ b/test-app/src/main/java/net/newpipe/newplayer/testapp/NewPlayerComponent.kt @@ -20,6 +20,7 @@ package net.newpipe.newplayer.testapp +import android.app.Activity import android.app.Application import android.util.Log import androidx.core.graphics.drawable.IconCompat @@ -40,9 +41,10 @@ object NewPlayerComponent { @Singleton fun provideNewPlayer(app: Application): NewPlayer { val player = NewPlayerImpl( - app, - TestMediaRepository(app), - notificationIcon = IconCompat.createWithResource(app, R.drawable.tinny_cools) + app = app, + repository = TestMediaRepository(app), + notificationIcon = IconCompat.createWithResource(app, R.drawable.tinny_cools), + playerActivityClass = MainActivity::class.java as Class ) if (app is NewPlayerApp) { app.appScope.launch {