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

Airy snackbar sound #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

amir-azari
Copy link

Add Sound Support to AirySnackbar

Description

Added sound capability to AirySnackbar library, allowing users to include sound effects when displaying snackbars. This feature includes:

  • A default notification sound
  • Option to use custom sounds
  • Option to disable sounds

Changes Made

Added New Features

  • Added SoundAttribute sealed class with three options:
    • Custom: For custom sound resources
    • UseDefault: Uses library's default notification sound
    • NoSound: Disables sound (default behavior)

Code Changes

  • Added sound playback functionality to AirySnackbarView
  • Added proper resource cleanup in onDetachedFromWindow
  • Integrated sound support in the main snackbar builder

Usage Examples

// Using default sound
AirySnackbar.make(
    source = AirySnackbarSource.ActivitySource(this),
    type = Type.Success,
    attributes = listOf(
        TextAttribute.Text("Success!"),
        SoundAttribute.UseDefault
    )
).show()

// Using custom sound
AirySnackbar.make(
    source = AirySnackbarSource.ActivitySource(this),
    type = Type.Success,
    attributes = listOf(
        TextAttribute.Text("Success!"),
        SoundAttribute.Custom(R.raw.my_custom_sound)
    )
).show()

Testing

  • Tested sound playback on various Android versions
  • Verified proper resource cleanup
  • Confirmed compatibility with existing snackbar features

Additional Notes

  • Default sound resource must be added to the library's raw resources
  • Clean handling of MediaPlayer lifecycle to prevent memory leaks
  • Maintains backward compatibility with existing implementations

Breaking Changes

None. This is a purely additive feature.

Add a new method `playSound` to play a sound resource.
Add `airy_default.mp3` as a default sound.
Release the media player in `onDetachedFromWindow`.
- Add a new "Sound on" button to the layout.
- Add a sound notification feature to the library.
- Add a new string resource for "Sound on".
- Add `VolumeLevel` value class to represent a volume level between 0.0 and 1.0.
- Update `playSound` in `AirySnackbarView` to accept `volumeLevel`.
- Update `SoundAttribute` to include `Volume` and modify `Custom` to accept an optional `volumeLevel`.
- Update sound logic in `AirySnackbar` to support the new attributes.
@amir-azari
Copy link
Author

@akndmr Hello! I've introduced volume control functionality for the sound system. Whenever you get a chance, I would appreciate your review and feedback. Thank you! 🙏

🔊 Added Volume Control to AirySnackbar Sound System

Changes Made

  • Added VolumeLevel class for flexible volume control
  • Enhanced SoundAttribute to support volume adjustment
  • Added volume control to sound playback system

Implementation Details

  • Volume can be set between 0.0 (mute) and 1.0 (max)
  • Default volume level is 0.15
  • Added volume support to both default and custom sounds

Code Examples

// Default sound with custom volume
AirySnackbar.make(
    source = AirySnackbarSource.ActivitySource(this),
    type = Type.Success,
    attributes = listOf(
        TextAttribute.Text("Success!"),
        SoundAttribute.Volume(VolumeLevel.of(0.65f))
    )
).show()

// Default behavior (0.15 volume)
AirySnackbar.make(
    source = AirySnackbarSource.ActivitySource(this),
    type = Type.Success,
    attributes = listOf(
        TextAttribute.Text("Success!"),
        SoundAttribute.UseDefault
    )
).show()

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

Successfully merging this pull request may close these issues.

1 participant