搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案