Home > Net >  Play music in background after killing the app in flutter
Play music in background after killing the app in flutter

Time:11-15

How can I impliment this functionality. I need to play music in background even after killing the app or we can after removing the from recently use.

I tried changes in the main file according to a video

import 'package:just_audio_background/just_audio_background.dart';
import 'package:flutter/material.dart';
import 'Home.dart';

Future<void> main() async {
  await JustAudioBackground.init(
    androidNotificationChannelId: 'com.ryanheise.bg_demo.channel.audio',
    androidNotificationChannelName: 'Audio playback',
    androidNotificationOngoing: true,
  );
  runApp(Home());
}

CodePudding user response:

  1. Remove audioplayer.dispose() wherever implemented.
  2. Checkout didChangeAppLifecycleState implementation which allows you to control the app in inactive, paused, resumed states
  • Related