Skip to content

Commit

Permalink
[Docs] Update camera & microphone guide to use new device managers
Browse files Browse the repository at this point in the history
  • Loading branch information
sierpinskid committed Apr 26, 2024
1 parent dbec2bc commit 25d28e3
Show file tree
Hide file tree
Showing 7 changed files with 552 additions and 228 deletions.

This file was deleted.

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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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;
}
}
Loading

0 comments on commit 25d28e3

Please sign in to comment.