Skip to content

Commit

Permalink
Initial commit of this application
Browse files Browse the repository at this point in the history
- Created the application code
- Updated README.md
  • Loading branch information
BlackDex committed Feb 10, 2019
1 parent 24b3149 commit 830e0a6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "mpris-control"
version = "0.1.0"
authors = ["BlackDex"]
edition = "2018"

repository = "https://github.com/BlackDex/mpris-control"
readme = "README.md"
license = "GPL-3.0-only"
publish = false
#build = "build.rs"

[dependencies]
mpris = "*"

[patch.crates-io]
mpris = { git = 'https://github.com/Mange/mpris-rs', rev = '4e1f06de3edc865970e5107bd34b2fb40699d03b' }

[profile.release]
lto = true
opt-level = "s"
codegen-units = 1
inline-threshold = 275

25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# mpris-control
Small application to control mpris-2 mediaplayers like spotify, vlc, rhythmbox etc..
A small application to control mpris-2 mediaplayers like spotify, vlc, rhythmbox etc..<br>
<br>
I Created this because the spotify-app (snap) didn't seem to work with the default media key's configuration of Ubuntu 18.04.<br>
<br>
This application works with all mpris-2 dbus controlled applications as far as i know.<br>
If you encounter any issues please report them in the issues section.<br>
<br>
**Simple usage:**
```bash
# Toggle play/pause
mpris-control toggle

# Play
mpris-control play

# Pause
mpris-control pause

# Next track
mpris-control next

# Previous track
mpris-control previous
```
50 changes: 50 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//src main.rs
use std::env;

extern crate mpris;

use mpris::PlayerFinder;

fn main() {
let args: Vec<String> = env::args().collect();

if args.len() == 2 {
let action = &args[1];
action.trim().to_ascii_lowercase();

if ! action.is_empty() {
match run_action(action) {
Ok(msg) => {
println!("{:?}", msg);
},
Err(err) => {
println!("{:?}", err);
}
}
}
} else {
println!("No action has been given!\nPlease use, toggle, play, pause, next or previous");
}
}

fn run_action(action: &str) -> Result<String, String> {
let player_finder = PlayerFinder::new()
.map_err(|e| format!("Could not connect to D-Bus: {}", e))?;

let player = player_finder.find_active()
.map_err(|e| format!("Could not find any player: {}", e))?;

if action == "toggle" {
player.checked_play_pause().map_err(|e| format!("Could not control player: {}", e))?;
} else if action == "play" {
player.checked_play().map_err(|e| format!("Could not control player: {}", e))?;
} else if action == "pause" {
player.checked_pause().map_err(|e| format!("Could not control player: {}", e))?;
} else if action == "next" {
player.checked_next().map_err(|e| format!("Could not control player: {}", e))?;
} else if action == "previous" {
player.checked_previous().map_err(|e| format!("Could not control player: {}", e))?;
}

Ok(format!("Action {} run", action))
}

0 comments on commit 830e0a6

Please sign in to comment.