mirror of
https://github.com/talwat/lowfi
synced 2025-01-26 18:31:26 +00:00
feat(mpris): wip implementation of propertieschanged signal
This commit is contained in:
parent
9414b97d62
commit
978dfbc5e2
@ -80,12 +80,18 @@ zypper install lowfi
|
|||||||
|
|
||||||
### Manual
|
### Manual
|
||||||
|
|
||||||
|
This is good for debugging, especially in issues.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/talwat/lowfi
|
git clone https://github.com/talwat/lowfi
|
||||||
cd lowfi
|
cd lowfi
|
||||||
|
|
||||||
cargo build --release
|
# If you want an actual binary
|
||||||
|
cargo build --release --all-features
|
||||||
./target/release/lowfi
|
./target/release/lowfi
|
||||||
|
|
||||||
|
# If you just want to test
|
||||||
|
cargo run --all-features
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -7,6 +7,7 @@ use std::{collections::VecDeque, ffi::CString, sync::Arc, time::Duration};
|
|||||||
use arc_swap::ArcSwapOption;
|
use arc_swap::ArcSwapOption;
|
||||||
use downloader::Downloader;
|
use downloader::Downloader;
|
||||||
use libc::freopen;
|
use libc::freopen;
|
||||||
|
use mpris_server::PlayerInterface;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use rodio::{OutputStream, OutputStreamHandle, Sink};
|
use rodio::{OutputStream, OutputStreamHandle, Sink};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
@ -244,12 +245,32 @@ impl Player {
|
|||||||
Ok(decoded)
|
Ok(decoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shorthand to emit a `PropertiesChanged` signal, like when pausing/unpausing.
|
||||||
|
#[cfg(feature = "mpris")]
|
||||||
|
async fn mpris_changed(&self, property: mpris_server::Property) -> eyre::Result<()> {
|
||||||
|
self.mpris
|
||||||
|
.get()
|
||||||
|
.unwrap()
|
||||||
|
.properties_changed(vec![property])
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shorthand to get the inner mpris server object.
|
||||||
|
#[cfg(feature = "mpris")]
|
||||||
|
fn mpris_innner(&self) -> &mpris::Player {
|
||||||
|
self.mpris.get().unwrap().imp()
|
||||||
|
}
|
||||||
|
|
||||||
/// This basically just calls [`Player::next`], and then appends the new track to the player.
|
/// This basically just calls [`Player::next`], and then appends the new track to the player.
|
||||||
///
|
///
|
||||||
/// This also notifies the background thread to get to work, and will send `TryAgain`
|
/// This also notifies the background thread to get to work, and will send `TryAgain`
|
||||||
/// if it fails. This functions purpose is to be called in the background, so that
|
/// if it fails. This functions purpose is to be called in the background, so that
|
||||||
/// when the audio server recieves a `Next` signal it will still be able to respond to other
|
/// when the audio server recieves a `Next` signal it will still be able to respond to other
|
||||||
/// signals while it's loading.
|
/// signals while it's loading.
|
||||||
|
///
|
||||||
|
/// This also sends the `NewSong` signal to `tx` apon successful completion.
|
||||||
async fn handle_next(
|
async fn handle_next(
|
||||||
player: Arc<Self>,
|
player: Arc<Self>,
|
||||||
itx: Sender<()>,
|
itx: Sender<()>,
|
||||||
@ -308,6 +329,7 @@ impl Player {
|
|||||||
// if there hasn't been any manual intervention.
|
// if there hasn't been any manual intervention.
|
||||||
let mut new = false;
|
let mut new = false;
|
||||||
|
|
||||||
|
// TODO: Clean mpris_changed calls & streamline them somehow.
|
||||||
loop {
|
loop {
|
||||||
let clone = Arc::clone(&player);
|
let clone = Arc::clone(&player);
|
||||||
|
|
||||||
@ -347,9 +369,23 @@ impl Player {
|
|||||||
}
|
}
|
||||||
Messages::Play => {
|
Messages::Play => {
|
||||||
player.sink.play();
|
player.sink.play();
|
||||||
|
|
||||||
|
#[cfg(feature = "mpris")]
|
||||||
|
player
|
||||||
|
.mpris_changed(mpris_server::Property::PlaybackStatus(
|
||||||
|
mpris_server::PlaybackStatus::Playing,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
Messages::Pause => {
|
Messages::Pause => {
|
||||||
player.sink.pause();
|
player.sink.pause();
|
||||||
|
|
||||||
|
#[cfg(feature = "mpris")]
|
||||||
|
player
|
||||||
|
.mpris_changed(mpris_server::Property::PlaybackStatus(
|
||||||
|
mpris_server::PlaybackStatus::Paused,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
Messages::PlayPause => {
|
Messages::PlayPause => {
|
||||||
if player.sink.is_paused() {
|
if player.sink.is_paused() {
|
||||||
@ -357,9 +393,21 @@ impl Player {
|
|||||||
} else {
|
} else {
|
||||||
player.sink.pause();
|
player.sink.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "mpris")]
|
||||||
|
player
|
||||||
|
.mpris_changed(mpris_server::Property::PlaybackStatus(
|
||||||
|
player.mpris_innner().playback_status().await?,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
Messages::ChangeVolume(change) => {
|
Messages::ChangeVolume(change) => {
|
||||||
player.set_volume(player.sink.volume() + change);
|
player.set_volume(player.sink.volume() + change);
|
||||||
|
|
||||||
|
#[cfg(feature = "mpris")]
|
||||||
|
player
|
||||||
|
.mpris_changed(mpris_server::Property::Volume(player.sink.volume().into()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
// This basically just continues, but more importantly, it'll re-evaluate
|
// This basically just continues, but more importantly, it'll re-evaluate
|
||||||
// the select macro at the beginning of the loop.
|
// the select macro at the beginning of the loop.
|
||||||
@ -369,6 +417,13 @@ impl Player {
|
|||||||
// begin waiting for the song to be over in order to autoplay.
|
// begin waiting for the song to be over in order to autoplay.
|
||||||
new = true;
|
new = true;
|
||||||
|
|
||||||
|
#[cfg(feature = "mpris")]
|
||||||
|
player
|
||||||
|
.mpris_changed(mpris_server::Property::Metadata(
|
||||||
|
player.mpris_innner().metadata().await?,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Messages::Quit => break,
|
Messages::Quit => break,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user