Skip to content

Commit e2d10b4

Browse files
committed
Add live streaming switch and bitrate option to the prejoin page.
1 parent 5d59331 commit e2d10b4

1 file changed

Lines changed: 56 additions & 2 deletions

File tree

example/lib/pages/prejoin.dart

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class _PreJoinPageState extends State<PreJoinPage> {
6060
MediaDevice? _selectedVideoDevice;
6161
MediaDevice? _selectedAudioDevice;
6262
VideoParameters _selectedVideoParameters = VideoParametersPresets.h720_169;
63+
int _videoBitrate = 3 * 1000 * 1000;
64+
bool _liveStreaming = true;
6365

6466
@override
6567
void initState() {
@@ -183,6 +185,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
183185
_videoTrack = await LocalVideoTrack.createCameraTrack(CameraCaptureOptions(
184186
deviceId: _selectedVideoDevice!.deviceId,
185187
params: _selectedVideoParameters,
188+
liveStreaming: _liveStreaming,
186189
));
187190
await _videoTrack!.start();
188191
}
@@ -203,8 +206,8 @@ class _PreJoinPageState extends State<PreJoinPage> {
203206

204207
try {
205208
//create new room
206-
const cameraEncoding = VideoEncoding(
207-
maxBitrate: 5 * 1000 * 1000,
209+
final cameraEncoding = VideoEncoding(
210+
maxBitrate: _videoBitrate,
208211
maxFramerate: 30,
209212
);
210213

@@ -449,6 +452,57 @@ class _PreJoinPageState extends State<PreJoinPage> {
449452
),
450453
),
451454
),
455+
if (_enableVideo)
456+
Padding(
457+
padding: const EdgeInsets.only(bottom: 5),
458+
child: Row(
459+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
460+
children: [
461+
const Text('Live Streaming:'),
462+
Switch(
463+
value: _liveStreaming,
464+
onChanged: (value) async {
465+
setState(() {
466+
_liveStreaming = value;
467+
});
468+
await _changeLocalVideoTrack();
469+
if (mounted) setState(() {});
470+
},
471+
),
472+
],
473+
),
474+
),
475+
if (_enableVideo)
476+
Padding(
477+
padding: const EdgeInsets.only(bottom: 25),
478+
child: Row(
479+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
480+
children: [
481+
const Text('Video Bitrate:'),
482+
SizedBox(
483+
width: 140,
484+
height: 40,
485+
child: TextFormField(
486+
initialValue: (_videoBitrate ~/ 1000).toString(),
487+
keyboardType: TextInputType.number,
488+
textAlign: TextAlign.right,
489+
decoration: const InputDecoration(
490+
isDense: true,
491+
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
492+
border: OutlineInputBorder(),
493+
suffixText: 'kbps',
494+
),
495+
onChanged: (value) {
496+
final kbps = int.tryParse(value);
497+
if (kbps != null && kbps > 0) {
498+
_videoBitrate = kbps * 1000;
499+
}
500+
},
501+
),
502+
),
503+
],
504+
),
505+
),
452506
Padding(
453507
padding: const EdgeInsets.only(bottom: 5),
454508
child: Row(

0 commit comments

Comments
 (0)