Giter Club home page Giter Club logo

Comments (28)

amitkhairnar44 avatar amitkhairnar44 commented on July 26, 2024 2

@scheung38 The path which you are getting after recording is actually an Uri. If you want to upload the file then you can do something like this:

    File file = File.fromUri(Uri.parse(filePath));

from record.

bafplus avatar bafplus commented on July 26, 2024 1

Great @amitkhairnar44 thanks! However....what is the exact code? Could you taka a look at my snippet in the second post?
I'm still very puzzled on what exactly should be placed in the "FULL_PATH_TO_AUDIOFILE" part. Would you be so kind to help me out?

from record.

bafplus avatar bafplus commented on July 26, 2024

This is partly what i need to....Im trying to email the resulting audio file yet i cant seem to get the variable to get the full path so my mailer can attach the audiofile. Im trying to use this code, maybe you know how or what to put in place of "FULL_PATH_TO_AUDIOFILE"?

mailer() async {
    final smtpServer = SmtpServer("smtp.server.com",
        username: 'username',
        password: 'passwd',
        allowInsecure: true,
        ignoreBadCertificate: true);

    final datumOpmaak = DateFormat('dd-MM-yyyy H:mm');

    // Create our message.
    final message = Message()
      ..from = Address('[email protected]', 'Me')
      ..recipients.add('[email protected]')
      ..subject =
          'Test Dart Mailer library :: 😀 :: ${datumOpmaak.format(DateTime.now())}'
      ..text = 'This is the plain text.\nThis is line 2 of the text part.'
      ..attachments = [
        FileAttachment(File('FULL_PATH_TO_AUDIOFILE'))
          ..location = Location.inline
          ..cid = '<[email protected]>'
      ];

    try {
      final sendReport = await send(message, smtpServer);
      print('Message sent: ' + sendReport.toString());
    } on MailerException catch (e) {
      print('Message not sent.');
      for (var p in e.problems) {
        print('Problem: ${p.code}: ${p.msg}');
      }
    }
  }
// DONE

from record.

scheung38 avatar scheung38 commented on July 26, 2024

Hi @bafplus

I think this is the path:

file:///$HOME/Library/Developer/CoreSimulator/Devices/XXXXXXXX-XXXX-XXXX-B3F2-BE4E4FB87E55/data/Containers/Data/Applic
ation/XXXXXXXX-XXXX-XXXX-XXXX-74B3B588FAA4/tmp/XXXXXXXX-XXXX-XXXX-XXXX-1D7571130760.m4a

but I cannot seem to upload .m4a this to Firebase Storage as outlined as it is saying:

'file.absolute.existsSync()': is not true

from record.

bafplus avatar bafplus commented on July 26, 2024

Im quite the noob so pardon if i say something stupid or abvious :-)....But isnt that path different on both android and IOS and even per device? If i'm correct the recorder/player is using string, and we are (trying) to use file, maybe thats the issue? So big questions remains...where and how does it store the audiofile and how to get said file to send to firebase (or mail in my case)?

from record.

scheung38 avatar scheung38 commented on July 26, 2024

Hi @bafplus, just copy and paste your filepath found into browser, if it works then thats your audio. But your point is valid, but i have not tried with Android yet, but I can imagine it would be the same path.

from record.

bafplus avatar bafplus commented on July 26, 2024

Thats my first problem...i havent found it yet :-)
And in browser? Does that also work in android (i think you are using web?)?

from record.

scheung38 avatar scheung38 commented on July 26, 2024

Working on iOS side, but when we paste into browser we should get:

Screenshot 2021-07-30 at 21 17 47

from record.

bafplus avatar bafplus commented on July 26, 2024

Yes but what variable holds that path/url in the first place?
That path is not the same for all devices, so hardcoding will definatly not work. I'm very new to coding in the first place (but learning ;-)) so its very hard for me to pinpoint where and how that path is declared in the first place...

from record.

llfbandit avatar llfbandit commented on July 26, 2024

If you do not provide your own path, path is returned from stop method as uri string. You should try Uri.parse and toFilePath or File.fromUri if you need file handler.

from record.

bafplus avatar bafplus commented on July 26, 2024

If you do not provide your own path, path is returned from stop method as uri string. You should try Uri.parse and toFilePath or File.fromUri if you need file handler.

That sounds good...but could you help this noob with some code or example? (see my code above)

from record.

scheung38 avatar scheung38 commented on July 26, 2024

@llfbandit why do we need to parse when we can pass the whole filePath

file:///$HOME/Library/........./XXX.m4a into this:

Future<void> uploadFile(String filePath) async {
  File file = File(filePath);

  try {
    await firebase_storage.FirebaseStorage.instance
        .ref('uploads/file-to-upload.png')
        .putFile(file);
  } on firebase_core.FirebaseException catch (e) {
    // e.g, e.code == 'canceled'
  }
}

from record.

bafplus avatar bafplus commented on July 26, 2024

Any luck yet @scheung38 ?

from record.

amitkhairnar44 avatar amitkhairnar44 commented on July 26, 2024

Great @amitkhairnar44 thanks! However....what is the exact code? Could you taka a look at my snippet in the second post?
I'm still very puzzled on what exactly should be placed in the "FULL_PATH_TO_AUDIOFILE" part. Would you be so kind to help me out?

You can use the same code as I have mentioned above.

FileAttachment(File.fromUri(Uri.parse(filePath)))
          ..location = Location.inline
          ..cid = '<[email protected]>'

filePath here would be the path received after recording.

from record.

bafplus avatar bafplus commented on July 26, 2024
File.fromUri(Uri.parse(filePath))

Thanks,

Yet i get this error: Undefined name 'filePath'.
If i change it to "Path" it says: The argument type 'Type' can't be assigned to the parameter type 'String'.
If i then make it 'Path as String' i have no errors, but if i try to send it i get: 'Unhandled Exception: type '_Type' is not a subtype of type 'String' in type cast...'

from record.

amitkhairnar44 avatar amitkhairnar44 commented on July 26, 2024

File.fromUri(Uri.parse(filePath))

Thanks,

Yet i get this error: Undefined name 'filePath'.

If i change it to "Path" it says: The argument type 'Type' can't be assigned to the parameter type 'String'.

If i then make it 'Path as String' i have no errors, but if i try to send it i get: 'Unhandled Exception: type '_Type' is not a subtype of type 'String' in type cast...'

filePath should be the path of the file that you are trying to send.

from record.

bafplus avatar bafplus commented on July 26, 2024

File.fromUri(Uri.parse(filePath))

Thanks,
Yet i get this error: Undefined name 'filePath'.
If i change it to "Path" it says: The argument type 'Type' can't be assigned to the parameter type 'String'.
If i then make it 'Path as String' i have no errors, but if i try to send it i get: 'Unhandled Exception: type '_Type' is not a subtype of type 'String' in type cast...'

filePath should be the path of the file that you are trying to send.

And thats the problem...we dont know the actual path. It is generated upon recorder_start and put in a variable, yet i dont know what variable exactly or how to (re)call it.

from record.

amitkhairnar44 avatar amitkhairnar44 commented on July 26, 2024

File.fromUri(Uri.parse(filePath))

Thanks,

Yet i get this error: Undefined name 'filePath'.

If i change it to "Path" it says: The argument type 'Type' can't be assigned to the parameter type 'String'.

If i then make it 'Path as String' i have no errors, but if i try to send it i get: 'Unhandled Exception: type '_Type' is not a subtype of type 'String' in type cast...'

filePath should be the path of the file that you are trying to send.

And thats the problem...we dont know the actual path. It is generated upon recorder_start and put in a variable, yet i dont know what variable exactly or how to (re)call it.

You'll get the path upon stopping the recorder.

Share the code snippet where you're stopping the recorder.

from record.

bafplus avatar bafplus commented on July 26, 2024

File.fromUri(Uri.parse(filePath))

Thanks,

Yet i get this error: Undefined name 'filePath'.

If i change it to "Path" it says: The argument type 'Type' can't be assigned to the parameter type 'String'.

If i then make it 'Path as String' i have no errors, but if i try to send it i get: 'Unhandled Exception: type '_Type' is not a subtype of type 'String' in type cast...'

filePath should be the path of the file that you are trying to send.

And thats the problem...we dont know the actual path. It is generated upon recorder_start and put in a variable, yet i dont know what variable exactly or how to (re)call it.

You'll get the path upon stopping the recorder.

Share the code snippet where you're stopping the recorder.

I used the example: https://github.com/llfbandit/record/blob/master/record/example/lib/main.dart

Here is my full main.dart: https://pastebin.com/XX42RjLd

Thanks allot for helping out!

from record.

bafplus avatar bafplus commented on July 26, 2024

@amitkhairnar44 I have tried different ways yet still without succes, help in any kind is much apriciated :-)

from record.

amitkhairnar44 avatar amitkhairnar44 commented on July 26, 2024

@bafplus I have checked your code.
In your _MyAppState class you have this code:

AudioRecorder(
              onStop: (path) {
                setState(() {
                  audioSource = ap.AudioSource.uri(Uri.parse(path));
                  showPlayer = true;
                });
              },
            )

You are getting the path in this widget's callback onStop. Assign that path to some variable and use it to upload the file.

from record.

bafplus avatar bafplus commented on July 26, 2024

@bafplus I have checked your code.
In your _MyAppState class you have this code:

AudioRecorder(
              onStop: (path) {
                setState(() {
                  audioSource = ap.AudioSource.uri(Uri.parse(path));
                  showPlayer = true;
                });
              },
            )

You are getting the path in this widget's callback onStop. Assign that path to some variable and use it to upload the file.

Thanks, and that variable would be "audioSource"?

Again, pardon my noobness...im learning here :-)

from record.

amitkhairnar44 avatar amitkhairnar44 commented on July 26, 2024

@bafplus Try this code: https://pastebin.com/nbbkSUk6

from record.

bafplus avatar bafplus commented on July 26, 2024

@bafplus Try this code: https://pastebin.com/nbbkSUk6

Almost :-)

The named parameter 'path' isn't defined. :236
All final variables must be initialized, but 'path' isn't. :268

from record.

amitkhairnar44 avatar amitkhairnar44 commented on July 26, 2024

Add it to the constructor like this:

const AudioPlayer({
    required this.path,
    required this.source,
    required this.onDelete,
  });

from record.

bafplus avatar bafplus commented on July 26, 2024

Add it to the constructor like this:

const AudioPlayer({
    required this.path,
    required this.source,
    required this.onDelete,
  });

Thats it! many many thanks, you eurned yourself a beer! :-)

from record.

bafplus avatar bafplus commented on July 26, 2024

Add it to the constructor like this:

const AudioPlayer({
    required this.path,
    required this.source,
    required this.onDelete,
  });

This works on emulator but not on device (release.apk)....next stop: permissions :-)

from record.

rvndsngwn avatar rvndsngwn commented on July 26, 2024

@scheung38 The path which you are getting after recording is actually an Uri. If you want to upload the file then you can do something like this:

    File file = File.fromUri(Uri.parse(filePath));

Unhandled Exception: FileSystemException: Cannot open file, path = 'file:///private/var/mobile/Containers/Data/Application/02XXXXD-7XX3-4XXX-XXXX-3XXXXXXX3/tmp/9XXXXX-5295-XXX-XXXX-XXXX97E8EE2.m4a' (OS Error: No such file or directory, errno = 2) #0 _File.open.<anonymous closure> (dart:io/file_impl.dart:356:9) #1 _rootRunUnary (dart:async/zone.dart:1362:47) #2 _CustomZone.runUnary (dart:async/zone.dart:1265:19) <asynchronous suspension>

I'm getting this error and I just replace this line file = File(path); to file = File.fromUri(Uri.parse(path)); and error solved. Thanks @scheung38

from record.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.