Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio playback stops audio recording #1251

Open
jaween opened this issue May 30, 2024 · 0 comments
Open

Audio playback stops audio recording #1251

jaween opened this issue May 30, 2024 · 0 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@jaween
Copy link

jaween commented May 30, 2024

Which API doesn't behave as documented, and how does it misbehave?
When using the mic with package:recorder, just audio's AudioPlayer.play() method causes the mic stream to stop emitting values. This problem doesn't occur if AudioPlayer.play() is called at least once prior to using the mic. This happens on iOS.

Minimal reproduction project
Verson 1: Mic stream halts once audio halts just after AudioPlayer.play():

import 'package:flutter/widgets.dart';
import 'package:just_audio/just_audio.dart' as ja;
import 'package:record/record.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await _recordAudio();
  await Future.delayed(const Duration(seconds: 1));
  await _playAudio();
}

Future<void> _recordAudio() async {
  final recorder = AudioRecorder();
  final micStream = await recorder.startStream(
    const RecordConfig(encoder: AudioEncoder.pcm16bits),
  );
  micStream.listen((_) => print('Got mic buffer'));
}

Future<void> _playAudio() async {
  final player = ja.AudioPlayer();
  try {
    print('Playing');
    player.play();
  } catch (e) {
    print('Error $e');
  }
  await player.dispose();
}

Output:

(9) flutter: Got mic buffer
flutter: Playing
flutter: Got mic buffer

Version 2: No issue, mic stream continues emitting values:

import 'package:flutter/widgets.dart';
import 'package:just_audio/just_audio.dart' as ja;
import 'package:record/record.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await _playAudio();
  await _recordAudio();
  await Future.delayed(const Duration(seconds: 1));
  await _playAudio();
}

Future<void> _recordAudio() async {
  final recorder = AudioRecorder();
  final micStream = await recorder.startStream(
    const RecordConfig(encoder: AudioEncoder.pcm16bits),
  );
  micStream.listen((_) => print('Got mic buffer'));
}

Future<void> _playAudio() async {
  final player = ja.AudioPlayer();
  try {
    print('Playing');
    player.play();
  } catch (e) {
    print('Error $e');
  }
  await player.dispose();
}

Output:

flutter: Playing
(9) flutter: Got mic buffer
flutter: Playing
(643) flutter: Got mic buffer

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:

  1. Install both package:record and package:just_audio
  2. Add the NSMicrophoneUsageDescription key and value to Info.plist so the app can use the mic on iOS.
  3. Run the first reproducible sample given
  4. Observe the mic stream stop printing out values

Expected behavior
The mic stream should continue regardless of whether or not AudioPlayer.play() is called.

Desktop (please complete the following information):

  • OS: MacOS Sonoma 14.4.1

Smartphone (please complete the following information):

  • Device: iPhone 7
  • OS: iOS 15.7.9

Flutter SDK version

[✓] Flutter (Channel stable, 3.19.1, on macOS 14.4.1 23E224 darwin-arm64, locale
    en-AU)
    • Flutter version 3.19.1 on channel stable at /opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision abb292a07e (3 months ago), 2024-02-20 14:35:05 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.90.0

[✓] Connected device (4 available)            
    • Jaween’s iPhone (mobile) • 02669b794c29bb14a717a3d0987dc6c5c116d819 • ios
      • iOS 15.7.9 19H365
    • macOS (desktop)          • macos                                    •
      darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)             • chrome                                   •
      web-javascript • Google Chrome 125.0.6422.113

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.
@jaween jaween added 1 backlog bug Something isn't working labels May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants