karostudio / flutter_desktop_audio_recorder

BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

[Windows] path argument is not working #2

Open JesseChang opened 1 year ago

JesseChang commented 1 year ago

The wav file is successful generated but at wrong location in the project folder instead of the given path.

I found the path argument is not implement in cpp for windows.

flutter_desktop_audio_recorder_plugin.cpp

if (method_call.method_name().compare("start_audio_record") == 0) {
      auto name_it = arguments->find(flutter::EncodableValue("fileName"));
      if (name_it != arguments->end())
      {
        std::string fileName = std::get<std::string>(name_it->second); //only use filename here
        result->Success(flutter:: EncodableValue(recorder.startRecording(fileName)));
      }
      result->Error("Error while parsing path");
    }
MengTingChen-maker commented 1 year ago

I have also encountered this problem. Do you know how to deal with it?

ANC1024GO commented 1 month ago

I made a small modification to allow specifying the directory

//voiceRecording.h

namespace  N {
    class VoiceRecording
    {
        public:
           // .... orginal code
           // std::string _fileName; 
           std::string _fullPath; // add
//voiceRecording.cpp

bool VoiceRecording::saveFile() {

    std::wstring fullPath =  std::wstring(_fullPath.begin(), _fullPath.end());

    // Save the recording to a file. Wait for the operation to complete before continuing.
    LPCWSTR sw = fullPath.c_str();
    mciSaveParms.lpfilename = sw;

    std::wcout << L"Saving to: " << sw << std::endl;

    dwReturn = 1;
    dwReturn = mciSendCommand(wDeviceID, MCI_SAVE,
        MCI_SAVE_FILE | MCI_WAIT, (DWORD_PTR) &mciSaveParms);
    if(dwReturn == 0)
    {
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        return true;
    }
    mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
    return false;
}
bool N::VoiceRecording::startRecording(string fullPath) {
    //.....
    _fullPath = fullPath;
    //.....
}
// flutter_desktop_audio_recorder_plugin.cpp
if (method_call.method_name().compare("start_audio_record") == 0) {
      auto name_it = arguments->find(flutter::EncodableValue("path"));
      if (name_it != arguments->end())
      {
        std::string fullPath = std::get<std::string>(name_it->second);
        result->Success(flutter:: EncodableValue(recorder.startRecording(fullPath)));
      }
      result->Error("Error while parsing path");
    }
    else if (method_call.method_name().compare("stop_audio_record") == 0) {
      recorder.stopRecording();
      result-> Success(recorder._fullPath);
    }
ANC1024GO commented 1 month ago

I have also encountered this problem. Do you know how to deal with it?