Skip to content

Commit b6eba63

Browse files
committed
fix: loadAsset future does not fail when an error loading the file occurs. #145
1 parent 850994f commit b6eba63

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
### 2.1.7 ()
1+
### 2.1.7 (29 Oct 2024)
22
- added `listPlaybackDevices` to get all the OS output devices available.
33
- added `deviceId` parameter to the `init()` method. You can choose which device is delegated to output the audio.
4-
- added `changeDevice` method to change the playback device on-the-fly.
4+
- added `changeDevice` method to change the output playback device on-the-fly.
5+
- fix: now throws when loading a file that might be corrupt #145.
56

67
### 2.1.6 (17 Oct 2024)
78
- fixed a bug that caused an error when loading a sound more than twice.

lib/src/exceptions/exceptions_from_cpp.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class SoLoudFileLoadFailedException extends SoLoudCppException {
3131
const SoLoudFileLoadFailedException([super.message]);
3232

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

lib/src/soloud.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ interface class SoLoud {
475475
final completeFileName = result['completeFileName'] as String;
476476
final hash = result['hash'] as int;
477477

478+
if (hash == 0) {
479+
loadedFileCompleters[result['completeFileName']]
480+
?.completeError(SoLoudCppException.fromPlayerError(error));
481+
return;
482+
}
483+
478484
final newSound = AudioSource(SoundHash(hash));
479485
final alreadyLoaded = _activeSounds
480486
.where((sound) => sound.soundHash == newSound.soundHash)
@@ -496,6 +502,8 @@ interface class SoLoud {
496502
_activeSounds.add(newSound);
497503
}
498504
} else {
505+
loadedFileCompleters[result['completeFileName']]
506+
?.completeError(SoLoudCppException.fromPlayerError(error));
499507
throw SoLoudCppException.fromPlayerError(error);
500508
}
501509
loadedFileCompleters[result['completeFileName']]?.complete(newSound);
@@ -535,6 +543,7 @@ interface class SoLoud {
535543
/// Returns the new sound as [AudioSource].
536544
///
537545
/// Throws [SoLoudNotInitializedException] if the engine is not initialized.
546+
/// Throws [SoLoudFileLoadFailedException] if the file could not be loaded.
538547
///
539548
/// If the file is already loaded, this is a no-op (but a warning
540549
/// will be produced in the log).
@@ -631,6 +640,7 @@ interface class SoLoud {
631640
/// Throws a [SoLoudTemporaryFolderFailedException] if there was a problem
632641
/// creating the temporary file that the asset will be copied to.
633642
/// Throws [SoLoudNotInitializedException] if the engine is not initialized.
643+
/// Throws [SoLoudFileLoadFailedException] if the file could not be loaded.
634644
///
635645
/// Returns the new sound as [AudioSource].
636646
///
@@ -673,6 +683,7 @@ interface class SoLoud {
673683
/// Throws a [SoLoudTemporaryFolderFailedException] if there was a problem
674684
/// creating the temporary file that the asset will be copied to.
675685
/// Throws [SoLoudNotInitializedException] if the engine is not initialized.
686+
/// Throws [SoLoudFileLoadFailedException] if the file could not be loaded.
676687
///
677688
/// Returns the new sound as [AudioSource].
678689
///

0 commit comments

Comments
 (0)