搜索插件、代码仓与 APP 分类

插件详情v4.0.0+4

flutter_ringtone_player

一个用于系统默认铃声、闹钟和通知的简单播放器

AndroidiOS
近 30 天下载
2640
喜欢数
287
Pub 分数
150

安装插件

flutter pub add flutter_ringtone_player

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个轻量级的 Flutter 包,可在 Android 和 iOS 设备上播放系统默认铃声、闹钟和通知。它提供了一个简单的 API 来访问和播放内置的声音资源,无需外部文件处理。非常适合需要触发设备特定音频提示的应用程序,例如提醒、警报或通知声音。该包与原生平台音频系统无缝集成,并在两个平台上支持最小配置。

适合场景

  • 在提醒应用中播放系统铃声
  • 在任务管理工具中触发警报声音
  • 在消息应用中重现通知音
  • 在实用程序应用中模拟设备警报声音
  • 启用静音模式回退的铃声播放

主要特点

  • 访问系统默认铃声
  • 对 Android 和 iOS 的支持
  • 最小化设置和集成
  • 跨平台兼容性
  • 简单的播放控制API

适合对象

  • 开发提醒或警报类应用的开发者
  • 需要原生通知声音的应用
  • 需要设备音频反馈的实用工具
  • 面向 Android 和 iOS 的移动应用

使用建议

  • 需要适当的平台权限
  • 仅限系统提供的音频资源
  • 不支持自定义铃声文件
  • 行为在 Android 和 iOS 之间可能略有差异
  • 依赖于原生系统音频的可用性

原始 README

以下为关联源码仓库的 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,
);

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目