skip to Main Content

I’m coding an alarm app using Flutter (Android only, for now).

I managed to play the alarm using a notification. But it only works when the phone isn’t in Silent Mode.

Is there a way to build such an app using Flutter? Playing the sound no matter the state of the phone is the core functionality of the app. If this isn’t possible, I should stop the development of this app.

Already tried using a sound played by AwesomeNotifications plugin (using Alarm Type with max priority) and a sound played by FlutterRingtonePlayer (triggered by a notification).

Flutter 3.3.5 • channel stable

Physical device used to test is running Android 13

Edit: as the app is an alarm, an isolate will play the sound.

3

Answers


  1. MediaPlayer mp= MediaPlayer.create(contexto, R.raw.your_sound);
    mp.start();
    

    You should call this when you start your alarm(you should call this in native code)

    Login or Signup to reply.
  2. 1-Add sound_mode as a dependency in your pubspec.yaml file

    dependencies:
    flutter:
    sdk: flutter
    flutter_localizations:
    sdk: flutter

    sound_mode: ^2.0.2

    2-Add the following permission to AndroidManifest.xml for the app to appear in the ‘Do Not Disturb Access’ list :

    <manifest ... >
        <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
        
        <application ... >
        ...
    </manifest>
    

    To change the device’s sound mode:

    import 'package:sound_mode/utils/ringer_mode_statuses.dart';
    
    //To get the device's current sound mode:
    String ringerStatus = await SoundMode.ringerModeStatus;
    print(ringerStatus);
    
    // To change the device's sound mode: silent to normal.
    if(ringerStatus == 'silent'){
       try {
          await SoundMode.setSoundMode(RingerModeStatus.normal);
         } on PlatformException {
         print('Please enable permissions required');
        }
    }
    
    // your code here : play a sound
         
    
    Login or Signup to reply.
  3. Once try with this because this package is providing functionality to work in silent mode also.

    assets_audio_player: ^3.0.6
    

    https://pub.dev/packages/assets_audio_player

    https://i.stack.imgur.com/qbjFB.png

    I hope this things are solve your issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search