flutterdartjust-audio

Problems with playlist not loading in just_audio app


Here is a simple code with just_audio (0.10.2) and just_audio_background(0.0.1-beta.16) and aprropriate permissions in AndroidManifest, mostly copied from the github repo. It works fine in debug mode but fails in build with Errors: I/flutter (25357): A stream error occurred: (2) Unexpected runtime error I/flutter (25357): Error loading playlist: (2) Unexpected runtime error. Here is the code. Can anyone help??

class TestFile extends StatefulWidget {
  const TestFile({super.key});

  @override
  State<TestFile> createState() => _TestFileState();
}

class _TestFileState extends State<TestFile> {
  static int _nextMediaId = 0;
  late AudioPlayer _player;
  bool isLoading = true;

  static final _playlist = [
    ClippingAudioSource(
      start: const Duration(seconds: 60),
      end: const Duration(seconds: 90),
      child: AudioSource.uri(
        Uri.parse(
          "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3",
        ),
      ),
      tag: MediaItem(
        id: '${_nextMediaId++}',
        album: "Science Friday",
        title: "A Salute To Head-Scratching Science (30 seconds)",
        artUri: Uri.parse(
          "https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
        ),
      ),
    ),
  ];

  @override
  void initState() {
    super.initState();
    _player = AudioPlayer(maxSkipsOnError: 3);
    SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(statusBarColor: Colors.black),
    );
    _init();
  }

  Future<void> _init() async {
    _player.errorStream.listen((e) {
      print('A stream error occurred: $e');
    });
    try {
      // Preloading audio is not currently supported on Linux.
      await _player.setAudioSources(_playlist,
  );
      setState(() {
        isLoading = false;
      });
    } on PlayerException catch (e) {
      // Catch load errors: 404, invalid url...
      print("Error loading playlist: $e");
    }
  }

  @override
  void dispose() {
    _player.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("test")),
      body:
          isLoading
              ? CircularProgressIndicator()
              : Column(
                children: [
                  ElevatedButton(
                    onPressed: () {
                      _player.play();
                    },
                    child: const Text("Play"),
                  ),
                  ElevatedButton(
                    onPressed: () {
                      _player.stop();
                    },
                    child: const Text("Stop"),
                  ),
                ],
              ),
    );
  }
}

Solution

  • There is not a bug in just_audio 10.2 causing this issue, but according to Ryan Heise the problem is with AGP 8.6 and 8.7 and the solution is to downgrade AGP to for example AGP 8.5.2 used in the official example (see issue #1468 on just_audio github).