Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ dependencies {
compileOnly(project(":stream-video-android-previewdata"))


implementation(libs.androidx.media.media)


implementation(libs.androidx.media.media)

// Noise Cancellation
Expand Down
6 changes: 6 additions & 0 deletions demo-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
</intent-filter>
</activity>

<receiver android:name="androidx.media.session.MediaButtonReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
<!-- Prevent firebase from using advertisement ID -->
<meta-data
android:name="google_analytics_adid_collection_enabled"
Expand Down
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
Comment thread
aleksandar-apostolov marked this conversation as resolved.
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
}
}
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ import io.getstream.chat.android.state.plugin.config.StatePluginConfig
import io.getstream.chat.android.state.plugin.factory.StreamStatePluginFactory
import io.getstream.log.Priority
import io.getstream.video.android.BuildConfig
import io.getstream.video.android.app
import io.getstream.video.android.core.StreamVideo
import io.getstream.video.android.core.StreamVideoBuilder
import io.getstream.video.android.core.internal.ExperimentalStreamVideoApi
import io.getstream.video.android.core.logging.LoggingLevel
import io.getstream.video.android.core.notifications.NotificationConfig
import io.getstream.video.android.core.notifications.handlers.CompatibilityStreamNotificationHandler
import io.getstream.video.android.core.notifications.internal.service.CallServiceConfigRegistry
import io.getstream.video.android.core.notifications.internal.service.DefaultCallConfigurations
import io.getstream.video.android.core.socket.common.token.TokenProvider
Expand All @@ -40,6 +43,8 @@ import io.getstream.video.android.datastore.delegate.StreamUserDataStore
import io.getstream.video.android.model.ApiKey
import io.getstream.video.android.model.User
import io.getstream.video.android.noise.cancellation.NoiseCancellation
import io.getstream.video.android.notification.LiveStreamMediaNotificationInterceptor
import io.getstream.video.android.notification.PausePlayMediaSessionCallback
import io.getstream.video.android.util.config.AppConfig
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -185,6 +190,7 @@ object StreamVideoInitHelper {
}

/** Sets up and returns the [StreamVideo] required to connect to the API. */
@OptIn(ExperimentalStreamVideoApi::class)
private fun initializeStreamVideo(
context: Context,
apiKey: ApiKey,
Expand Down Expand Up @@ -212,6 +218,12 @@ object StreamVideoInitHelper {
),
),
hideRingingNotificationInForeground = true,
notificationHandler = CompatibilityStreamNotificationHandler(
application = context.app,
mediaSessionCallback = PausePlayMediaSessionCallback(),
updateNotificationBuilderInterceptor = LiveStreamMediaNotificationInterceptor(context),
hideRingingNotificationInForeground = true,
),
),
tokenProvider = object : TokenProvider {
override suspend fun loadToken(): String {
Expand Down