llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
213 stars 174 forks source link

Flutter Windows Lost connection to device #313

Open Hopheylalal opened 1 month ago

Hopheylalal commented 1 month ago

Hello record 5.0.5

Environment

llfbandit commented 1 month ago

Try to start your app from Visual Studio to get log and stacktrace. From here, I will be able to investigate otherwise I will close this issue.

6th-kate commented 1 month ago

Hello, I am facing the same "Lost connection to device" crash

dart: >=3.3.1 <4.0.0 flutter: >=3.19.0 record: ^5.1.1 windows 10

Exception thrown: read access violation. pSinkWriter was nullptr.

The stacktrace:

record_windows_plugin.dll!record_windows::Recorder::CreateSinkWriter(std::string path) Line 397 C++
record_windows_plugin.dll!record_windows::Recorder::Start(std::unique_ptr<record_windows::RecordConfig,std::default_delete<record_windows::RecordConfig>> config, std::string path) Line 81 C++
record_windows_plugin.dll!record_windows::RecordWindowsPlugin::HandleMethodCall(const flutter::MethodCall<flutter::EncodableValue> & method_call, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>,std::default_delete<flutter::MethodResult<flutter::EncodableValue>>> result) Line 134  C++
record_windows_plugin.dll!<lambda_1165fad256d06266751221916df127db>::operator()<flutter::MethodCall<flutter::EncodableValue>,std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>,std::default_delete<flutter::MethodResult<flutter::EncodableValue>>>>(const flutter::MethodCall<flutter::EncodableValue> & call, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>,std::default_delete<flutter::MethodResult<flutter::EncodableValue>>> result) Line 45    C++
[External Code] 
record_windows_plugin.dll!flutter::MethodChannel<flutter::EncodableValue>::SetMethodCallHandler::__l2::<lambda>(const unsigned char * message, unsigned __int64 message_size, std::function<void __cdecl(unsigned char const *,unsigned __int64)> reply) Line 121   C++
[External Code] 
record_windows_plugin.dll!flutter::`anonymous namespace'::ForwardToHandler(FlutterDesktopMessenger * messenger, const FlutterDesktopMessage * message, void * user_data) Line 76    C++
[External Code] 
myapp.exe!wWinMain(HINSTANCE__ * instance, HINSTANCE__ * prev, wchar_t * command_line, int show_command) Line 39    C++
[External Code] 

Might it be that I don't have some of standard Windows utilities installed which I'm not knowing about?

llfbandit commented 1 month ago

Thanks for the stack trace. There's a missing check when starting the recording.

It seems that the given path is problematic. Are you trying to record to a protected folder? To confirm this (and workaround for now), can try to record in a public folder?

llfbandit commented 1 month ago

record_windows 1.0.3 has been released to fix the crash and forward the underlying error on Dart side.

6th-kate commented 3 weeks ago

Thank you for your response and the record_windows update! I was able to secure my users' experience by handling this exception.

This turned out to be a "Path not found" error. I am not actually sure about its reason, got this thrown while trying to record audios into the "documents" directory, returned by path_provider getApplicationDocumentsDirectory().

It might be one of the two things:

  1. This directory is synchronized with my OneDrive cloud, therefore, the returned path contains "OneDrive". Not completely sure if this folder is virtual, but it may occur due to some privacy settings.
  2. My Windows uses locale with Cyrillic symbols, so the path in my terminal is shown like this: C:\Users\<username>\OneDrive\Документи. At the same time, the path I get from path_provider looks like the following: C:\Users\<username>\OneDrive\Documents. This duality is managed by most of inbuilt utilities, though sometimes it is still causing errors.

However, dart:io has been able to create folders and files in the same directory. Also, archive plugin successfully unzipped data in there. Is this caused by MediaFoundation at some point? Writing in other folders like C:\workspace\myapp works perfectly well.

Hope this might help.

llfbandit commented 1 week ago

Sorry for the late reply, I bet on the encoding issue since dart/native communication is UTF8 only. I will try to use pigeon to workaround those fuzzy issues on windows platform.