You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Camera] Audio is only recorded with first recording on specific iOS device (iPhone 7) #131553
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-x64)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] VS Code (version 1.80.1)
[✓] Connected device (3 available)
! Error: (null) needs to connect to determine its availability. Check the connection between the device and its companion iPhone, and the connection between the iPhone and Xcode. Both devices may also need
to be restarted and unlocked. (code 1)
[✓] Network resources
Hi, @misos1. Thanks for filing this issue. Using the code sample provided here https://github.com/bettercoding-dev/flutter-video, I can't seem to produce on the latest master and stable channels and also using the camera: ^0.10.5+2 and video_player: ^2.7.0. Can you retry on your end with the code sample to confirm this issue still reproduces?
I can reproduce this issue on my device iPhone 7, iOS 15.7.2. Verified this with plugin example code.
The issue only occurs if I keep recording with one camera. But if I switch to another camera (front or rear) between tests, the output video always contains sound.
The issue is not reproducible on Android (Realme 6, Android 11).
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-x64, locale en-VN)
• Flutter version 3.10.6 on channel stable at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f468f3366c (3 weeks ago), 2023-07-12 15:19:05 -0700
• Engine revision cdbeda788a
• Dart version 3.0.6
• DevTools version 2.23.1
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 32.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
• Xcode at /Applications/Xcode-beta.app/Contents/Developer
• Build 15A5195m
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.80.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.68.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 13.5 22G74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.114
[✓] Network resources
• All expected network resources are available.
• No issues found!
[!] Flutter (Channel master, 3.13.0-15.0.pre.13, on macOS 13.5 22G74 darwin-x64, locale en-VN)
• Flutter version 3.13.0-15.0.pre.13 on channel master at /Users/huynq/Documents/GitHub/flutter_master
! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at
/Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at
/Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c851efaa3a (5 hours ago), 2023-07-31 22:40:26 -0400
• Engine revision 791f505c8c
• Dart version 3.2.0 (build 3.2.0-16.0.dev)
• DevTools version 2.25.0
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 32.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
• Xcode at /Applications/Xcode-beta.app/Contents/Developer
• Build 15A5195m
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.80.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.68.0
[✓] Connected device (3 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30)
• macOS (desktop) • macos • darwin-x64 • macOS 13.5 22G74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.114
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
This is caused by interference between camera_avfoundation and video_player_avfoundation. Both use same application shared AVAudioSession. Implicitly in camera_avfoundation because AVCaptureSession.usesApplicationAudioSession defaults to true and also AVCaptureSession.automaticallyConfiguresApplicationAudioSession defaults to true and seems capture session in such case is setting AVAudioSession.category to AVAudioSessionCategoryPlayAndRecord and video_player_avfoundation sets this explicitly to AVAudioSessionCategoryPlayback: https://github.com/flutter/packages/blob/354af05222810a79ffc59201fddebc367a911d87/packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m#L596
Do not mess with global settings in plugins like video_player or camera. What would happen if I used yet another plugin which sets yet another audio category? Maybe better would be to have a separate plugin for that and the user will be required to set up a proper audio session category so that camera and video_player work properly like there are permission requirements already now. (This could be even done automatically where each plugin could hint its category and for example when both playback and record is required then will be selected PlayAndRecord.)
Audio can be fixed and restored by removing and re-adding audioInput into _audioCaptureSession. This will also restore the category to PlayAndRecord. Problem is how to detect that there is no audio. For example it could be done after change to AVAudioSession.category but this is not even KVO compliant. The only working method of detection which I came with is really ugly. It looks at audio input sample buffer bytes and if all bytes are zero then it means we have no audio.
I think the best would be 2 and maybe this is applicable also to android. Video player would work also without setting AVAudioSessionCategoryPlayback it will just not play audio when the phone is in silent mode (which can be actually more appropriate for some apps). But somehow video cannot be recorded on older iPhones when it is not set to AVAudioSessionCategoryPlayAndRecord (or possibly AVAudioSessionCategoryRecord) and on newer iPhones it probably works with any category. So probably would be the best to have a dedicated plugin/package that lets users set audio category, options and modes as is most appropriate for specific apps.
For now I would suggest to not set category AVAudioSessionCategoryPlayback in L596 if it is already PlayAndRecord or Playback. And use already set category in L706-L710. That should fix this issue.
@kaciula You can try to do something like VideoPlayerController.file(File(""))..initialize()..dispose() before initializing camera so player will not later overwrite category set by camera.
Also as camera_avfoundation does not set automaticallyConfiguresApplicationAudioSession to false, it automatically overwrites what was set by the mixWithOthers option of VideoPlayerOptions.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
dam-ease commentedon Jul 31, 2023
Hi, @misos1. Thanks for filing this issue. Using the code sample provided here https://github.com/bettercoding-dev/flutter-video, I can't seem to produce on the latest
masterandstablechannels and also using thecamera: ^0.10.5+2andvideo_player: ^2.7.0. Can you retry on your end with the code sample to confirm this issue still reproduces?RPReplay_Final1690802278.MP4
misos1 commentedon Jul 31, 2023
According to your video it seems that you used some newer iphone like 11. It is possible that this bug happens only on older devices like iphone 7.
RPReplay_Final1690813936.mov
huycozy commentedon Aug 1, 2023
I can reproduce this issue on my device
iPhone 7, iOS 15.7.2. Verified this with plugin example code.The issue only occurs if I keep recording with one camera. But if I switch to another camera (front or rear) between tests, the output video always contains sound.
The issue is not reproducible on Android (Realme 6, Android 11).
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-x64, locale en-VN) • Flutter version 3.10.6 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (3 weeks ago), 2023-07-12 15:19:05 -0700 • Engine revision cdbeda788a • Dart version 3.0.6 • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 32.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode-beta.app/Contents/Developer • Build 15A5195m • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] VS Code (version 1.80.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.68.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 13.5 22G74 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.114 [✓] Network resources • All expected network resources are available. • No issues found!2 remaining items
misos1 commentedon Aug 22, 2023
This is caused by interference between
camera_avfoundationandvideo_player_avfoundation. Both use same application sharedAVAudioSession. Implicitly incamera_avfoundationbecauseAVCaptureSession.usesApplicationAudioSessiondefaults to true and alsoAVCaptureSession.automaticallyConfiguresApplicationAudioSessiondefaults to true and seems capture session in such case is settingAVAudioSession.categorytoAVAudioSessionCategoryPlayAndRecordandvideo_player_avfoundationsets this explicitly toAVAudioSessionCategoryPlayback:https://github.com/flutter/packages/blob/354af05222810a79ffc59201fddebc367a911d87/packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m#L596
Note this "per-instance" state which is actually global state, multiple video player controllers will share this across app:
https://github.com/flutter/packages/blob/354af05222810a79ffc59201fddebc367a911d87/packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m#L706-L710
I think it would not be good idea to use separate
AVAudioSessionfor recording as this could cause interruptions as is stated in:https://developer.apple.com/documentation/avfoundation/avcapturesession/1620490-usesapplicationaudiosession?language=objc
Do not mess with global settings in plugins like
video_playerorcamera. What would happen if I used yet another plugin which sets yet another audio category? Maybe better would be to have a separate plugin for that and the user will be required to set up a proper audio session category so thatcameraandvideo_playerwork properly like there are permission requirements already now. (This could be even done automatically where each plugin could hint its category and for example when both playback and record is required then will be selectedPlayAndRecord.)Audio can be fixed and restored by removing and re-adding
audioInputinto_audioCaptureSession. This will also restore the category toPlayAndRecord. Problem is how to detect that there is no audio. For example it could be done after change toAVAudioSession.categorybut this is not even KVO compliant. The only working method of detection which I came with is really ugly. It looks at audio input sample buffer bytes and if all bytes are zero then it means we have no audio.I think the best would be 2 and maybe this is applicable also to android. Video player would work also without setting
AVAudioSessionCategoryPlaybackit will just not play audio when the phone is in silent mode (which can be actually more appropriate for some apps). But somehow video cannot be recorded on older iPhones when it is not set toAVAudioSessionCategoryPlayAndRecord(or possiblyAVAudioSessionCategoryRecord) and on newer iPhones it probably works with any category. So probably would be the best to have a dedicated plugin/package that lets users set audio category, options and modes as is most appropriate for specific apps.Any other ideas?
misos1 commentedon Aug 22, 2023
For now I would suggest to not set category
AVAudioSessionCategoryPlaybackin L596 if it is alreadyPlayAndRecordorPlayback. And use already set category in L706-L710. That should fix this issue.kaciula commentedon Jan 21, 2024
Is there a workaround for this? I'm trying to film multiple videos one after the other and only the first one has sound.
misos1 commentedon Jul 8, 2024
@kaciula You can try to do something like
VideoPlayerController.file(File(""))..initialize()..dispose()before initializing camera so player will not later overwrite category set by camera.misos1 commentedon Jul 13, 2024
Also as
camera_avfoundationdoes not setautomaticallyConfiguresApplicationAudioSessionto false, it automatically overwrites what was set by themixWithOthersoption ofVideoPlayerOptions.[video_player_avfoundation, camera_avfoundation] never overwrite but …
github-actions commentedon Jan 27, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[video_player_avfoundation, camera_avfoundation] never overwrite but …
[video_player_avfoundation, camera_avfoundation] never overwrite but …
[video_player_avfoundation, camera_avfoundation] never overwrite but …
[video_player_avfoundation, camera_avfoundation] never overwrite but …
[video_player_avfoundation, camera_avfoundation] never overwrite but …