pub struct NowPlaying { /* private fields */ }Expand description
A struct for managing and interacting with the “Now Playing” media session.
The NowPlaying struct allows access to the currently playing media information,
and provides functionality to control playback (e.g., play, pause, skip).
§Example
use media_remote::{Controller, NowPlaying};
let now_playing = NowPlaying::new();
now_playing.play();Implementations§
Source§impl NowPlaying
impl NowPlaying
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of NowPlaying and registers for playback notifications.
This function initializes a new NowPlaying object, sets up necessary observers,
and ensures that media metadata is updated upon creation.
§Returns
NowPlaying: A new instance of theNowPlayingstruct.
§Example
use media_remote::NowPlaying;
let now_playing = NowPlaying::new();Sourcepub fn get_info(&self) -> RwLockReadGuard<'_, Option<NowPlayingInfo>>
pub fn get_info(&self) -> RwLockReadGuard<'_, Option<NowPlayingInfo>>
Retrieves the latest now playing information.
This function provides a read-locked view of the current playing media metadata.
§Note
- The lock should be released as soon as possible to minimize blocking time.
§Returns
RwLockReadGuard<'_, Option<NowPlayingInfo>>: A guard to the now playing metadata.
§Example
use media_remote::NowPlaying;
let now_playing = NowPlaying::new();
let guard = now_playing.get_info();
let info = guard.as_ref();
if let Some(info) = info {
println!("Currently playing: {:?}", info.title);
}
drop(guard);Trait Implementations§
Source§impl Controller for NowPlaying
impl Controller for NowPlaying
fn is_info_some(&self) -> bool
Source§impl Drop for NowPlaying
impl Drop for NowPlaying
Source§impl Subscription for NowPlaying
impl Subscription for NowPlaying
fn get_info(&self) -> RwLockReadGuard<'_, Option<NowPlayingInfo>>
fn get_token_counter(&self) -> Arc<AtomicU64>
fn get_listeners( &self, ) -> Arc<Mutex<HashMap<ListenerToken, Box<dyn Fn(RwLockReadGuard<'_, Option<NowPlayingInfo>>) + Send + Sync>>>>
Source§fn subscribe<F: Fn(RwLockReadGuard<'_, Option<NowPlayingInfo>>) + Send + Sync + 'static>(
&self,
listener: F,
) -> ListenerToken
fn subscribe<F: Fn(RwLockReadGuard<'_, Option<NowPlayingInfo>>) + Send + Sync + 'static>( &self, listener: F, ) -> ListenerToken
Subscribes a listener to receive updates when the “Now Playing” information changes. Read more
Source§fn unsubscribe(&self, token: ListenerToken)
fn unsubscribe(&self, token: ListenerToken)
Unsubscribes a previously registered listener using the provided
ListenerToken. Read moreAuto Trait Implementations§
impl Freeze for NowPlaying
impl !RefUnwindSafe for NowPlaying
impl !Send for NowPlaying
impl !Sync for NowPlaying
impl Unpin for NowPlaying
impl UnsafeUnpin for NowPlaying
impl !UnwindSafe for NowPlaying
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more