Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: flutterSoundHelper.convertFile crash on release app #710

Closed
Necrometal opened this issue Jun 30, 2021 · 52 comments
Closed

[BUG]: flutterSoundHelper.convertFile crash on release app #710

Necrometal opened this issue Jun 30, 2021 · 52 comments

Comments

@Necrometal
Copy link

Flutter Sound Version :

  • FULL flavor ?

  • Important: Result of the command : flutter pub deps | grep flutter_sound


Severity

  • Crash on release app

Platforms you faced the error

  • Android

  • Real device


Describe the bug
On debug mode, i used flutterSoundHelper.convertFile to convert the temp file created by the recorder to permanent file; i record on aac as temp and convert to premanent mp3; this work well on debug, but when i build a release app, record work well, but when on convert , the app crash,
i said that is the convert the problem cause i put a specifi button to convert aac to mp3, and when the button clicked, the app crash,


Logs!!!!

i put some try catch on my code to see the output, this is the log on debug

I/flutter (14966): ----------------------------------------
I/flutter (14966): convert start
I/flutter (14966): ----------------------------------------
D/flutter-ffmpeg(14966): Running FFmpeg with arguments: [-loglevel, error, -y, -i, /data/user/0/com.example.topos/cache/300621-19#58-Bornage-Immatriculation.aac, /storage/emulated/0/Topos/300621-19#58-Bornage-Immatriculation.mp3].
I/mobile-ffmpeg(14966): Loading mobile-ffmpeg.
I/mobile-ffmpeg(14966): Loaded mobile-ffmpeg-full-arm64-v8a-4.4-lts-20200724.
D/mobile-ffmpeg(14966): Callback thread started.
D/flutter-ffmpeg(14966): FFmpeg exited with rc: 0
I/flutter (14966): ----------------------------------------
I/flutter (14966): convert end
I/flutter (14966): ----------------------------------------

the aac file is the temp file, and the mp3 is the result of convert, the file is successfuly converted and it appear in the path where it would be. i don't know if this line "D/flutter-ffmpeg(14966): Running FFmpeg with arguments: [-loglevel, error, -y, -i, " mean something important or not cause this error text.

But on release this convert make the app crash.

Below screenshot of my full code to save the record

Screenshot_3

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

I have no idea :(

Have you any possibility to check if your AAC file is correct before trying to convert it on your release version ?

@Necrometal
Copy link
Author

I have no idea :(

Have you any possibility to check if your AAC file is correct before trying to convert it on your release version ?

my device is not rooted, so i think i can't check manualy, but ill try with File.exist()

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

I am not an expert, but maybe you can try "adb pull ..."

@Necrometal
Copy link
Author

I am not an expert, but maybe you can try "adb pull ..."

adb pull with device connected or no need?

i've tried to play the recorded (tmp file)on release and it work, make a dialog to show if file exit or not and it exist

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

ok. If you can play your AAC temporary file, it is certainly correct.

Actually I have no idea.
Does someone else can help ?

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

Try to do a convert to an "xxx.opus" file.
Just to see if the crash is because .mp3. (Mobile FFmpeg use lame to encode mp3. But lame is not supposed to be in a released app).
I guess that you will get the same crash, but just try ...

@Necrometal
Copy link
Author

Try to do a convert to an "xxx.opus" file.
Just to see if the crash is because .mp3. (Mobile FFmpeg use lame to encode mp3. But lame is not supposed to be in a released app).
I guess that you will get the same crash, but just try ...

you mean opus extension?

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

yes

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

😄

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

The extension really must be ".opus" instead of ".mp3" for your test. FFmpeg uses the extension to select the correct output
codec.

@Necrometal
Copy link
Author

so tried to convert to obus using Codec.obusCAF and Codec.obusOGG, tried with aac to aac, all crash :(

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

:(

Did you try to connect your device to your computer and do a "flutter run --release" ?
We really need logs ...

@Necrometal
Copy link
Author

Necrometal commented Jun 30, 2021

at the last line, it crash
i record, stop record, play the file recorded, pause it,
and when try to convert, it end like that
Screenshot_4

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

Interesting.

Can you try to replace the special char "#" in your filename to something else ?

@Necrometal
Copy link
Author

same thing
Screenshot_5

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

I must study your log now.
I I do not understand why there is a "pausePlayer()" before your convert.
You should have a "stopPlayer()" and not a "pausePlayer()"

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

The sequence seems incorrect : The player is paused and not stopped during the convert.

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

But this does not explain why a crash

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

The sequence is correct in your last logs.

I am stuck. No idea.

@Necrometal
Copy link
Author

I must study your log now.
I I do not understand why there is a "pausePlayer()" before your convert.
You should have a "stopPlayer()" and not a "pausePlayer()"
in this line i'm playing the record :/

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

Of course you use the full flavor of flutter sound, and not the lite ? don't you ?

@Necrometal
Copy link
Author

Of course you use the full flavor of flutter sound, and not the lite ? don't you ?

honestly i don't know .
i just use this this

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

What is the result of :

flutter pub deps | grep flutter_sound

?

@Necrometal
Copy link
Author

What is the result of :

flutter pub deps | grep flutter_sound

?

i'm using vscode, so i just copy the dependence on pubspec and it pub automaticly ^^"

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

Just check the command

flutter pub deps | grep flutter_sound

We will know which version flutter had selected

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

Or just :
flutter pub deps

if you do not have a regular shell

@Necrometal
Copy link
Author

i removed the dependence from pubspec and added it manually with flutter pub add flutter_sound

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

I insist you do a "flutter pub deps" to be sure which flutter_sound version is selected

@Necrometal
Copy link
Author

Screenshot_6

@Larpoux
Copy link
Collaborator

Larpoux commented Jun 30, 2021

This is correct.

I am sorry, Necro, I am stuck. Someone else can help ?

@Necrometal
Copy link
Author

This is correct.

I am sorry, Necro, I am stuck. Someone else can help ?

just a question , have you already use the converter on a little project? :)
i think if you tried to make it yourself in little project can maybe help if its not a package bug :)

@mhstoller
Copy link

Might be better off using flutter sound lite and including ffmpeg as a separate dependency and running the commands directly.

Flutter_ffmpeg likes to crash or output weird things when multiple jobs are run concurrently. I had to create a queue system for ffmpeg calls to work around this. I'm sure there are other quirks and something like that could be causing this issue.

Best way forward is probably to run ffmpeg directly so you have full control over the process

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 1, 2021

I agree with @mhstoller.
Actually Flutter Sound Full is linked with Flutter FFmpeg FULL. Flutter FFmpeg FULL is huge and probably you do not need all the video stuff. The current link of Flutter Sound FULL is a kind of hack to be able to play directly Opus files on iOS.

If you use Flutter Sound Lite and put a dependency on "Flutter FFmpeg Audio" (or maybe even a lighter library),
you will have something more clean and more lite.

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 1, 2021

@mhstoller :

I am not surprised that you got some concurrency issues using Flutter Ffmpeg.
All the Flutter Sound verbs are protected with an interlock semaphore.
But I did not realized that Convert() must be also protected with this interlock semaphore.

Someone (me?) should add a few lines of code to achieve that.

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 1, 2021

just a question , have you already use the converter on a little project? :)
i think if you tried to make it yourself in little project can maybe help if its not a package bug :)

Yes. Definitely. I began to write several few very simple test app. The purpose of those little tests are to show and test only one or two Flutter Sound feature at a time.
We must code a new very little test for the Convert routine.

@Necrometal :
I will do some tests and fix concurrency issues if any, tomorrow.
Please wait a few days.
I am sorry that you get problems with Flutter Sound.

@Necrometal
Copy link
Author

just a question , have you already use the converter on a little project? :)
i think if you tried to make it yourself in little project can maybe help if its not a package bug :)

Yes. Definitely. I began to write several few very simple test app. The purpose of those little tests are to show and test only one or two Flutter Sound feature at a time.
We must code a new very little test for the Convert routine.

@Necrometal :
I will do some tests and fix concurrency issues if any, tomorrow.
Please wait a few days.
I am sorry that you get problems with Flutter Sound.

Not problem dude :) for moment i used to record the sound directly on perment file xD
But record an mp3 is not allowed right? i tried on record to mp3 but no sound when playing the file.

@Necrometal
Copy link
Author

Might be better off using flutter sound lite and including ffmpeg as a separate dependency and running the commands directly.

Flutter_ffmpeg likes to crash or output weird things when multiple jobs are run concurrently. I had to create a queue system for ffmpeg calls to work around this. I'm sure there are other quirks and something like that could be causing this issue.

Best way forward is probably to run ffmpeg directly so you have full control over the process

Have you please any tutorial for doing the FFmpeg separately?

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 2, 2021

Yes. Android and iOS does not allow us to record mp3.
What you are trying to do is correct : record AAC (for example) and then do a convert to mp3 with ffmpeg.

I am writing a little test for Convert. I will tell you when done.

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 2, 2021

Have you please any tutorial for doing the FFmpeg separately?

The documentation is on the Flutter FFmpeg site.
You must add a dependency to Flutter_FFmpeg and you must link your android App with Mobile FFmpeg.
I think that this link is not obvious. It is the reason for which I linked Flutter Sound to Fluttter FFmpeg, so that Flutter Sound users does not bother with that.

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 2, 2021

Wait until tomorrow. I will have a new Flutter Sound with an example of Convert AAC to MP3.

@Necrometal
Copy link
Author

Wait until tomorrow. I will have a new Flutter Sound with an example of Convert AAC to MP3.

ok thanks :)

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 2, 2021

Is there any reason you try to convert during a PausePlayer() ?

@Necrometal
Copy link
Author

Is there any reason you try to convert during a PausePlayer() ?

Not at all, i just use my app like guest user xD, i just paused the audio for no reason and save (convert) like nothing happen

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 2, 2021

OK. I will keep my example very simple :

  • Convert an AAC file to MP3
  • Play the MP3

@Necrometal
Copy link
Author

so the sound must be stopped to be converted?

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 2, 2021

No.
I just asked to be similar in my test with your App

@Necrometal
Copy link
Author

No.
I just asked to be similar in my test with your App

okay, i'll wait for your up tomorrow

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 3, 2021

Necro,
I am able to reproduce your issue on my development environment.

The problem is a problem in Mobile FFmpeg : Here
@tanersener published a work-around. I am going to try this work-around this afternoon.

Then I will post more informations in this thread.

@Larpoux
Copy link
Collaborator

Larpoux commented Jul 3, 2021

Hi Necro,

Flutter Sound 8.1.9 is released.
This version has a fix for your issue.

You must also check your build.gradle :

  • Remove any reference to repository jcenter()
  • Add a reference to mavenCentral() if not already done

I wrote a very simple example here that record an AAC audio, convert it to MP3 and playback it.
You probably do not need any more this example : your code was correct and the problem was on Flutter FFmpeg.

Thank you for your patience

@Necrometal
Copy link
Author

Necrometal commented Jul 3, 2021

Hi Necro,

Flutter Sound 8.1.9 is released.
This version has a fix for your issue.

You must also check your build.gradle :

  • Remove any reference to repository jcenter()
  • Add a reference to mavenCentral() if not already done

I wrote a very simple example here that record an AAC audio, convert it to MP3 and playback it.
You probably do not need any more this example : your code was correct and the problem was on Flutter FFmpeg.

Thank you for your patience

Thanks :) i'll test it and give you a feedback

@Necrometal
Copy link
Author

it work on flutter run --release, i think it'll work on build release too :) thanks.

i have another thing to ask if you can check this one please ^^

@ThinkerJack
Copy link

Hi Necro,
Flutter Sound 8.1.9 is released.
This version has a fix for your issue.
You must also check your build.gradle :

  • Remove any reference to repository jcenter()
  • Add a reference to mavenCentral() if not already done

I wrote a very simple example here that record an AAC audio, convert it to MP3 and playback it.
You probably do not need any more this example : your code was correct and the problem was on Flutter FFmpeg.
Thank you for your patience

Thanks :) i'll test it and give you a feedback

good job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants