title: Flutter - How to play ringtone from background task and let the user be able to stop it?
body: <p>I want to play a ringtone, while my flutter app is in the background, and let the user stop it.</p>
  <p>I want to play a ringtone after a specific interval that the user chooses (for example 3 minutes or 58 minutes), and then the user should be able to stop the ringtone. This works when the flutter app is in the foreground, but not when the app is in the background(For example when the screen is closed).</p>
  <p>I'm currently using the callbackDispatcher fron the Workmanager plugin for flutter, which creates a new Isolate. Let's call it <strong>isolate B</strong>, to distinguish it from <strong>isolate A</strong> that is created when flutter starts my app.</p>
  <p><strong>Here is the callbackDispatcher:</strong></p>
  <pre><code>void callbackDispatcher() {
    print('callbackDispatcher');
  
      FlutterRingtonePlayer.play(
        android: AndroidSounds.ringtone,
        ios: IosSounds.glass,
        looping: false,
        // Android only - API &gt;= 28
        volume: 1,
        // Android only - API &gt;= 28
        asAlarm: true, // Android only - all APIs
      );
  
      return Future.value(true);
    });
  }
  </code></pre>
  <p>The problems is that I can start playing the ringtone from Isolate B, but I don't know how to let the user stop it.</p>
  <p>So far I've tried:</p>
  <ul>
  <li>Calling FlutterRingtonePlayer.stop() from Isolate A when a notification is clicked, but that doesn't stop the ringtone that is playing in Isolate B.</li>
  <li>Starting the notification from Isolate B, and then stop the ringtone in Isolate B once clicked. But for some reason the notification doesn't popup when it's created in Isolate B.</li>
  <li>Calling FlutterRingtonePlayer.stop() from Isolate A, but that doesn't stop the ringtone that is playing in Isolate B.</li>
  <li>Making a global class with a method for playing and stopping ringtone and using it in Isolate B to play the ringtone and using it in Isolate A to stop the ringtone, but this also doesn't work...</li>
  </ul>
  <p>I don't know how to communicate with Isolate B that Workmanager creates, and it seems like their documentation doesn't specify how to communicate with the new Isolate that is created...</p>
  <p>What else can I try? My only goal is to play a Ringtone in background mode and let the user stop it.</p>