Skip to content

Commit 4c733e9

Browse files
committed
Expose method to allow pausing/unpausing audio for android platform (needed e.g. when app is minimized)
1 parent 03266e2 commit 4c733e9

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

Packages/StreamVideo/Runtime/Core/IStreamVideoClient.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,18 @@ Task<IStreamCall> JoinCallAsync(StreamCallType callType, string callId, bool cre
106106
void SetAudioProcessingModule(bool enabled, bool echoCancellationEnabled, bool autoGainEnabled, bool noiseSuppressionEnabled, int noiseSuppressionLevel);
107107

108108
void GetAudioProcessingModuleConfig(out bool enabled, out bool echoCancellationEnabled, out bool autoGainEnabled, out bool noiseSuppressionEnabled, out int noiseSuppressionLevel);
109+
110+
111+
/// <summary>
112+
/// Temporary method (can be removed in the future) to pause audio playback on Android.
113+
/// This will completely suspend playback of any audio coming from the StreamVideo SDK on the Android platform.
114+
/// </summary>
115+
void PauseAndroidAudioPlayback();
116+
117+
/// <summary>
118+
/// Temporary method (can be removed in the future) to resume audio playback on Android.
119+
/// Call this resume audio playback if it was previously paused using <see cref="PauseAndroidAudioPlayback"/>.
120+
/// </summary>
121+
void ResumeAndroidAudioPlayback();
109122
}
110123
}

Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public async Task StartAsync(StreamCall call)
369369

370370
//StreamTodo: validate when this state should set
371371
CallState = CallingState.Joined;
372-
372+
373373
#if STREAM_DEBUG_ENABLED
374374
_videoAudioSyncBenchmark?.Init(call);
375375
#endif
@@ -434,7 +434,7 @@ public async Task StopAsync(string reason = "")
434434
{
435435
await _sfuWebSocket.DisconnectAsync(WebSocketCloseStatus.NormalClosure, reason);
436436
}
437-
437+
438438
CallState = CallingState.Offline;
439439

440440
#if STREAM_DEBUG_ENABLED
@@ -491,6 +491,30 @@ public void TryRestartAudioPlayback()
491491
#endif
492492
}
493493

494+
//StreamTODO: temp solution to allow stopping the audio when app is minimized. User tried disabling the AudioSource but the audio is handled natively so it has no effect
495+
public void PauseAndroidAudioPlayback()
496+
{
497+
#if STREAM_NATIVE_AUDIO
498+
WebRTC.StopAudioPlayback();
499+
_logs.Warning("Audio Playback is paused. This stops all audio coming from StreamVideo SDK on Android platform.");
500+
#else
501+
throw new NotSupportedException(
502+
$"{nameof(PauseAndroidAudioPlayback)} is only supported on Android platform.");
503+
#endif
504+
}
505+
506+
//StreamTODO: temp solution to allow stopping the audio when app is minimized. User tried disabling the AudioSource but the audio is handled natively so it has no effect
507+
public void ResumeAndroidAudioPlayback()
508+
{
509+
#if STREAM_NATIVE_AUDIO
510+
WebRTC.StartAudioPlayback(AudioOutputSampleRate, AudioOutputChannels);
511+
_logs.Warning("Audio Playback is resumed. This resumes audio coming from StreamVideo SDK on Android platform.");
512+
#else
513+
throw new NotSupportedException(
514+
$"{nameof(ResumeAndroidAudioPlayback)} is only supported on Android platform.");
515+
#endif
516+
}
517+
494518
/// <summary>
495519
/// Set Publisher Video track enabled/disabled, if track is available, or store the preference for when track becomes available
496520
/// </summary>

Packages/StreamVideo/Runtime/Core/StreamVideoClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ public void SetAudioProcessingModule(bool enabled, bool echoCancellationEnabled,
311311
#endif
312312
}
313313

314+
public void PauseAndroidAudioPlayback() => InternalLowLevelClient.RtcSession.PauseAndroidAudioPlayback();
315+
316+
public void ResumeAndroidAudioPlayback() => InternalLowLevelClient.RtcSession.ResumeAndroidAudioPlayback();
317+
314318
#region IStreamVideoClientEventsListener
315319

316320
event Action IStreamVideoClientEventsListener.Destroyed

0 commit comments

Comments
 (0)