-
Notifications
You must be signed in to change notification settings - Fork 58
Add media Play / Pause actions for the livestream notification
#1461
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
Merged
aleksandar-apostolov
merged 14 commits into
develop
from
media-notification-handler-demo-app
Jul 29, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ba338e6
Manage mediaSession objects separately
aleksandar-apostolov 309faea
Update test
aleksandar-apostolov ff56bbc
Spotless & API
aleksandar-apostolov 1655c1e
Update to use client scope for updates
aleksandar-apostolov 35fcc26
Add pause/play action in demo app
aleksandar-apostolov f1d0048
Enable custom callback and interceptor
aleksandar-apostolov 78619ac
Remove delay
aleksandar-apostolov 8e66c3a
Merge branch 'develop' into media-notification-handler
aleksandar-apostolov 17dc221
Allow overriding media style
aleksandar-apostolov fcc793b
Merge branch 'media-notification-handler' into media-notification-han…
aleksandar-apostolov 2843f1d
Remove duration
aleksandar-apostolov a038c5a
Merge branch 'develop' into media-notification-handler-demo-app
aleksandar-apostolov 5f6243a
Merge branch 'develop' into media-notification-handler-demo-app
aleksandar-apostolov b243098
Merge branch 'develop' into media-notification-handler-demo-app
aleksandar-apostolov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../kotlin/io/getstream/video/android/notification/LiveStreamMediaNotificationInterceptor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.video.android.notification | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.Bitmap | ||
| import android.graphics.BitmapFactory | ||
| import android.support.v4.media.MediaMetadataCompat | ||
| import android.support.v4.media.session.PlaybackStateCompat | ||
| import android.util.Log | ||
| import androidx.core.app.NotificationCompat | ||
| import androidx.media.session.MediaButtonReceiver | ||
| import io.getstream.video.android.R | ||
| import io.getstream.video.android.core.Call | ||
| import io.getstream.video.android.core.notifications.handlers.StreamNotificationUpdateInterceptors | ||
| import java.net.URL | ||
|
|
||
| class LiveStreamMediaNotificationInterceptor(private val context: Context) : StreamNotificationUpdateInterceptors() { | ||
| private var bitmap: Bitmap? = null | ||
|
|
||
| override suspend fun onUpdateMediaNotificationPlaybackState( | ||
| builder: PlaybackStateCompat.Builder, | ||
| call: Call, | ||
| callDisplayName: String?, | ||
| ): PlaybackStateCompat.Builder { | ||
| builder.setActions( | ||
| PlaybackStateCompat.ACTION_PLAY or PlaybackStateCompat.ACTION_PAUSE, | ||
| ) | ||
| return builder | ||
| } | ||
|
|
||
| override suspend fun onUpdateOngoingCallMediaNotification( | ||
| builder: NotificationCompat.Builder, | ||
| callDisplayName: String?, | ||
| call: Call, | ||
| ): NotificationCompat.Builder { | ||
| val bitmap = getStreamLogoBitmap() | ||
| if (bitmap != null) { | ||
| builder.setLargeIcon(bitmap) | ||
| } | ||
|
|
||
| val playAction = NotificationCompat.Action( | ||
| android.R.drawable.ic_media_play, | ||
| "Play", | ||
| MediaButtonReceiver.buildMediaButtonPendingIntent( | ||
| context, | ||
| PlaybackStateCompat.ACTION_PLAY, | ||
| ), | ||
| ) | ||
|
|
||
| val pauseAction = NotificationCompat.Action( | ||
| android.R.drawable.ic_media_pause, | ||
| "Pause", | ||
| MediaButtonReceiver.buildMediaButtonPendingIntent( | ||
| context, | ||
| PlaybackStateCompat.ACTION_PAUSE, | ||
| ), | ||
| ) | ||
| builder.addAction(playAction) | ||
| builder.addAction(pauseAction) | ||
|
|
||
| return builder | ||
| } | ||
|
|
||
| override suspend fun onUpdateMediaNotificationMetadata( | ||
| builder: MediaMetadataCompat.Builder, | ||
| call: Call, | ||
| callDisplayName: String?, | ||
| ): MediaMetadataCompat.Builder { | ||
| val bitmap = getStreamLogoBitmap() | ||
| if (bitmap != null) { | ||
| Log.d("StreamVideoInitHelper", "Loaded image") | ||
| builder.putBitmap( | ||
| MediaMetadataCompat.METADATA_KEY_ALBUM_ART, | ||
| bitmap, | ||
| ) | ||
| } | ||
| return builder | ||
| } | ||
|
|
||
| private fun getStreamLogoBitmap(): Bitmap? { | ||
| if (bitmap == null) { | ||
| bitmap = try { | ||
| URL("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ8dzj-6rSfEfYMOXPSCV3s84Luuqr2c9KzMg&s").openStream() | ||
| .use { BitmapFactory.decodeStream(it) } | ||
| } catch (e: Exception) { | ||
| // Fallback | ||
| BitmapFactory.decodeResource(context.resources, R.drawable.stream_calls_logo) | ||
| } | ||
| } | ||
| return bitmap | ||
| } | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
.../src/main/kotlin/io/getstream/video/android/notification/PausePlayMediaSessionCallback.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.video.android.notification | ||
|
|
||
| import android.support.v4.media.session.MediaSessionCompat | ||
| import android.util.Log | ||
| import io.getstream.video.android.core.StreamVideo | ||
|
|
||
| /** | ||
| * Callback for media session. | ||
| */ | ||
| class PausePlayMediaSessionCallback : MediaSessionCompat.Callback() { | ||
|
|
||
| override fun onPause() { | ||
| Log.d("StreamVideoInitHelper", "Pause") | ||
| StreamVideo.instanceOrNull()?.state?.activeCall?.value?.debug?.pause() | ||
| super.onPause() | ||
| } | ||
|
|
||
| override fun onPlay() { | ||
| Log.d("StreamVideoInitHelper", "Play") | ||
| StreamVideo.instanceOrNull()?.state?.activeCall?.value?.debug?.resume() | ||
| super.onPlay() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.