gitlabEdit

playPlayback

Play your music!

The playback tools in the Basolia library contains two separate sections: the actual playback tools and the playback positioning tools.


Playback tools

The playback tools shipped with the Basolia library is a key feature for every single music player.

chevron-rightPlaying musichashtag

There are two ways to play the music: synchronously and asynchronously. For normal console applications, you'd typically use Play() for a single audio player, or this function in a thread for a music player, such as BassBoom.Cli.

public static void Play(BasoliaMedia? basolia) { }

However, for GUI applications, it's best to use the asynchronous version whenever possible, PlayAsync(), to avoid blocking the main thread.

public static async Task PlayAsync(BasoliaMedia? basolia) { }
chevron-rightPausing and stopping musichashtag

If you want to pause the music, you can use the Pause() function. It'll stop the music, but stays at the current position. If you want to start over, you can use the Stop() function.

public static void Pause(BasoliaMedia? basolia) { }
public static void Stop(BasoliaMedia? basolia) { }
chevron-rightVolume Controlshashtag

For controlling the volume that the Basolia library controls, you can use both the SetVolume() and the GetVolume() functions.

SetVolume() allows you to set the current volume to the new volume from 0.0 (0%) to 1.0 (100%). Additionally, if you've enabled the volume boost option, you can set the volume up to 3.0 (300%), though this may cause audio artifacts in some cases where parts of an audio file is loud.

public static void SetVolume(BasoliaMedia? basolia, double volume, bool volBoost = false) { }

Getting the current volume using the GetVolume() function returns three variables that describe the following:

Variable
Description

baseLinear

The base linear volume from 0.0 to 1.0

actualLinear

The actual linear volume from 0.0 to 1.0

decibelsRva

The RVA value in decibels (dB)

public static (double baseLinear, double actualLinear, double decibelsRva) GetVolume(BasoliaMedia? basolia) { }
chevron-rightPlayback stateshashtag

When either Play(), Pause(), or Stop() functions are called, the playback state changes, depending on the action. You can get the current playback state by using the GetState function.

public static PlaybackState GetState(BasoliaMedia? basolia) { }

You can also quickly determine whether Basolia is busy playing a song using the IsPlaying function:

public static bool IsPlaying(BasoliaMedia? basolia) { }

The playback states are the following:

State
Description

Stopped

Music has either stopped or not played yet

Playing

Music is playing

Paused

Music has been paused by the user or by the call to the Pause() function

chevron-rightOpening the outputhashtag

If you want to open the output to your selected device and driver or to a pre-determined device and driver as selected by your OS, you can use the below function:

circle-info

You don't usually need to call this function, unless you have a reason to. Playback tools already use this function internally.

chevron-rightStarting the outputhashtag

If you want to start the output at a selected rate, channel count, and encoding, you can use the below function:

circle-info

You don't usually need to call this function, unless you have a reason to. Playback tools already use this function internally.

chevron-rightClosing the outputhashtag

If you no longer want to output anything, you can use this function:

triangle-exclamation

Play'n'Forget

If you don't want to set up a persistent BasoliaMedia instance for every operation, you can use this technique to implement Play'n'Forget in your applications so that you can play either a file or a stream without any difficulty. The below functions can be found in the Independent namespace.

circle-info

If you want to change a specific setting, you should create a class instance of PlayForgetSettings that consists of:

  • Volume (settable and constructible)

  • VolumeBoost (settable and constructible)

  • RootLibPath (constructible, but not modifiable)

Be careful about the RootLibPath settings entry, as it gets ignored right after Basolia verifies that the library is loaded for the first time.

chevron-rightPlaying a filehashtag

There are two ways to play a file: synchronously and asynchronously.

Just call one of these functions, passing it either an absolute path or a relative path to your music file, optionally passing it the Play'n'Forget settings instance.

chevron-rightPlaying a streamhashtag

There are two ways to play a stream: synchronously and asynchronously.

Just call one of these functions, passing it a seekable stream containing MP3 data of your song file, optionally passing it the Play'n'Forget settings instance.

triangle-exclamation

Positioning tools

In addition to the playback tools, you can also get access to the positioning tools to perform seek operations to jump to a specific section of a song, regardless of whether the song is playing or not.

chevron-rightCurrent durationhashtag

You can get the current duration in two units: Samples and time span. If you want to get the current duration using the samples, you can use the GetCurrentDuration() function:

Similarly, you can also get the current duration in the timespan for easier representation by using the GetCurrentDurationSpan() function:

chevron-rightSeeking controlshashtag

If you want to seek the music file either to a selected position using a frame number or to the beginning of the song (frame 0), you can simply use one of the two functions:

chevron-rightDropping MPEG frameshashtag

If you want to flush all MPEG frames to the device for any reason, you can use this function:


Equalizer tools

BassBoom's Basolia library also allows you to modify the equalizer settings during playback so that you can listen to enhanced music. It currently supports 32 bands as MPG123 supports.

circle-info

You can run this tool on either left, right, or both speakers.

chevron-rightGetting current equalizer valueshashtag

If you want to get the current equalizer values, you can use the below function:

chevron-rightSetting equalizer valueshashtag

If you want to set the equalizer values for one or more bands to make your music sound better, you can use the below function:

chevron-rightResetting equalizer valueshashtag

If you want to reset the equalizer values to their natural states (1.00), you can use the below function:

chevron-rightGetting native statehashtag

If you want to get the native state of the output stream that represents the currently playing music, you can use this function:

The mpg123_state enumeration has the following states for you to get:

State
Description

MPG123_ACCURATE

Accurate rendering

MPG123_BUFFERFILL

Buffer fill

MPG123_DEC_DELAY

Decode delay in milliseconds

MPG123_ENC_DELAY

Encode delay in milliseconds

MPG123_ENC_PADDING

Encoding padding

MPG123_FRANKENSTEIN

Frankenstein stream?

MPG123_FRESH_DECODER

Fresh decoder

Last updated