use crate::error::PlatformError;
#[derive(Debug, Clone, PartialEq)]
pub enum VideoPlayerCommand {
Play,
Pause,
Stop,
NotifyEnded,
Seek {
position: f64,
},
SetDuration {
duration: f64,
},
EnterFullscreen,
ExitFullscreen,
}
pub trait VideoPlayerHandle: Send + Sync {
fn dispatch(&self, command: VideoPlayerCommand) -> Result<(), PlatformError>;
}
pub struct VideoPlayerHandleImpl<D>
where
D: Fn(VideoPlayerCommand) -> Result<(), PlatformError> + Send + Sync,
{
dispatch_fn: D,
}
impl<D> VideoPlayerHandleImpl<D>
where
D: Fn(VideoPlayerCommand) -> Result<(), PlatformError> + Send + Sync,
{
pub fn new(dispatch_fn: D) -> Self {
Self { dispatch_fn }
}
}
impl<D> VideoPlayerHandle for VideoPlayerHandleImpl<D>
where
D: Fn(VideoPlayerCommand) -> Result<(), PlatformError> + Send + Sync,
{
fn dispatch(&self, command: VideoPlayerCommand) -> Result<(), PlatformError> {
(self.dispatch_fn)(command)
}
}
pub trait VideoPlayerManager: Send + Sync + 'static {
fn bind_player(&self, component_id: &str) -> Result<Box<dyn VideoPlayerHandle>, PlatformError>;
fn set_player_callback(
&self,
_component_id: &str,
_callback_id: u64,
) -> Result<(), PlatformError> {
Ok(())
}
}