1+ import 'package:dolbyio_comms_sdk_flutter/dolbyio_comms_sdk_flutter.dart' ;
2+ import 'package:dolbyio_comms_sdk_flutter_example/widgets/secondary_button.dart' ;
13import 'package:flutter/material.dart' ;
24import '/widgets/dolby_title.dart' ;
35import '/widgets/primary_button.dart' ;
6+ import 'dart:developer' as developer;
47
5- class AudioPreviewScreen extends StatelessWidget {
8+ class AudioPreviewScreen extends StatefulWidget {
69 const AudioPreviewScreen ({Key ? key}) : super (key: key);
710
11+ @override
12+ State <AudioPreviewScreen > createState () => _AudioPreviewScreenState ();
13+ }
14+
15+ class _AudioPreviewScreenState extends State <AudioPreviewScreen > {
16+ VoiceFont selectedVoiceFont = VoiceFont .none;
17+ AudioCaptureMode selectedAudioCaptureMode = AudioCaptureMode .standard;
18+ NoiseReduction selectedNoiseReduction = NoiseReduction .low;
19+ final _dolbyioCommsSdkFlutterPlugin = DolbyioCommsSdk .instance;
20+
821 @override
922 Widget build (BuildContext context) {
1023 return SafeArea (
@@ -30,6 +43,118 @@ class AudioPreviewScreen extends StatelessWidget {
3043 child: Column (
3144 mainAxisAlignment: MainAxisAlignment .center,
3245 children: [
46+ DropdownButton <AudioCaptureMode >(
47+ focusColor: Colors .white,
48+ value: selectedAudioCaptureMode,
49+ style: const TextStyle (color: Colors .white),
50+ iconEnabledColor: Colors .black,
51+ items: AudioCaptureMode .values
52+ .map <DropdownMenuItem <AudioCaptureMode >>(
53+ (AudioCaptureMode value) {
54+ return DropdownMenuItem <AudioCaptureMode >(
55+ value: value,
56+ child: Text (
57+ value.name,
58+ style: const TextStyle (color: Colors .black),
59+ ),
60+ );
61+ }).toList (),
62+ onChanged: (AudioCaptureMode ? audioCaptureMode) {
63+ setState (() {
64+ selectedAudioCaptureMode = audioCaptureMode! ;
65+ });
66+ },
67+ ),
68+ const SizedBox (height: 16 ),
69+ DropdownButton <NoiseReduction >(
70+ focusColor: Colors .white,
71+ value: selectedNoiseReduction,
72+ style: const TextStyle (color: Colors .white),
73+ iconEnabledColor: Colors .black,
74+ items: NoiseReduction .values
75+ .map <DropdownMenuItem <NoiseReduction >>(
76+ (NoiseReduction value) {
77+ return DropdownMenuItem <NoiseReduction >(
78+ value: value,
79+ child: Text (
80+ value.name,
81+ style: const TextStyle (color: Colors .black),
82+ ),
83+ );
84+ }).toList (),
85+ onChanged: (NoiseReduction ? noiseReduction) {
86+ setState (() {
87+ selectedNoiseReduction = noiseReduction! ;
88+ });
89+ },
90+ ),
91+ const SizedBox (height: 16 ),
92+ DropdownButton <VoiceFont >(
93+ focusColor: Colors .white,
94+ value: selectedVoiceFont,
95+ style: const TextStyle (color: Colors .white),
96+ iconEnabledColor: Colors .black,
97+ items: VoiceFont .values
98+ .map <DropdownMenuItem <VoiceFont >>(
99+ (VoiceFont value) {
100+ return DropdownMenuItem <VoiceFont >(
101+ value: value,
102+ child: Text (
103+ value.name,
104+ style: const TextStyle (color: Colors .black),
105+ ),
106+ );
107+ }).toList (),
108+ onChanged: (VoiceFont ? voiceFont) {
109+ setState (() {
110+ selectedVoiceFont = voiceFont! ;
111+ });
112+ },
113+ ),
114+ const SizedBox (height: 16 ),
115+ Row (
116+ mainAxisAlignment: MainAxisAlignment .center,
117+ children: [
118+ SecondaryButton (
119+ text: 'Record' ,
120+ onPressed: () {
121+ record ();
122+ },
123+ color: Colors .deepPurple,
124+ ),
125+ SecondaryButton (
126+ text: 'Play' ,
127+ onPressed: () {
128+ play ();
129+ },
130+ color: Colors .deepPurple,
131+ ),
132+ SecondaryButton (
133+ text: 'Cancel' ,
134+ onPressed: () {
135+ cancel ();
136+ },
137+ color: Colors .deepPurple,
138+ ),
139+ SecondaryButton (
140+ text: 'Release' ,
141+ onPressed: () {
142+ release ();
143+ },
144+ color: Colors .deepPurple,
145+ ),
146+ ],
147+ ),
148+ const SizedBox (height: 16 ),
149+ PrimaryButton (
150+ widgetText: const Text (
151+ 'Set capture mode with chosen options' ),
152+ onPressed: () {
153+ setCaptureMode ();
154+ },
155+ color: Colors .deepPurple,
156+ ),
157+ const SizedBox (height: 16 ),
33158 PrimaryButton (
34159 widgetText: const Text ('Back to join screen' ),
35160 onPressed: () {
@@ -52,4 +177,57 @@ class AudioPreviewScreen extends StatelessWidget {
52177 void navigateToJoinScreen (BuildContext context) {
53178 Navigator .of (context).pop ();
54179 }
180+
181+ Future <void > setCaptureMode () async {
182+ try {
183+ var options = AudioCaptureOptions (
184+ selectedAudioCaptureMode, selectedNoiseReduction,
185+ voiceFont: selectedVoiceFont);
186+ await _dolbyioCommsSdkFlutterPlugin.audioService.localAudio.preview
187+ .setCaptureMode (options);
188+ developer.log ("setCaptureMode success" );
189+ } catch (error) {
190+ developer.log ("Error during setCaptureMode: $error " );
191+ }
192+ }
193+
194+ Future <void > play () async {
195+ try {
196+ await _dolbyioCommsSdkFlutterPlugin.audioService.localAudio.preview
197+ .play (false );
198+ developer.log ("play success" );
199+ } catch (error) {
200+ developer.log ("Error during play: $error " );
201+ }
202+ }
203+
204+ Future <void > record () async {
205+ try {
206+ await _dolbyioCommsSdkFlutterPlugin.audioService.localAudio.preview
207+ .record (3 );
208+ developer.log ("record success" );
209+ } catch (error) {
210+ developer.log ("Error during record: $error " );
211+ }
212+ }
213+
214+ Future <void > cancel () async {
215+ try {
216+ await _dolbyioCommsSdkFlutterPlugin.audioService.localAudio.preview
217+ .cancel ();
218+ developer.log ("cancel success" );
219+ } catch (error) {
220+ developer.log ("Error during cancel $error " );
221+ }
222+ }
223+
224+ Future <void > release () async {
225+ try {
226+ await _dolbyioCommsSdkFlutterPlugin.audioService.localAudio.preview
227+ .release ();
228+ developer.log ("release success" );
229+ } catch (error) {
230+ developer.log ("Error during release: $error " );
231+ }
232+ }
55233}
0 commit comments