-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Created the application code - Updated README.md
- Loading branch information
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |