-
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] Update camera & microphone guide to use new device managers
- Loading branch information
1 parent
dbec2bc
commit 25d28e3
Showing
7 changed files
with
552 additions
and
228 deletions.
There are no files selected for viewing
83 changes: 0 additions & 83 deletions
83
Packages/StreamVideo/DocsCodeSamples/03-guides/CameraAndMicrophone.cs
This file was deleted.
Oops, something went wrong.
158 changes: 158 additions & 0 deletions
158
Packages/StreamVideo/DocsCodeSamples/03-guides/CameraAndMicrophone_Camera.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,158 @@ | ||
using System.Linq; | ||
using StreamVideo.Core; | ||
using StreamVideo.Core.DeviceManagers; | ||
using UnityEngine; | ||
using UnityEngine.Android; | ||
using UnityEngine.UI; | ||
|
||
namespace StreamVideoDocsCodeSamples._03_guides | ||
{ | ||
internal class CameraAndMicrophone_Camera : MonoBehaviour | ||
{ | ||
public void ListAvailableCameraDevices() | ||
{ | ||
var cameras = _client.VideoDeviceManager.EnumerateDevices(); | ||
|
||
foreach (var camera in cameras) | ||
{ | ||
Debug.Log(camera.Name); // Get camera name | ||
} | ||
} | ||
|
||
public void SelectCamera() | ||
{ | ||
// Get available camera devices. Returns IEnumerable<CameraDeviceInfo> | ||
var cameras = _client.VideoDeviceManager.EnumerateDevices(); | ||
|
||
foreach (var cam in cameras) | ||
{ | ||
Debug.Log(cam.Name); // Get the name of the camera | ||
} | ||
|
||
var camera = cameras.First(); | ||
|
||
_client.VideoDeviceManager.SelectDevice(camera, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, enable: true, requestedFPS: 24); | ||
|
||
|
||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_720p, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_720p, enable: true, requestedFPS: 30); | ||
} | ||
|
||
public void VideoResolutionValues() | ||
{ | ||
// Get available camera devices. Returns IEnumerable<CameraDeviceInfo> | ||
var cameras = _client.VideoDeviceManager.EnumerateDevices(); | ||
|
||
|
||
var camera = cameras.First(); | ||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_144p, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_240p, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_360p, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_480p, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_720p, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, VideoResolution.Res_1080p, enable: true); | ||
_client.VideoDeviceManager.SelectDevice(camera, new VideoResolution(500, 500), enable: true); | ||
} | ||
|
||
public void GetSelectedCamera() | ||
{ | ||
var selectedCamera = _client.VideoDeviceManager.SelectedDevice; | ||
} | ||
|
||
public void StartStopCamera() | ||
{ | ||
// Enable device to start capturing camera input | ||
_client.VideoDeviceManager.Enable(); | ||
|
||
// Disable device to stop capturing camera input | ||
_client.VideoDeviceManager.Disable(); | ||
|
||
// Set the enabled state by passing a boolean argument | ||
_client.VideoDeviceManager.SetEnabled(true); | ||
} | ||
|
||
public void GetLocalParticipantVideoPreview() | ||
{ | ||
var webCamTexture = _client.VideoDeviceManager.GetSelectedDeviceWebCamTexture(); | ||
|
||
// You can attach this texture to RawImage UI Component | ||
GetComponent<RawImage>().texture = webCamTexture; | ||
} | ||
|
||
public void GetLocalParticipantVideoPreviewFull() | ||
{ | ||
// Triggered when the selected devices changes | ||
_client.VideoDeviceManager.SelectedDeviceChanged += UpdateLocalParticipantPreview; | ||
} | ||
|
||
private void UpdateLocalParticipantPreview(CameraDeviceInfo previousDevice, CameraDeviceInfo currentDevice) | ||
{ | ||
var webCamTexture = _client.VideoDeviceManager.GetSelectedDeviceWebCamTexture(); | ||
|
||
// You can attach this texture to RawImage UI Component | ||
GetComponent<RawImage>().texture = webCamTexture; | ||
} | ||
|
||
public void CheckCameraStatus() | ||
{ | ||
// Check if currently selected device is enabled | ||
var isDeviceEnabled = _client.VideoDeviceManager.IsEnabled; | ||
} | ||
|
||
public void VideoDeviceManagerEvents() | ||
{ | ||
// Triggered when the selected devices changes | ||
_client.VideoDeviceManager.SelectedDeviceChanged += OnSelectedDeviceChanged; | ||
|
||
// Triggered when the IsEnabled property changes | ||
_client.VideoDeviceManager.IsEnabledChanged += OnIsEnabledChanged; | ||
} | ||
|
||
private void OnIsEnabledChanged(bool isEnabled) | ||
{ | ||
} | ||
|
||
private void OnSelectedDeviceChanged(CameraDeviceInfo previousDevice, CameraDeviceInfo currentDevice) | ||
{ | ||
} | ||
|
||
public void CameraTesting() | ||
{ | ||
var cameras = _client.VideoDeviceManager.EnumerateDevices(); | ||
var camera = cameras.First(); | ||
|
||
// Testing devices | ||
|
||
_client.VideoDeviceManager.TestDeviceAsync(camera); | ||
|
||
_client.VideoDeviceManager.TryFindFirstWorkingDeviceAsync(); | ||
} | ||
|
||
public void CameraIOSPermissions() | ||
{ | ||
// Request permission to use the Camera | ||
Application.RequestUserAuthorization(UserAuthorization.WebCam); | ||
|
||
// Check if user granted camera permission | ||
if (!Application.HasUserAuthorization(UserAuthorization.WebCam)) | ||
{ | ||
// Notify user that camera permission was not granted and the camera capturing will not work. | ||
} | ||
} | ||
|
||
public void CameraAndroidPermissions() | ||
{ | ||
// Request camera permissions | ||
Permission.RequestUserPermission(Permission.Camera); | ||
|
||
// Check if user granted camera permission | ||
if (!Permission.HasUserAuthorizedPermission(Permission.Camera)) | ||
{ | ||
// Notify user that camera permission was not granted and the camera capturing will not work. | ||
} | ||
} | ||
|
||
private IStreamVideoClient _client; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/StreamVideo/DocsCodeSamples/03-guides/CameraAndMicrophone_Camera.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
115 changes: 115 additions & 0 deletions
115
Packages/StreamVideo/DocsCodeSamples/03-guides/CameraAndMicrophone_Microphone.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,115 @@ | ||
using System.Linq; | ||
using StreamVideo.Core; | ||
using StreamVideo.Core.DeviceManagers; | ||
using UnityEngine; | ||
using UnityEngine.Android; | ||
|
||
namespace StreamVideoDocsCodeSamples._03_guides | ||
{ | ||
internal class CameraAndMicrophone_Microphone | ||
{ | ||
public void ListAvailableMicrophoneDevices() | ||
{ | ||
var microphones = _client.AudioDeviceManager.EnumerateDevices(); | ||
|
||
foreach (var mic in microphones) | ||
{ | ||
Debug.Log(mic.Name); // Get microphone name | ||
} | ||
} | ||
|
||
public void SelectMicrophone() | ||
{ | ||
// Get available microphone devices. Returns IEnumerable<MicrophoneDeviceInfo> | ||
var microphones = _client.AudioDeviceManager.EnumerateDevices(); | ||
|
||
foreach (var mic in microphones) | ||
{ | ||
Debug.Log(mic.Name); // Get the name of the microphone | ||
} | ||
|
||
var microphone = microphones.First(); | ||
|
||
// Select device for audio capturing. Pass the `enable` argument to control if capturing should be enabled | ||
_client.AudioDeviceManager.SelectDevice(microphone, enable: true); | ||
} | ||
|
||
public void GetSelectedMicrophone() | ||
{ | ||
var selectedMicrophone = _client.AudioDeviceManager.SelectedDevice; | ||
} | ||
|
||
public void StartStopMicrophone() | ||
{ | ||
// Enable device to start capturing microphone input | ||
_client.AudioDeviceManager.Enable(); | ||
|
||
// Disable device to stop capturing microphone input | ||
_client.AudioDeviceManager.Disable(); | ||
|
||
// Set the enabled state by passing a boolean argument | ||
_client.AudioDeviceManager.SetEnabled(true); | ||
} | ||
|
||
public void CheckMicrophoneStatus() | ||
{ | ||
// Check if currently selected device is enabled | ||
var isDeviceEnabled = _client.AudioDeviceManager.IsEnabled; | ||
} | ||
|
||
public void AudioDeviceManagerEvents() | ||
{ | ||
// Triggered when the selected devices changes | ||
_client.AudioDeviceManager.SelectedDeviceChanged += OnSelectedDeviceChanged; | ||
|
||
// Triggered when the IsEnabled property changes | ||
_client.AudioDeviceManager.IsEnabledChanged += OnIsEnabledChanged; | ||
} | ||
|
||
private void OnIsEnabledChanged(bool isEnabled) | ||
{ | ||
} | ||
|
||
private void OnSelectedDeviceChanged(MicrophoneDeviceInfo previousDevice, MicrophoneDeviceInfo currentDevice) | ||
{ | ||
} | ||
|
||
public void MicrophoneTesting() | ||
{ | ||
var microphones = _client.AudioDeviceManager.EnumerateDevices(); | ||
var microphone = microphones.First(); | ||
|
||
// Testing devices | ||
|
||
_client.AudioDeviceManager.TestDeviceAsync(microphone); | ||
|
||
_client.AudioDeviceManager.TryFindFirstWorkingDeviceAsync(); | ||
} | ||
|
||
public void MicrophoneIOSPermissions() | ||
{ | ||
// Request permission to use the Microphone | ||
Application.RequestUserAuthorization(UserAuthorization.Microphone); | ||
|
||
// Check if user granted microphone permission | ||
if (!Application.HasUserAuthorization(UserAuthorization.Microphone)) | ||
{ | ||
// Notify user that microphone permission was not granted and the microphone capturing will not work. | ||
} | ||
} | ||
|
||
public void MicrophoneAndroidPermissions() | ||
{ | ||
// Request microphone permissions | ||
Permission.RequestUserPermission(Permission.Microphone); | ||
|
||
// Check if user granted microphone permission | ||
if (!Permission.HasUserAuthorizedPermission(Permission.Microphone)) | ||
{ | ||
// Notify user that microphone permission was not granted and the microphone capturing will not work. | ||
} | ||
} | ||
|
||
private IStreamVideoClient _client; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.