Git Product home page Git Product logo

flutter_ringtone_player's Introduction

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 that works for both Android and iOS:

FlutterRingtonePlayer.play(fromAsset: "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,
);

flutter_ringtone_player's People

Contributors

spodjasek avatar dependabot[bot] avatar georgeamgad avatar wrbl606 avatar aarajput avatar andzejsw avatar pietroid avatar t1ooo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.