diff --git a/demo-app/src/main/kotlin/io/getstream/video/android/util/StreamVideoInitHelper.kt b/demo-app/src/main/kotlin/io/getstream/video/android/util/StreamVideoInitHelper.kt index d7d2ed73e5..7d11d48e0e 100644 --- a/demo-app/src/main/kotlin/io/getstream/video/android/util/StreamVideoInitHelper.kt +++ b/demo-app/src/main/kotlin/io/getstream/video/android/util/StreamVideoInitHelper.kt @@ -191,6 +191,13 @@ object StreamVideoInitHelper { apiKey = apiKey, user = user, token = token, + loggingLevel = loggingLevel, + ensureSingleInstance = false, + notificationConfig = NotificationConfig( + pushDeviceGenerators = listOf( + FirebasePushDeviceGenerator(providerName = "firebase"), + ), + ), tokenProvider = { val email = user.custom?.get("email") val authData = StreamService.instance.getAuthData( @@ -199,13 +206,6 @@ object StreamVideoInitHelper { ) authData.token }, - loggingLevel = loggingLevel, - notificationConfig = NotificationConfig( - pushDeviceGenerators = listOf( - FirebasePushDeviceGenerator(providerName = "firebase"), - ), - ), - ensureSingleInstance = false, appName = "Stream Video Demo App", ).build() } diff --git a/docusaurus/docs/Android/06-advanced/01-ringing.mdx b/docusaurus/docs/Android/06-advanced/01-ringing.mdx index 0f34e9682c..eb8d079792 100644 --- a/docusaurus/docs/Android/06-advanced/01-ringing.mdx +++ b/docusaurus/docs/Android/06-advanced/01-ringing.mdx @@ -120,9 +120,67 @@ call.leave() The SDK plays sounds for incoming and outgoing calls. You can customize these sounds by passing your own instance of the `Sounds` class to the `StreamVideoBuilder` `sounds` constructor parameter. -`Sounds` has two resource properties, `incomingCallSoundResId` and `outgoingCallSoundResId`. These properties can have the following values: -- By default, their values are the device ringtone for incoming and a default ringing tone provided by the SDK for outgoing. -- You can pass raw resource identifiers that correspond to audio files in your project's `res/raw` directory. -- To disable (mute) one of the sounds, pass `null` to the corresponding property. -- You can pass the `Sounds.DEVICE_INCOMING_RINGTONE` special value to `incomingCallSoundResId` to use the device ringtone. -- Special cases: if the device ringtone is evaluated to `null` or the outgoing sound is set to `DEVICE_INCOMING_RINGTONE`, a corresponding default sound will be used. \ No newline at end of file +#### Deprecated method for customizing sounds + +`Sounds` has two properties, `incomingCallSound` and `outgoingCallSound`. You need to assign raw resource identifiers to these properties. These identifiers correspond to audio files in your project's `res/raw` directory. + +To disable sounds, pass `null` to `incomingCallSound` or `outgoingCallSound`. + +:::caution +This constructor of the `Sounds` class is deprecated. It should be replaced with the `Sounds(SoundConfig)` constructor. See the recommended method below. +::: + +#### Recommended method for customizing sounds + +`Sounds` has one property, `soundConfig` of type `SoundConfig`. + +The `SoundConfig` interface defines two properties: +- `incomingCallSoundUri`: The URI for the incoming call sound. +- `outgoingCallSoundUri`: The URI for the outgoing call sound. + +Also, `SoundConfig` provides several static factory methods to create sound configurations: +- `createDeviceRingtoneSoundConfig` - This method returns a `SoundConfig` that uses the device ringtone for incoming calls and the SDK default ringing tone for outgoing calls. +- `createStreamResourcesSoundConfig` - This method returns a `SoundConfig` that uses the SDK's default sounds for both incoming and outgoing calls. +- `createEmptySoundConfig` - Returns a `SoundConfig` that mutes (disables) all sounds. +- `createCustomSoundConfig` - This method allows you to specify custom sounds for incoming and outgoing calls. The sounds can be either `URI`s or resource ID `Int`s. If you use resource IDs, you **must** provide a context. + +:::note +By default, if you don't pass anything to the `sounds` builder parameter, the `createDeviceRingtoneSoundConfig` configuration is used. +::: + +##### Usage examples + +```kotlin +val soundConfig = SoundConfig.createCustomSoundConfig( + incomingCallSound = R.raw.custom_sound, + outgoingCallSound = customSoundUri, + context = context +) + +StreamVideoBuilder( + // ... + sounds = Sounds(soundConfig), + // ... +) +``` + +```kotlin +val baseSoundConfig = SoundConfig.createDeviceRingtoneSoundConfig(context) + +val mixedSoundConfig1 = SoundConfig.createCustomSoundConfig( + // Use device ringtone for incoming calls + incomingCallSound = baseSoundConfig.incomingCallSoundUri, + // Use custom sound for outgoing calls + outgoingCallSound = R.raw.call_busy_sound, + // Context needed as we're using a res ID + context = context +) + +val mixedSoundConfig2 = SoundConfig.createCustomSoundConfig( + // Use device ringtone for incoming calls + incomingCallSound = baseSoundConfig.incomingCallSoundUri, + // Mute the outgoing call sound + outgoingCallSound = null, + // Context not needed as we're not using any res ID +) +``` \ No newline at end of file diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/SoundConfig.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/SoundConfig.kt index 62df1c7734..fbe4aebaa2 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/SoundConfig.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/SoundConfig.kt @@ -23,7 +23,7 @@ import io.getstream.video.android.core.R import io.getstream.video.android.core.utils.safeCall /** - * Base sound configuration. + * Interface representing a sound configuration. * * @see createDeviceRingtoneSoundConfig * @see createStreamResourcesSoundConfig @@ -70,6 +70,11 @@ interface SoundConfig { getSoundUriFromRes(context, R.raw.call_outgoing_sound) } + /** + * Utility method that returns a sound URI from a resource ID. + * + * @return The sound URI or null if the resource ID is null or an exception occurred. + */ fun getSoundUriFromRes(context: Context, soundResId: Int?): Uri? = soundResId?.let { safeCall(default = null) { Uri.parse("android.resource://${context.packageName}/$soundResId") diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/Sounds.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/Sounds.kt index 13c38897b3..6bd632944a 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/Sounds.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/sounds/Sounds.kt @@ -41,7 +41,6 @@ constructor( ) { private var soundConfig: SoundConfig? = null - private set /** * Configure sounds by passing a [SoundConfig]. @@ -60,9 +59,7 @@ constructor( if (soundConfig != null) { soundConfig.incomingCallSoundUri } else { - incomingCallSound?.let { - Uri.parse("android.resource://${context.packageName}/$it") - } + incomingCallSound?.let { SoundConfig.getSoundUriFromRes(context, it) } } } @@ -70,9 +67,7 @@ constructor( if (soundConfig != null) { soundConfig.outgoingCallSoundUri } else { - outgoingCallSound?.let { - Uri.parse("android.resource://${context.packageName}/$it") - } + outgoingCallSound?.let { SoundConfig.getSoundUriFromRes(context, it) } } } }