flutter audioplayers plugin don't play sound instead freezes the app

2,842

Since you are using the ^, it is upgrading you to the 0.16.x (the latest with primary version number 0)

Most likely you installed the latest available package of audioplayers (0.16.0), they have an issue that causes apps to crash on iOS devices https://github.com/luanpotter/audioplayers/issues/613 You can simply downgrade to 0.15.1 (remove the ^) in your pubspec.yaml and run packages get command to make it work

Share:
2,842
AKKAY GAMING
Author by

AKKAY GAMING

Updated on December 22, 2022

Comments

  • AKKAY GAMING
    AKKAY GAMING over 1 year

    I am using flutter plugin audioplayers: ^0.15.1, the below code is working in Android but not working in IOS instead of freezing the app.

    I run the code in ios simulator and click the button. It supposes the play the mp3 file, but no sound at all. And the app gets frozen. Same problem with assets_audio_player plugin.

    Please help to solve this issue.

    import 'package:flutter/material.dart';
    import 'package:audioplayers/audio_cache.dart';
    
    void main() => runApp(XylophoneApp());
    
    class XylophoneApp extends StatelessWidget {
      void playNote(int noteNO) {
        final player = AudioCache();
        player.play('note$noteNO.wav');
      }
    
      Expanded buildKey(int no, Color color) {
        return Expanded(
          child: FlatButton(
            color: color,
            onPressed: () {
              playNote(no);
            },
          ),
        );
      }
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            backgroundColor: Colors.black,
            body: SafeArea(
              child: Center(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    buildKey(1,Colors.red),
                    buildKey(2,Colors.orange),
                    buildKey(3,Colors.yellow),
                    buildKey(4,Colors.green),
                    buildKey(5,Colors.blue),
                    buildKey(6,Colors.indigo),
                    buildKey(7,Colors.purple),
                  ],
                ),
              ),
            ),
          ),
        );
      }
    }
    
    void playNote(int noteNO) {
      final player = AudioCache();
      player.play('note$noteNO.wav');
    }
    

    debug console:Screenshot

    iOS => call startHeadlessService, playerId 6178a81e-22dc-485b-bfc8-f6a8402f518e
    iOS => call play, playerId 6178a81e-22dc-485b-bfc8-f6a8402f518e
    play!
    isLocal: 1 1
    volume: 1.000000 1
    position: 0 (null)
    setUrl /Users/akshay/Library/Developer/CoreSimulator/Devices/575F03D0-0EBE-4813-970A-14128CEF49ED/data/Containers/Data/Application/394C51F0-1ABD-4315-921A-F92E97CC1F98/Library/Caches/note5.wav
    [VERBOSE-2:profiler_metrics_ios.mm(184)] Error retrieving thread information: (ipc/send) invalid destination port
    player status: 2
    player status: 2
    player status: 2