Skip to main content

## PlayerBackend

# Trait PlayerBackend

Source

    pub trait PlayerBackend: Send + Sync {
    Show 14 methods    // Required methods
        fn load(&mut self, media: &MediaItem) -> Result<(), PlayerError>;
        fn play(&mut self) -> Result<(), PlayerError>;
        fn pause(&mut self) -> Result<(), PlayerError>;
        fn stop(&mut self) -> Result<(), PlayerError>;
        fn seek(&mut self, position: f64) -> Result<(), PlayerError>;
        fn set_volume(&mut self, volume: f32) -> Result<(), PlayerError>;
        fn position(&self) -> f64;
        fn duration(&self) -> Option<f64>;
        fn state(&self) -> PlayerState;
        fn volume(&self) -> f32;

        // Provided methods
        fn set_audio_settings(
            &mut self,
            _settings: &AudioSettings,
        ) -> Result<(), PlayerError> { ... }
        fn audio_settings(&self) -> AudioSettings { ... }
        fn set_audio_track(&mut self, _stream_index: i32) -> Result<(), PlayerError> { ... }
        fn set_subtitle_track(
            &mut self,
            _stream_index: Option<i32>,
        ) -> Result<(), PlayerError> { ... }
    }

Expand description

Player backend trait - implemented by platform-specific players

TRACES: UR-003, UR-004 | IR-003, IR-004 | DR-004

## Required Methods§

Source

#### fn load(&mut self, media: &MediaItem) -> Result<(), PlayerError>

Load a media item for playback TRACES: UR-005

Source

#### fn play(&mut self) -> Result<(), PlayerError>

Start or resume playback TRACES: UR-005

Source

#### fn pause(&mut self) -> Result<(), PlayerError>

Pause playback TRACES: UR-005

Source

#### fn stop(&mut self) -> Result<(), PlayerError>

Stop playback and unload media TRACES: UR-005

Source

#### fn seek(&mut self, position: f64) -> Result<(), PlayerError>

Seek to a position in seconds TRACES: UR-005

Source

#### fn set_volume(&mut self, volume: f32) -> Result<(), PlayerError>

Set volume (0.0 - 1.0) TRACES: UR-016

Source

#### fn position(&self) -> f64

Get current playback position in seconds

Source

#### fn duration(&self) -> Option<f64>

Get total duration in seconds

Source

#### fn state(&self) -> PlayerState

Get current player state

Source

#### fn volume(&self) -> f32

Get current volume

## Provided Methods§

Source

#### fn set_audio_settings( &mut self, _settings: &AudioSettings, ) -> Result<(), PlayerError>

Apply audio settings (crossfade, gapless, normalization)

@req-partial: UR-031 (Linux only) - Crossfade between audio tracks @req-partial: UR-032 (Linux only) - Gapless playback for seamless album listening @req-partial: UR-033 (Linux only) - Volume normalization to prevent volume jumps @req: DR-034 - Crossfade engine with configurable duration (0-12s) @req: DR-035 - Gapless playback between sequential tracks @req: DR-036 - Volume normalization with preset levels (Loud/Normal/Quiet)

Source

#### fn audio_settings(&self) -> AudioSettings

Get current audio settings

@req: DR-034 - Crossfade engine @req: DR-035 - Gapless playback @req: DR-036 - Volume normalization

Source

#### fn set_audio_track(&mut self, _stream_index: i32) -> Result<(), PlayerError>

Set the active audio track by stream index

Overridden by the Android (ExoPlayer) backend. `MpvBackend` deliberately does not override it — MPV is the audio-only backend here, so it keeps this `not_implemented()` default and the Linux video path switches track by re-opening the stream instead (`player_switch_audio_track`).

TRACES: UR-021 | IR-019, DR-024

Source

#### fn set_subtitle_track( &mut self, _stream_index: Option<i32>, ) -> Result<(), PlayerError>

Set the active subtitle track by stream index (None to disable subtitles)

Overridden by the Android (ExoPlayer) backend. `MpvBackend` deliberately does not override it, so it keeps this `not_implemented()` default; the Linux video path renders subtitles as `<track>` children of the WebKitGTK HTML5 `<video>` element and never calls this.

TRACES: UR-020 | IR-018, DR-023

## Trait Implementations§

Source §

### impl PlayerBackend for Box<dyn PlayerBackend>

Forward the trait through a box.

`Box<dyn PlayerBackend>` does not implement `PlayerBackend` on its own, so without this the boxed engine built at the composition root cannot be handed to anything generic over the trait — `LegacyPlayer` in particular.

Source §

#### fn load(&mut self, media: &MediaItem) -> Result<(), PlayerError>

Load a media item for playback TRACES: UR-005
Source §

#### fn play(&mut self) -> Result<(), PlayerError>

Start or resume playback TRACES: UR-005
Source §

#### fn pause(&mut self) -> Result<(), PlayerError>

Pause playback TRACES: UR-005
Source §

#### fn stop(&mut self) -> Result<(), PlayerError>

Stop playback and unload media TRACES: UR-005
Source §

#### fn seek(&mut self, position: f64) -> Result<(), PlayerError>

Seek to a position in seconds TRACES: UR-005
Source §

#### fn set_volume(&mut self, volume: f32) -> Result<(), PlayerError>

Set volume (0.0 - 1.0) TRACES: UR-016
Source §

#### fn position(&self) -> f64

Get current playback position in seconds
Source §

#### fn duration(&self) -> Option<f64>

Get total duration in seconds
Source §

#### fn state(&self) -> PlayerState

Get current player state
Source §

#### fn volume(&self) -> f32

Get current volume
Source §

#### fn set_audio_settings( &mut self, settings: &AudioSettings, ) -> Result<(), PlayerError>

Apply audio settings (crossfade, gapless, normalization) Read more
Source §

#### fn audio_settings(&self) -> AudioSettings

Get current audio settings Read more
Source §

#### fn set_audio_track(&mut self, stream_index: i32) -> Result<(), PlayerError>

Set the active audio track by stream index Read more
Source §

#### fn set_subtitle_track( &mut self, stream_index: Option<i32>, ) -> Result<(), PlayerError>

Set the active subtitle track by stream index (None to disable subtitles) Read more

## Implementations on Foreign Types§

Source §

### impl PlayerBackend for Box<dyn PlayerBackend>

Forward the trait through a box.

`Box<dyn PlayerBackend>` does not implement `PlayerBackend` on its own, so without this the boxed engine built at the composition root cannot be handed to anything generic over the trait — `LegacyPlayer` in particular.

Source §

#### fn load(&mut self, media: &MediaItem) -> Result<(), PlayerError>

Source §

#### fn play(&mut self) -> Result<(), PlayerError>

Source §

#### fn pause(&mut self) -> Result<(), PlayerError>

Source §

#### fn stop(&mut self) -> Result<(), PlayerError>

Source §

#### fn seek(&mut self, position: f64) -> Result<(), PlayerError>

Source §

#### fn set_volume(&mut self, volume: f32) -> Result<(), PlayerError>

Source §

#### fn position(&self) -> f64

Source §

#### fn duration(&self) -> Option<f64>

Source §

#### fn state(&self) -> PlayerState

Source §

#### fn volume(&self) -> f32

Source §

#### fn set_audio_settings( &mut self, settings: &AudioSettings, ) -> Result<(), PlayerError>

Source §

#### fn audio_settings(&self) -> AudioSettings

Source §

#### fn set_audio_track(&mut self, stream_index: i32) -> Result<(), PlayerError>

Source §

#### fn set_subtitle_track( &mut self, stream_index: Option<i32>, ) -> Result<(), PlayerError>

## Implementors§

Source §

### impl PlayerBackend for MpvBackend

Source §

### impl PlayerBackend for NullBackend