Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/fix-audio-visualizer-unpublished-track
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="fixed" "Fix audio visualizer not working for unpublished local audio tracks"
27 changes: 27 additions & 0 deletions lib/src/hardware/hardware.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import 'dart:async';

import 'package:flutter/foundation.dart' show kIsWeb;

import 'package:collection/collection.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;

Expand Down Expand Up @@ -194,6 +196,31 @@ class Hardware {
});
}

/// Explicitly starts the audio device module's recording pipeline.
///
/// This is called automatically when a [LocalAudioTrack] is started, but
/// can be called manually for pre-join scenarios (e.g. audio visualization
/// before connecting to a room).
///
/// No-ops on web. Safe to call multiple times (idempotent).
Future<void> startLocalRecording() async {
if (!kIsWeb) {
await rtc.NativeAudioManagement.startLocalRecording();
}
}

/// Stops the audio device module's recording pipeline.
///
/// Normally you don't need to call this — WebRTC manages the ADM lifecycle.
/// Use this only for explicit control (e.g. CallKit flows).
///
/// No-ops on web.
Future<void> stopLocalRecording() async {
if (!kIsWeb) {
await rtc.NativeAudioManagement.stopLocalRecording();
}
}

dynamic _onDeviceChange(dynamic _) async {
final devices = await enumerateDevices();
selectedAudioInput ??= devices.firstWhereOrNull((element) => element.kind == 'audioinput');
Expand Down
11 changes: 11 additions & 0 deletions lib/src/track/local/audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import 'dart:async';

import 'package:flutter/foundation.dart' show kIsWeb;

import 'package:collection/collection.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -110,6 +112,15 @@ class LocalAudioTrack extends LocalTrack with AudioTrack, LocalAudioManagementMi
return senderStats;
}

@override
Future<bool> start() async {
if (isActive) return false;
if (!kIsWeb) {
await rtc.NativeAudioManagement.startLocalRecording();
}
return await super.start();
}

// private constructor
@internal
LocalAudioTrack(
Expand Down
Loading