modules.core.player

Audio Player using GStreamer Command-Line Tools

A simple audio player that uses GStreamer command-line tools (gst-launch-1.0) for playback control.

Functions

main()

Main function to handle command line arguments and play audio.

play_audio(filepath)

Simple playback function for command-line compatibility.

Classes

AudioPlayer()

A GStreamer command-line based audio player with playback control.

class modules.core.player.AudioPlayer[source]

Bases: object

A GStreamer command-line based audio player with playback control.

This class provides audio playback functionality using GStreamer’s command-line tools (gst-launch-1.0) including play, pause, stop, volume control, and looping capabilities. No PyGObject bindings required.

Initialize the AudioPlayer with command-line GStreamer support.

Raises:

RuntimeError – If gst-launch-1.0 is not available.

__init__()[source]

Initialize the AudioPlayer with command-line GStreamer support.

Raises:

RuntimeError – If gst-launch-1.0 is not available.

signal_handler(signum, frame)[source]

Handle termination signals gracefully.

Parameters:
  • signum (int) – Signal number received.

  • frame – Current stack frame (unused).

load_file(filepath)[source]

Load an audio file for playback.

Parameters:

filepath (str) – Path to the audio file.

Returns:

True if file loaded successfully, False otherwise.

Return type:

bool

play()[source]

Start or resume playback.

Returns:

True if playback started successfully, False otherwise.

Return type:

bool

pause()[source]

Pause playback.

Returns:

True if paused successfully, False otherwise.

Return type:

bool

resume()[source]

Resume paused playback.

Returns:

True if resumed successfully, False otherwise.

Return type:

bool

stop()[source]

Stop playback.

Returns:

True if stopped successfully, False otherwise.

Return type:

bool

set_volume(volume)[source]

Set playback volume.

Parameters:

volume (float) – Volume level between 0.0 and 1.0.

Returns:

True if volume set successfully, False otherwise.

Return type:

bool

get_volume()[source]

Get current volume level.

Returns:

Current volume between 0.0 and 1.0.

Return type:

float

seek(position_seconds)[source]

Seek to a specific position in the audio.

Parameters:

position_seconds (float) – Position to seek to in seconds.

Returns:

True if seek successful, False otherwise.

Return type:

bool

get_position()[source]

Get current playback position.

Returns:

Current position in seconds.

Return type:

float

get_duration()[source]

Get total duration of the current audio file.

Returns:

Total duration in seconds.

Return type:

float

set_loop_mode(mode)[source]

Set loop mode for playback.

Parameters:

mode (str) – Loop mode - ‘none’, number (e.g. ‘3’), or ‘infinite’.

Returns:

True if loop mode set successfully, False otherwise.

Return type:

bool

get_loop_mode()[source]

Get current loop mode.

Returns:

Current loop mode setting.

Return type:

str

get_repeat_count()[source]

Get number of times the current song has repeated.

Returns:

Number of repeats completed.

Return type:

int

get_state()[source]

Get current player state information.

Returns:

Dictionary containing player state including:
  • is_playing (bool): Whether audio is currently playing

  • is_paused (bool): Whether audio is paused

  • current_file (str): Path to current file

  • position (float): Current position in seconds

  • duration (float): Total duration in seconds

  • volume (float): Current volume level

  • loop_mode (str): Current loop mode

  • repeat_count (int): Number of repeats completed

Return type:

dict

run_interactive()[source]

Run the player in interactive mode with command input.

Starts a command-line interface allowing real-time control of playback through user commands.

handle_input()[source]

Handle user input in interactive mode.

Processes user commands while audio playback continues.

modules.core.player.play_audio(filepath)[source]

Simple playback function for command-line compatibility.

Parameters:

filepath (str) – Path to the audio file to play.

Returns:

True if playback completed successfully, False otherwise.

Return type:

bool

modules.core.player.main()[source]

Main function to handle command line arguments and play audio.

Parses command-line arguments and initiates appropriate playback mode (simple, interactive, or daemon).

Examples

Simple playback:

python player.py /path/to/song.mp3

Interactive mode with controls:

python player.py –interactive /path/to/song.mp3

Daemon mode for external control:

python player.py –daemon /path/to/song.mp3

Using test file:

python player.py ../../testing_files/test.mp3