-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs] Add info on how to update audio & video input sources during t…
…he call
- Loading branch information
1 parent
b52ffca
commit 240c496
Showing
3 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
Packages/StreamVideo/DocsCodeSamples/03-guides/CameraAndMicrophone.cs
This file contains 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,83 @@ | ||
using System.Linq; | ||
using StreamVideo.Core; | ||
using UnityEngine; | ||
|
||
namespace DocsCodeSamples._03_guides | ||
{ | ||
internal class CameraAndMicrophone : MonoBehaviour | ||
{ | ||
public void SetupMicrophoneInput() | ||
{ | ||
// Obtain reference to an AudioSource that will be used a source of audio | ||
var inputAudioSource = GetComponent<AudioSource>(); | ||
|
||
// Get a valid microphone device name. | ||
// You usually want to populate a dropdown list with Microphone.devices so that the user can pick which device should be used | ||
_activeMicrophoneDeviceName = Microphone.devices.First(); | ||
|
||
inputAudioSource.clip | ||
= Microphone.Start(_activeMicrophoneDeviceName, true, 3, AudioSettings.outputSampleRate); | ||
inputAudioSource.loop = true; | ||
inputAudioSource.Play(); | ||
|
||
_client.SetAudioInputSource(inputAudioSource); | ||
} | ||
|
||
public void ChangeMicrophoneDevice() | ||
{ | ||
var newMicrophoneDeviceName = "test"; | ||
|
||
// Stop previously active microphone | ||
Microphone.End(_activeMicrophoneDeviceName); | ||
|
||
// Obtain reference to an AudioSource that was setup as an input source | ||
var inputAudioSource = GetComponent<AudioSource>(); | ||
|
||
inputAudioSource.clip = Microphone.Start(newMicrophoneDeviceName, true, 3, AudioSettings.outputSampleRate); | ||
} | ||
|
||
public void SetupCameraInput() | ||
{ | ||
// Obtain a camera device | ||
var cameraDevice = WebCamTexture.devices.First(); | ||
|
||
// Use device name to create a new WebCamTexture instance | ||
var activeCamera = new WebCamTexture(cameraDevice.name); | ||
|
||
// Call Play() in order to start capturing the video | ||
activeCamera.Play(); | ||
|
||
// Set WebCamTexture in Stream's Client - this WebCamTexture will be the video source in video calls | ||
_client.SetCameraInputSource(activeCamera); | ||
} | ||
|
||
public void ChangeVideoDevice() | ||
{ | ||
// Item from WebCamTexture.devices | ||
var newDeviceName = "deviceName"; | ||
|
||
_activeCamera.Stop(); | ||
_activeCamera.deviceName = newDeviceName; | ||
_activeCamera.Play(); | ||
} | ||
|
||
public void UpdateCameraInputSource() | ||
{ | ||
// Obtain a camera device | ||
var cameraDevice = WebCamTexture.devices.First(); | ||
|
||
// Use device name to create a new WebCamTexture instance | ||
var activeCamera = new WebCamTexture(cameraDevice.name); | ||
|
||
// Call Play() in order to start capturing the video | ||
activeCamera.Play(); | ||
|
||
_client.SetCameraInputSource(activeCamera); | ||
} | ||
|
||
private IStreamVideoClient _client; | ||
private string _activeMicrophoneDeviceName; | ||
|
||
private WebCamTexture _activeCamera; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/StreamVideo/DocsCodeSamples/03-guides/CameraAndMicrophone.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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