arrow-left

All pages
gitbookPowered by GitBook
1 of 12

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

The Ï„ Recorder API

setAudioFocus()

hashtag
-

hashtag
setAudioFocus()

  • Dart API:

hashtag
focus: parameter possible values are

  • AudioFocus.requestFocus (request focus, but do not do anything special with others App)

  • AudioFocus.requestFocusAndStopOthers (your app will have exclusive use of the output audio)

  • AudioFocus.requestFocusAndDuckOthers (if another App like Spotify use the output audio, its volume will be lowered)

hashtag
Other parameters :

Please look to to understand the meaning of the other parameters

Example:

</div>

AudioFocus.requestFocusAndKeepOthers (your App will play sound above others App)

  • AudioFocus.requestFocusAndInterruptSpokenAudioAndMixWithOthers

  • AudioFocus.requestFocusTransient (for Android)

  • AudioFocus.requestFocusTransientExclusive (for Android)

  • AudioFocus.abandonFocus (Your App will not have anymore the audio focus)

  • setAudioFocusarrow-up-right
    openAudioSession()arrow-up-right
    Dart
    Javascript
    
            myPlayer.setAudioFocus(focus: AudioFocus.requestFocusAndDuckOthers);
    
            Lorem ipsum ...

    recorder

    The Ï„ Recorder API

    setSubscriptionDuration()

    hashtag
    setSubscriptionDuration()

    • Dart API: setSubscriptionDurationarrow-up-right

    This verb is used to change the default interval between two post on the "Update Progress" stream. (The default interval is 0 (zero) which means "NO post")

    Example:

    </div>

    Flutter Sound Helpers API

    constructor

    hashtag
    Module instanciation

    • Dart API: constructorarrow-up-right

    You do not need to instanciate the Flutter Sound Helper module. To use this module, you can just use the singleton offers by the module : flutterSoundHelper.

    Example:

    </div>

    The Ï„ Recorder API

    `recorderState`, `isRecording`, `isPaused`, `isStopped`.

    hashtag
    recorderState, isRecording, isPaused, isStopped

    • Dart API:

    • Dart API:

    • Dart API:

    • Dart API:

    This four attributs is used when the app wants to get the current Audio State of the recorder.

    recorderState is an attribut which can have the following values :

    • isStopped /// Recorder is stopped

    • isRecording /// Recorder is recording

    • isPaused /// Recorder is paused

    Example:

    </div>

    The Ï„ Recorder API

    stopRecorder()

    hashtag
    stopRecorder()

    • Dart API: stopRecorderarrow-up-right

    Use this verb to stop a record. This verb never throws any exception. It is safe to call it everywhere, for example when the App is not sure of the current Audio State and want to recover a clean reset state.

    Example:

    </div>

    The Ï„ Recorder API

    resumeRecorder()

    hashtag
    resumeRecorder()

    • Dart API: resumeRecorderarrow-up-right

    On Android this API verb needs al least SDK-24. An exception is thrown if the Recorder is not currently paused.

    Example:

    </div>

    The Ï„ Recorder API

    `openAudioSession()` and `closeAudioSession()`

    hashtag
    openAudioSession() and closeAudioSession()

    • Dart API: openAudioSessionarrow-up-right

    • Dart API:

    A recorder must be opened before used. A recorder correspond to an Audio Session. With other words, you must open the Audio Session before using it. When you have finished with a Recorder, you must close it. With other words, you must close your Audio Session. Opening a recorder takes resources inside the OS. Those resources are freed with the verb closeAudioSession().

    You MUST ensure that the recorder has been closed when your widget is detached from the UI. Overload your widget's dispose() method to close the recorder when your widget is disposed. In this way you will reset the player and clean up the device resources, but the recorder will be no longer usable.

    You maynot openAudioSession many recorders without releasing them. You will be very bad if you try something like :

    openAudioSession() and closeAudioSession() return Futures. You may not use your Recorder before the end of the initialization. So probably you will await the result of openAudioSession(). This result is the Recorder itself, so that you can collapse instanciation and initialization together with myRecorder = await FlutterSoundPlayer().openAudioSession();

    The four optional parameters are used if you want to control the Audio Focus. Please look to to understand the meaning of those parameters

    Example:

    </div>

    The Ï„ Recorder API

    isEncoderSupported()

    hashtag
    isEncoderSupported()

    • Dart API: isEncoderSupportedarrow-up-right

    This verb is useful to know if a particular codec is supported on the current platform; Return a Future.

    Example:

    </div>

    The Ï„ Recorder API

    pauseRecorder()

    hashtag
    pauseRecorder()

    • Dart API: pauseRecorderarrow-up-right

    On Android this API verb needs al least SDK-24. An exception is thrown if the Recorder is not currently recording.

    Example:

    </div>

    The Ï„ Recorder API

    startRecorder()

    hashtag
    startRecorder()

    • Dart API: startRecorderarrow-up-right

    You use startRecorder() to start recording in an open session. startRecorder() has the destination file path as parameter. It has also 7 optional parameters to specify :

    • codec: The codec to be used. Please refer to the to know which codecs are currently supported.

    • toFile: a path to the file being recorded

    • toStream: if you want to record to a Dart Stream. Please look to . This new functionnality needs, at least, Android SDK >= 21 (23 is better)

    can be useful if you want to get access to some directories on your device.

    Flutter Sound does not take care of the recording permission. It is the App responsability to check or require the Recording permission. is probably useful to do that.

    Example:

    </div>

    The Ï„ Recorder API

    onProgress

    hashtag
    onProgress

    • Dart API: onProgressarrow-up-right

    The attribut onProgress is a stream on which FlutterSound will post the recorder progression. You may listen to this Stream to have feedback on the current recording.

    Example:

    </div>

    
            // 0 is default
            myRecorder.setSubscriptionDuration(0.010);
    
            Lorem ipsum ...
    Dart
    Javascript
    
            Duration t = await flutterSoundHelper.duration(aPathFile);
    
            Lorem ipsum ...
    Dart
    Javascript
    isRecording is a boolean attribut which is true when the recorder is in the "Recording" mode.
  • isPaused is a boolean atrribut which is true when the recorder is in the "Paused" mode.

  • isStopped is a boolean atrribut which is true when the recorder is in the "Stopped" mode.

  • recorderStatearrow-up-right
    isRecordingarrow-up-right
    isPausedarrow-up-right
    isStoppedarrow-up-right
    Dart
    Javascript
    
            await myRecorder.stopRecorder();
            if (_recorderSubscription != null)
            {
                    _recorderSubscription.cancel();
                    _recorderSubscription = null;
            }
    
            Lorem ipsum ...
    Dart
    Javascript
    
            await myRecorder.resumeRecorder();
    
            Lorem ipsum ...
    Dart
    Javascript
    closeAudioSessionarrow-up-right
    FlutterSoundPlayer openAudioSession()arrow-up-right
    Dart
    Javascript
    
           if ( await myRecorder.isEncoderSupported(Codec.opusOGG) ) doSomething;
    
            Lorem ipsum ...
    Dart
    Javascript
    
            await myRecorder.pauseRecorder();
    
            Lorem ipsum ...
    Dart
    Javascript

    sampleRate: The sample rate in Hertz

  • numChannels: The number of channels (1=monophony, 2=stereophony)

  • bitRate: The bit rate in Hertz

  • audioSource : possible value is :

    • defaultSource

    • microphone

    • voiceDownlink (if someone can explain me what it is, I will be grateful ;-) )

  • Codec compatibility Tablearrow-up-right
    the following noticearrow-up-right
    path_providerarrow-up-right
    Permission_handlerarrow-up-right
    Dart
    Javascript
    
            _recorderSubscription = myrecorder.onProgress.listen((e)
            {
                    Duration maxDuration = e.duration;
                    double decibels = e.decibels
                    ...
            }
    
            Lorem ipsum ...
    Dart
    Javascript
    
            switch(myRecorder.recorderState)
            {
                    case RecorderState.isRecording: doSomething; break;
                    case RecorderState.isStopped: doSomething; break;
                    case RecorderState.isPaused: doSomething; break;
            }
            ...
            if (myRecorder.isStopped) doSomething;
            if (myRecorder.isRecording) doSomething;
            if (myRecorder.isPaused) doSomething;
    
            Lorem ipsum ...
    @override
    void dispose()
    {
            if (myRecorder != null)
            {
                myRecorder.closeAudioSession();
                myPlayer = null;
            }
            super.dispose();
    }
        while (aCondition)  // *DO'NT DO THAT*
        {
                flutterSound = FlutterSoundRecorder().openAudioSession(); // A **new** Flutter Sound instance is created and opened
                ...
        }
    
        myRecorder = await FlutterSoundRecorder().openAudioSession();
    
        ...
        (do something with myRecorder)
        ...
    
        myRecorder.closeAudioSession();
        myRecorder = null;
    
            Lorem ipsum ...
    
        // Request Microphone permission if needed
        PermissionStatus status = await Permission.microphone.request();
        if (status != PermissionStatus.granted)
                throw RecordingPermissionException("Microphone permission not granted");
    
        Directory tempDir = await getTemporaryDirectory();
        File outputFile = await File ('${tempDir.path}/flutter_sound-tmp.aac');
        await myRecorder.startRecorder(toFile: outputFile.path, codec: t_CODEC.CODEC_AAC,);
    
            Lorem ipsum ...