Getting Started

Getting Started..

Playback

The complete running example is there

1. FlutterSoundPlayer instanciation

To play back something you must instanciate a player. Most of the time, you will need just one player, and you can place this instanciation in the variables initialisation of your class :

  import 'package:flauto/flutter_sound.dart';
...
  FlutterSoundPlayer _myPlayer = FlutterSoundPlayer();

2. Open and close the audio session

Before calling startPlayer() you must open the Session.

When you have finished with it, you must close the session. A good places to put those verbs are in the procedures initState() and dispose().

@override
  void initState() {
    super.initState();
    // Be careful : openAudioSession return a Future.
    // Do not access your FlutterSoundPlayer or FlutterSoundRecorder before the completion of the Future
    _myPlayer.openAudioSession().then((value) {
      setState(() {
        _mPlayerIsInited = true;
      });
    });
  }



  @override
  void dispose() {
    // Be careful : you must `close` the audio session when you have finished with it.
    _myPlayer.closeAudioSession();
    _myPlayer = null;
    super.dispose();
  }

3. Play your sound

To play a sound you call startPlayer(). To stop a sound you call stopPlayer()

Recording

The complete running example is there

1. FlutterSoundRecorder instanciation

To play back something you must instanciate a recorder. Most of the time, you will need just one recorder, and you can place this instanciation in the variables initialisation of your class :

2. Open and close the audio session

Before calling startRecorder() you must open the Session.

When you have finished with it, you must close the session. A god place to pute those verbs is in the procedures initState() and dispose().

3. Record something

To record something you call startRecorder(). To stop the recorder you call stopRecorder()

Last updated

Was this helpful?