Skip to main content

Playerctl

Struct Playerctl 

Source
pub struct Playerctl;
Expand description

§Playerctl

Playerctl wrapper struct allowing to send commands and control the player.

§Examples

§Stop the current player

Playerctl::stop().unwrap();

§Advance and rewind 10 seconds

Playerctl::position(10.).unwrap();
Playerctl::position(-10.).unwrap();

§Get metadata

let metadata = Playerctl::metadata().unwrap();

println!("Track title: {}", metadata.title);

Implementations§

Source§

impl Playerctl

Source

pub fn play() -> Result<()>

Command the player to play.

Playerctl::play().unwrap();
Examples found in repository?
examples/basic.rs (line 5)
3fn main() {
4    // Command the player to play
5    Playerctl::play().unwrap_or_default();
6
7    // Command the player to pause
8    Playerctl::pause().unwrap_or_default();
9
10    // Command the player to toggle between play/pause
11    Playerctl::play_pause().unwrap_or_default();
12
13    // Command the player to seek forward/backward OFFSET in seconds
14    Playerctl::position(10.).unwrap_or_default();
15
16    // Get metadata information for the current track
17    let metadata = Playerctl::metadata().unwrap_or_default();
18
19    println!(
20        "Title: {}\nAlbum: {}\nArtist: {}\nURL: {}\nLength: {}",
21        metadata.title, metadata.album, metadata.artist, metadata.url, metadata.length
22    )
23}
Source

pub fn pause() -> Result<()>

Command the player to pause.

Playerctl::pause().unwrap();
Examples found in repository?
examples/basic.rs (line 8)
3fn main() {
4    // Command the player to play
5    Playerctl::play().unwrap_or_default();
6
7    // Command the player to pause
8    Playerctl::pause().unwrap_or_default();
9
10    // Command the player to toggle between play/pause
11    Playerctl::play_pause().unwrap_or_default();
12
13    // Command the player to seek forward/backward OFFSET in seconds
14    Playerctl::position(10.).unwrap_or_default();
15
16    // Get metadata information for the current track
17    let metadata = Playerctl::metadata().unwrap_or_default();
18
19    println!(
20        "Title: {}\nAlbum: {}\nArtist: {}\nURL: {}\nLength: {}",
21        metadata.title, metadata.album, metadata.artist, metadata.url, metadata.length
22    )
23}
Source

pub fn play_pause() -> Result<()>

Command the player to toggle between play/pause.

Playerctl::play_pause().unwrap();
Examples found in repository?
examples/basic.rs (line 11)
3fn main() {
4    // Command the player to play
5    Playerctl::play().unwrap_or_default();
6
7    // Command the player to pause
8    Playerctl::pause().unwrap_or_default();
9
10    // Command the player to toggle between play/pause
11    Playerctl::play_pause().unwrap_or_default();
12
13    // Command the player to seek forward/backward OFFSET in seconds
14    Playerctl::position(10.).unwrap_or_default();
15
16    // Get metadata information for the current track
17    let metadata = Playerctl::metadata().unwrap_or_default();
18
19    println!(
20        "Title: {}\nAlbum: {}\nArtist: {}\nURL: {}\nLength: {}",
21        metadata.title, metadata.album, metadata.artist, metadata.url, metadata.length
22    )
23}
Source

pub fn stop() -> Result<()>

Command the player to stop.

Playerctl::stop().unwrap();
Source

pub fn next() -> Result<()>

Command the player to skip to the next track.

Playerctl::next().unwrap();
Source

pub fn previous() -> Result<()>

Command the player to skip to the previous track.

Playerctl::previous().unwrap();
Source

pub fn position(secs: f32) -> Result<()>

Command the player to seek forward/backward OFFSET in seconds.

Playerctl::position(10.).unwrap();
Examples found in repository?
examples/basic.rs (line 14)
3fn main() {
4    // Command the player to play
5    Playerctl::play().unwrap_or_default();
6
7    // Command the player to pause
8    Playerctl::pause().unwrap_or_default();
9
10    // Command the player to toggle between play/pause
11    Playerctl::play_pause().unwrap_or_default();
12
13    // Command the player to seek forward/backward OFFSET in seconds
14    Playerctl::position(10.).unwrap_or_default();
15
16    // Get metadata information for the current track
17    let metadata = Playerctl::metadata().unwrap_or_default();
18
19    println!(
20        "Title: {}\nAlbum: {}\nArtist: {}\nURL: {}\nLength: {}",
21        metadata.title, metadata.album, metadata.artist, metadata.url, metadata.length
22    )
23}
Source

pub fn volume(percent: f32) -> Result<()>

Set the volume to LEVEL from 0.0 to 1.0.

Playerctl::volume(10.).unwrap();
Source

pub fn status() -> Result<TrackStatus>

Get the play status of the player.

Playerctl::status(10.).unwrap();
Source

pub fn metadata() -> Result<TrackMetadata>

Get metadata information for the current track.

let metadata = Playerctl::metadata().unwrap();

println!("Title: {}", metadata.title);
Examples found in repository?
examples/basic.rs (line 17)
3fn main() {
4    // Command the player to play
5    Playerctl::play().unwrap_or_default();
6
7    // Command the player to pause
8    Playerctl::pause().unwrap_or_default();
9
10    // Command the player to toggle between play/pause
11    Playerctl::play_pause().unwrap_or_default();
12
13    // Command the player to seek forward/backward OFFSET in seconds
14    Playerctl::position(10.).unwrap_or_default();
15
16    // Get metadata information for the current track
17    let metadata = Playerctl::metadata().unwrap_or_default();
18
19    println!(
20        "Title: {}\nAlbum: {}\nArtist: {}\nURL: {}\nLength: {}",
21        metadata.title, metadata.album, metadata.artist, metadata.url, metadata.length
22    )
23}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.