FLUTTER ECOSYSTEM

inway/flutter_ringtone_player

簡單的 Flutter 插件,用於播放鈴聲、鬧鐘與通知聲音

flutter_ringtone_player 專案封面
Stars
102
Forks
108
最近推送(UTC)
2025年11月21日
專案狀態
未封存
InWay.pro GitHub avatar
GITHUB Organization

InWay.pro ↗

語言DartJavaObjective-CSwiftRubyDockerfileKotlin

技術主題

此儲存庫發佈的套件

使用的依賴

依賴清單 5 項
  • flutter{"sdk":"flutter"}
  • path_provider^2.1.1
  • plugin_platform_interface^2.1.7
  • flutter_test開發依賴{"sdk":"flutter"}
  • flutter_lints開發依賴>=3.0.1 <6.0.0

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

展開 / 收合專案 README

flutter_ringtone_player

A simple ringtone, alarm & notification player plugin.

pub package flutter

Usage

Add following import to your code:

import 'package:flutter_ringtone_player/flutter_ringtone_player.dart';

Then simply call this to play system default notification sound:

FlutterRingtonePlayer().playNotification();

There's also this generic method allowing you to specify in detail what kind of ringtone should be played:

FlutterRingtonePlayer().play(
  android: AndroidSounds.notification,
  ios: IosSounds.glass,
  looping: true, // Android only - API >= 28
  volume: 0.1, // Android only - API >= 28
  asAlarm: false, // Android only - all APIs
);

Also you can specify a custom ringtone from assets, or provide direct path to file that works for both Android and iOS:

FlutterRingtonePlayer().play(fromAsset: "assets/ringtone.wav");  
FlutterRingtonePlayer().play(fromFile: "assets/ringtone.wav");  

You can specify a platform specific ringtone and it will override the one from assets:

FlutterRingtonePlayer().play(  
 fromAsset: "assets/ringtone.wav", // will be the sound on Android
 ios: IosSounds.glass 			   // will be the sound on iOS
 );  
.play() optional attributes
Attribute Description
bool looping Enables looping of ringtone. Requires FlutterRingtonePlayer().stop(); to stop ringing.
double volume Sets ringtone volume in range 0 to 1.0.
bool asAlarm Allows to ignore device's silent/vibration mode and play given sound anyway.

To stop looped ringtone please use:

FlutterRingtonePlayer().stop();

Above works only on Android, and please note that by default Alarm & Ringtone sounds are looped.

Default sounds

Method Android iOS
playAlarm RingtoneManager.TYPE_ALARM IosSounds.alarm
playNotification RingtoneManager.TYPE_NOTIFICATION IosSounds.triTone
playRingtone RingtoneManager.TYPE_RINGTONE IosSounds.electronic
Note on iOS sounds

If you want to use any other sound on iOS you can always specify a valid Sound ID and manually construct [IosSound]:

FlutterRingtonePlayer().play(
  android: AndroidSounds.notification,
  ios: const IosSound(1023),
  looping: true,
  volume: 0.1,
);