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

fix: SoLoudFileLoadFailedException (SoLoudFileLoadFailedException: File found, but could not be loaded! Could be a permission error or the file is corrupted. (on the C++ side).) #181

Open
Miamlya opened this issue Feb 14, 2025 · 7 comments
Labels
bug Something isn't working

Comments

@Miamlya
Copy link

Miamlya commented Feb 14, 2025

Description

When I run the app, while initializing sources within my static class, I get this exception using VSCode, Flutter - Windows.

    hoverSource = await SoLoud.instance.loadAsset('assets/sounds/hover_1.mp3');

I initialized SoLoud in the main() function and I ran AudioEffects.initialize as showed in the example.

AudioEffects class:

`import 'package:flutter_soloud/flutter_soloud.dart';

class AudioEffects {
  var soloud = SoLoud.instance.init();
  static double _volume = 1.0;

  static AudioSource? hoverSource;
  static AudioSource? clickSource;

  static void initialize() async {
    clickSource = await SoLoud.instance.loadAsset('assets/sounds/click_1.wav');
    hoverSource = await SoLoud.instance.loadAsset('assets/sounds/hover_1.mp3');
  }

  static setVolume(double volume) {
    AudioEffects._volume = volume;
  }

  static playHover() async {
    final handle = await SoLoud.instance.play(hoverSource!);
    SoLoud.instance.setVolume(handle, _volume);
  }

  static playClick() async {
    final handle = await SoLoud.instance.play(clickSource!);
    SoLoud.instance.setVolume(handle, _volume);
  }
}

main.dart:

...
  WidgetsFlutterBinding.ensureInitialized();
  /// Initialize the player.
  await SoLoud.instance.init();
  AudioEffects.initialize();
  runApp(const MyApp());
}

Expected Behavior

Play sound

Screenshots

Image

Image

Additional Context

Add any other context about the problem here.

@Miamlya Miamlya added the bug Something isn't working label Feb 14, 2025
@alnitak
Copy link
Owner

alnitak commented Feb 14, 2025

Hi @Miamlya,

at first sight, I see you are calling init in a class parameter. This is wrong and you are initializing already in the main:
var soloud = SoLoud.instance.init();

I think you can safely remove that line or declare it as var soloud = SoLoud.instance; and use soloud in the other parts of AudioEffects class.

I see also in the main that you call AudioEffects.initialize(); without the await. This could be the cause of the problem.

Feel free to ask if you have any doubts and to close this issue if this helps.

@Miamlya
Copy link
Author

Miamlya commented Feb 14, 2025

Thank you for your reply. It is MP3 format. Tried with a few other mp3 files. Same error. WAV files play just fine. Also, I get the same problem with example() method.

void example() async {
  final soloud = SoLoud.instance;

  await soloud.init();

// **Error** SoLoudFileLoadFailedException (SoLoudFileLoadFailedException: File found, but could not be loaded! Could be a permission error or the file is corrupted. (on the C++ side).)
  final source = await soloud.loadAsset('assets/sounds/hover_1.mp3');
// **Works**
  final source = await soloud.loadAsset('assets/sounds/click_1.wav');

  final handle = await soloud.play(source);
}

@alnitak
Copy link
Owner

alnitak commented Feb 14, 2025

As the error said, it could be a problem with the mp3. Maybe it is encoded with some non-common format that dr_mp3.h (which is the decoder used by the native SoLoud C++ lib uses) cannot manage.

Could you please provide me hover_1.mp3 for testing?

@Miamlya
Copy link
Author

Miamlya commented Feb 14, 2025

@alnitak
Copy link
Owner

alnitak commented Feb 14, 2025

It seems it is an issue for very short mp3s coming from dr_mp3.h.

Unfortunately, I cannot do much about this issue.

My suggestion is to convert it to wav with something like ffmpeg -i test.mp3 test.wav. The file will grow from 25 to 46 KB.

@novas1r1
Copy link

Hey,
I just checked my crashlogging and out of 300 users I have 100 users affected with this error as well - 90% android/10% ios users. Unfortunately I cannot tell more at the moment, I will try to add more context to my crashlogging to be able to give more information. Is there any way to detect if its a permission error or if the file is corrupted? If it's corrupted I could guide the user to a converter.

Thank youu :)

@alnitak
Copy link
Owner

alnitak commented Feb 23, 2025

Hey Verry,

unfortunately I don't have many thoughts. Do users want to open these very short mp3 files for use in your app?

I have no experience on iOS, but on Android if you have the media permission you can open all the music files stored in the Music folder. If you are using a file picker it will copy the media to your app sandbox and your app for sure has the permission to open it.

As soon as you have some more info, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants