system_ringtone 0.0.1
system_ringtone: ^0.0.1 copied to clipboard
A production-ready Flutter plugin to fetch and play Android system ringtones, alarms, and notification sounds using RingtoneManager.
system_ringtone #
A production-ready Flutter plugin to fetch and play Android system ringtones, alarms, and notification sounds bypassing the limitations of the standard MediaPlayer using RingtoneManager.
Features #
- Fetch Ringtones: Get all notification, alarm, and ringtone sounds available on the Android device.
- Play Sounds: Directly play the ringtone URI bypassing the generic
MediaPlayerto correctly resolvecontent://URIs. - Volume Control: Change playback volume easily.
- Stop Sounds: Ensure only one ringtone plays at a time and stop them programmaticly.
- Duplicates Removal: Automatically deduplicates sounds that fall under multiple categories.
- Sorted: Returns an alphabetically sorted list of ringtones.
Platform Support #
Currently, this plugin only supports Android. iOS support is not included since Apple restricts access to system ringtones directly.
Installation #
Add system_ringtone to your pubspec.yaml:
dependencies:
system_ringtone: ^0.0.1
Usage #
Fetch Ringtones #
Returns a list of RingtoneItem containing the sound title and URI.
import 'package:system_ringtone/system_ringtone.dart';
// Fetch all available sounds
final List<RingtoneItem> sounds = await AndroidRingtonePlayer.getRingtones(
notification: true,
alarm: true,
ringtone: true,
);
Play and Stop Sounds #
import 'package:system_ringtone/system_ringtone.dart';
// Play a specific sound by passing its URI
await AndroidRingtonePlayer.play(
sounds.first.uri,
volume: 1.0, // range 0.0 to 1.0
);
// Stop the currently playing sound
await AndroidRingtonePlayer.stop();
Example App #
See the example directory for a complete sample app demonstrating how to fetch, list, and play system ringtones.