Skip to content

Commit

Permalink
Merge pull request #85 from alnitak/dev
Browse files Browse the repository at this point in the history
removed cpp exception check from setVolume
  • Loading branch information
alnitak authored May 23, 2024
2 parents bd77bb1 + fca6505 commit eadcac3
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 79 deletions.
8 changes: 7 additions & 1 deletion lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ enum PlayerErrors {
filterAlreadyAdded(15),

/// Player already inited.
playerAlreadyInited(16);
playerAlreadyInited(16),

/// Audio handle is not found
soundHandleNotFound(17);

const PlayerErrors(this.value);

Expand Down Expand Up @@ -152,6 +155,9 @@ enum PlayerErrors {
return 'Filter not found!';
case PlayerErrors.playerAlreadyInited:
return 'The player has already been inited!';
case PlayerErrors.soundHandleNotFound:
return 'The handle is not found! The playing handle could have been '
'stopped or ended and it is no more valid!';
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/exceptions/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ abstract class SoLoudCppException extends SoLoudException {
return const SoLoudFilterAlreadyAddedException();
case PlayerErrors.playerAlreadyInited:
return const SoLoudPlayerAlreadyInitializedException();
case PlayerErrors.soundHandleNotFound:
return const SoLoudSoundHandleNotFoundCppException();
}
}
}
15 changes: 14 additions & 1 deletion lib/src/exceptions/exceptions_from_cpp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SoLoudNullPointerException extends SoLoudCppException {
/// An exception that is thrown when SoLoud (C++) receives a sound hash
/// that is not found.
class SoLoudSoundHashNotFoundCppException extends SoLoudCppException {
/// Creates a new [SoLoudSoundHashNotFoundDartException].
/// Creates a new [SoLoudSoundHashNotFoundCppException].
const SoLoudSoundHashNotFoundCppException([super.message]);

@override
Expand Down Expand Up @@ -162,3 +162,16 @@ class SoLoudPlayerAlreadyInitializedException extends SoLoudCppException {
String get description => 'The player has already been initialized '
'(on the C++ side).';
}

/// An exception that is thrown when SoLoud (C++) receives a handle
/// that is not found. This could happen when trying to use the given handle
/// to get/set some of its attributes (like setting handle volume) after the
/// handle has been stopped/ended and hence it becomes invalid.
class SoLoudSoundHandleNotFoundCppException extends SoLoudCppException {
/// Creates a new [SoLoudSoundHandleNotFoundCppException].
const SoLoudSoundHandleNotFoundCppException([super.message]);

@override
String get description => 'The sound handle is not found '
'(on the C++ side).';
}
7 changes: 1 addition & 6 deletions lib/src/soloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1229,12 +1229,7 @@ interface class SoLoud {
if (!isInitialized) {
throw const SoLoudNotInitializedException();
}
final ret = SoLoudController().soLoudFFI.setVolume(handle, volume);
final error = PlayerErrors.values[ret];
if (error != PlayerErrors.noError) {
_log.severe(() => 'setVolume(): $error');
throw SoLoudCppException.fromPlayerError(error);
}
SoLoudController().soLoudFFI.setVolume(handle, volume);
}

/// Check if the [handle] is still valid.
Expand Down
Loading

0 comments on commit eadcac3

Please sign in to comment.