Comments (28)
@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.
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.
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.
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.
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.
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.
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.
Working on iOS side, but when we paste into browser we should get:
from record.
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.
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.
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.
@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.
Any luck yet @scheung38 ?
from record.
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.
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.
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.
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.
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.
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.
@amitkhairnar44 I have tried different ways yet still without succes, help in any kind is much apriciated :-)
from record.
@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 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.
@bafplus Try this code: https://pastebin.com/nbbkSUk6
from record.
@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.
Add it to the constructor like this:
const AudioPlayer({
required this.path,
required this.source,
required this.onDelete,
});
from record.
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.
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.
@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)
- In browser, is that only use stream ? beacuse i can't create file on web. HOT 4
- is there any way to restrict max duration of recorded audio? and fire a function on a callback when it reaches the max duration? How to get duration of the audio recording? HOT 1
- Trying to stream PCM16 over websockets to Google's Speech-to-Text API results in a jumbled mess. HOT 2
- Doesn't see Sampling frequency change when analyze with MKVToolNix
- Android recordings are unplayable on iOS [aacLc/.m4a] HOT 1
- Unexpected stereo output on Android devices when configuring mono audio recording HOT 2
- WEB: Exception on starting recording in chrome HOT 3
- Darwin installation HOT 2
- Record failed on macos. HOT 2
- define AudioRecorder in initstate without arguments HOT 1
- The app also picks up speaker sound
- Cannot choose a device to record HOT 6
- When will the new changes be published to pub.dev HOT 1
- No encoder found for {aac-profile=2, bitrate=128000, mime=audio/mp4a-latm, channel-count=1, sample-rate=44100}
- Safari on MacOS and iOS is very slow to start recording HOT 1
- The version >= 5.0.0 of the package encounters an error when the package on_audio_query: ^2.9.0 is present. HOT 1
- iOS AudioEncoder.wav Not supported
- On Safari or any browser on IOS no sound output HOT 1
- Audio files recorded by the record plugin are incorrectly saved without duration value HOT 2
- Error while trying to record HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from record.