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: loadAsset future does not fail when an error loading the file occurs. #146

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
### 2.1.7 ()
### 2.1.7 (29 Oct 2024)
- added `listPlaybackDevices` to get all the OS output devices available.
- added `deviceId` parameter to the `init()` method. You can choose which device is delegated to output the audio.
- added `changeDevice` method to change the playback device on-the-fly.
- added `changeDevice` method to change the output playback device on-the-fly.
- fix: now throws when loading a file that might be corrupt #145.

### 2.1.6 (17 Oct 2024)
- fixed a bug that caused an error when loading a sound more than twice.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/exceptions/exceptions_from_cpp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SoLoudFileLoadFailedException extends SoLoudCppException {
const SoLoudFileLoadFailedException([super.message]);

@override
String get description => 'The file was found, but could not be loaded '
String get description => 'File found, but could not be loaded! '
'Could be a permission error or the file is corrupted. '
'(on the C++ side).';
}

Expand Down
11 changes: 11 additions & 0 deletions lib/src/soloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ interface class SoLoud {
final completeFileName = result['completeFileName'] as String;
final hash = result['hash'] as int;

if (hash == 0) {
loadedFileCompleters[result['completeFileName']]
?.completeError(SoLoudCppException.fromPlayerError(error));
return;
}

final newSound = AudioSource(SoundHash(hash));
final alreadyLoaded = _activeSounds
.where((sound) => sound.soundHash == newSound.soundHash)
Expand All @@ -496,6 +502,8 @@ interface class SoLoud {
_activeSounds.add(newSound);
}
} else {
loadedFileCompleters[result['completeFileName']]
?.completeError(SoLoudCppException.fromPlayerError(error));
throw SoLoudCppException.fromPlayerError(error);
}
loadedFileCompleters[result['completeFileName']]?.complete(newSound);
Expand Down Expand Up @@ -535,6 +543,7 @@ interface class SoLoud {
/// Returns the new sound as [AudioSource].
///
/// Throws [SoLoudNotInitializedException] if the engine is not initialized.
/// Throws [SoLoudFileLoadFailedException] if the file could not be loaded.
///
/// If the file is already loaded, this is a no-op (but a warning
/// will be produced in the log).
Expand Down Expand Up @@ -631,6 +640,7 @@ interface class SoLoud {
/// Throws a [SoLoudTemporaryFolderFailedException] if there was a problem
/// creating the temporary file that the asset will be copied to.
/// Throws [SoLoudNotInitializedException] if the engine is not initialized.
/// Throws [SoLoudFileLoadFailedException] if the file could not be loaded.
///
/// Returns the new sound as [AudioSource].
///
Expand Down Expand Up @@ -673,6 +683,7 @@ interface class SoLoud {
/// Throws a [SoLoudTemporaryFolderFailedException] if there was a problem
/// creating the temporary file that the asset will be copied to.
/// Throws [SoLoudNotInitializedException] if the engine is not initialized.
/// Throws [SoLoudFileLoadFailedException] if the file could not be loaded.
///
/// Returns the new sound as [AudioSource].
///
Expand Down