# Preview Before and after joining a session, you can give users a preview of their video and audio by starting the camera and microphone locally. ## Preview camera To preview a camera, filter through the available camera and subscribe to it with your defined view using the video helper interface. ```swift if let videoHelper = ZMVideoSDK.shareInstance()?.getVideoHelper() { // Get the camera list and select the camera you want to preview. let cameraList = videoHelper.getCameraList() // Use the first camera as an example let selectedCamera = cameralist[0] // Start preview: viewForVideoPreview is an example of an UIView defined earlier videoHelper.startVideoCanvasPreview(viewForVideoPreview, deviceID: selectedCamera.deviceID) // Stop preview videoHelper.stopVideoCanvasPreview(viewForVideoPreview) } ``` ```objectivec ZMVideoSDKVideoHelper *videoHelper = [[ZMVideoSDK sharedVideoSDK] getVideoHelper()]; // Get the camera list and select the camera you want to preview. NSArray *cameraList = [videoHelper getCameraList()]; // Use the first camera as an example ZMVideoSDKCameraDevice *selectedCamera = cameraList[0]; // Start preview: viewForVideoPreview is an example of an UIView defined earlier [videoHelper startVideoCanvasPreview:viewForVideoPreview deviceID:selectedCamera.deviceID]; // Stop preview [videoHelper stopVideoCanvasPreview:viewForVideoPreview]; ``` ## Preview audio See the following restrictions and prerequisites for testing the microphone and speakers. ### Restriction Users can only test their audio after joining a session with the SDK, for example, if they're in a waiting room. ### Prerequisites - Video SDK Account - Microphone, such as the built in microphone, a USB microphone (if supported), or an inline microphone on headphones - Speaker or headphones ### Preview microphone 1. Override the following two callbacks in `ZMVideoSDKDelegate`. For example, when the volume changes (available levels are from 0 to 10). See step 3 and for 4 more details. ```swift public func onMicSpeakerVolumeChanged(_ micVolume: UInt32, speakerVolume: UInt32) { // TODO } public func onTestMicStatusChanged(_ status: ZMVideoSDKMicTestStatus) { // TODO } ``` ```objectivec - (void)onMicSpeakerVolumeChanged:(unsigned int)micVolume speakerVolume:(unsigned int)speakerVolume { //TO DO } - (void)onTestMicStatusChanged:(ZMVideoSDKMicTestStatus)status { //TO DO } ``` 2. Start a microphone testing session. Define the microphone `deviceId` in `startMicTestRecording`. ```swift // Use AudioHelper to get the microphone list and select the microphone you want to preview. // Use AudioDeviceTestHelper to start/stop/playback the selected microphone if let audioHelper = ZMVideoSDK.sharedVideoSDK()?.getAudioHelper(), let audioDeviceTestHelper = ZMVideoSDK.sharedVideoSDK()?.getAudioDeviceTestHelper { // Get microphone list and select first one as an example let micList = audioHelper.getMicList() let selectedMic = micList[0] // Start microphone audioDeviceTestHelper.startMicTestRecording(selectedMic.deviceId) //... } ``` ```objectivec // Use AudioHelper to get the microphone list and select the microphone you want to preview. ZMVideoSDKAudioHelper *audioHelper = [[ZMVideoSDK sharedVideoSDK] getAudioHelper()]; NSArray *micList = [audioHelper getMicList()]; // Use the first microphone as an example ZMVideoSDKMicDevice *selectedMicrophone = micList[0]; ZMVideoSDKAudioDeviceTestHelper* testAudioDeviceHelper = [[ZMVideoSDK sharedVideoSDK] getAudioDeviceTestHelper()]; ZMVideoSDKErrors err = [testAudioDeviceHelper startMicTestRecording:selectedMicrophone.deviceId]; ``` 3. After calling `startMicTestRecording`, the microphone will start recording for 6 seconds. During this time, you'll receive the callback `onMicSpeakerVolumeChanged` with the microphone volume. When the recording stops, you'll receive the callback `onTestMicStatusChanged` with the status `ZMVideoSDKMicTestStatus_CanPlay`. Once you receive the status, you'll be able to start playing the microphone recording. ```swift //... let error = audioDeviceTestHelper.playMicTestRecording() //... ``` ```objectivec ZMVideoSDKErrors err = [testAudioDeviceHelper playMicTestRecording]; ``` 4. When the microphone recording is played, you'll receive the callback `onTestMicStatusChanged` with the status `ZMVideoSDKMicTestStatus_CanTest`. After receiving this status, call `startMicTestRecording` again if needed. 5. To finish the microphone testing session, call `stopMicTestRecording`. ```swift //... let error = audioDeviceTestHelper.stopMicTestRecording() } ``` ```objectivec ZMVideoSDKErrors err = [testAudioDeviceHelper stopMicTestRecording]; ``` ### Preview speakers Zoom Video SDK currently only supports MP3 files for speaker tests. The size of the file cannot exceed 1 MB. You must add your own MP3 file and make it accessible from the user's device when they run the test. Follow these steps to configure and run the test. 1. Add the MP3 file to your project. 2. Ensure that the user's device can access the MP3 file to use for the test. Define the speaker test audio file path in `ZMVideoSDKInitParams`, create a `ZMVideoSDKExtendParams`, and add the MP3 file path under its `speakerTestFilePath` variable. Be sure that the path is valid and not null. ```swift // Setup for speaker test - E.g. test.mp3 let extendParam = ZMVideoSDKExtendParams() let bundle = Bundle.main extendParam.speakerTestFilePath = bundle.path(forResource: "test", ofType: "mp3") ``` ```objectivec // Setup for speaker test - E.g. test.mp3 ZMVideoSDKInitParams *initParams = [[ZMVideoSDKInitParams alloc] init]; ZMVideoSDKExtendParams *extendParams = [[ZMVideoSDKExtendParams alloc] init]; NSString *lpath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp3"]; extendParams.speakerTestFilePath = lpath; ``` 3. Under the same `ZMVideoSDKInitParams`, which is used to set the domain and enable the log, add the `ZMVideoSDKExtendParams` variable under its `extendParam`. Then get the helper to test the speaker. ```swift // Add the extendParams to ZMVideoSDKInitParams params initParams.extendParam = extendParam // Use AudioHelper to get the speaker list and select the speaker you want to preview. // Use AudioDeviceTestHelper to start/stop the selected speaker if let audioHelper = ZMVideoSDK.sharedVideoSDK()?.getAudioHelper(), let audioDeviceTestHelper = ZMVideoSDK.sharedVideoSDK()?.getAudioDeviceTestHelper { //... } ``` ```objectivec // Add the extendParams to ZMVideoSDKInitParams params params.extendParams = extendParams; // Use AudioHelper to get the speaker list and select the speaker you want to preview. ZMVideoSDKAudioHelper *audioHelper = [[ZMVideoSDK sharedVideoSDK] getAudioHelper]; // Get ZMVideoSDKTestAudioDeviceHelper to test the speaker ZMVideoSDKTestAudioDeviceHelper *testAudioDeviceHelper = [[ZMVideoSDK shareInstance] getAudioDeviceTestHelper]; ``` 4. Start the speaker test. If it's successful, you'll receive the callback `onMicSpeakerVolumeChanged` with the speaker volume. ```swift //... // Get speaker list and select first one as an example let speakerList = audioHelper.getSpeakerList() let selectedSpeaker = micList[0] // Start speaker test audioDeviceTestHelper.startSpeakerTest(selectedSpeaker.deviceId) //... ``` ```objectivec // Use the first speaker as an example NSArray *speakerList = [audioHelper getSpeakerList]; ZMVideoSDKSpeakerDevice* selectedSpeaker = speakerList[0]; // Start the speaker test ZMVideoSDKErrors err = [testAudioDeviceHelper startSpeakerTest:selectedSpeaker.deviceId]; ``` 5. Stop the speaker test. ```swift //... // Stop speaker - This method only works when startSpeakerTest was called successfully audioDeviceTestHelper.stopSpeakerTest() } ``` ```objectivec ZMVideoSDKErrors err = [testAudioDeviceHelper stopSpeakerTest]; ```