diff --git a/lib/membrane/core/playback.ex b/lib/membrane/core/playback.ex index c4f7b5a74..73f36d779 100644 --- a/lib/membrane/core/playback.ex +++ b/lib/membrane/core/playback.ex @@ -3,7 +3,7 @@ defmodule Membrane.Core.Playback do This module defines available playback states and struct that is held internally by every module having playback state. - There are three playback states: :stopped, :prepared and :playing. + There are three playback states: `:stopped`, `:prepared` and `:playing`. """ use Bunch.Access @@ -22,4 +22,6 @@ defmodule Membrane.Core.Playback do } @type state_t :: :stopped | :prepared | :playing + + defguard is_playback_state(atom) when atom in [:stopped, :prepared, :playing] end diff --git a/lib/membrane/core/playback_requestor.ex b/lib/membrane/core/playback_requestor.ex index 80e1aafcf..65f6ee7ae 100644 --- a/lib/membrane/core/playback_requestor.ex +++ b/lib/membrane/core/playback_requestor.ex @@ -10,30 +10,39 @@ defmodule Membrane.Core.PlaybackRequestor do defmacro __using__(_args) do quote location: :keep do @behaviour unquote(__MODULE__) + require Membrane.Core.Playback @doc """ - Alias for `change_playback_state(pid, :playing)`. - See `c:#{__MODULE__}.change_playback_state/2`. + Changes playback state to `:playing`. + + An alias for `change_playback_state/2` with proper state. """ @spec play(pid) :: :ok def play(pid), do: change_playback_state(pid, :playing) @doc """ - Alias for `change_playback_state(pid, :prepared)`. - See `c:#{__MODULE__}.change_playback_state/2`. + Changes playback state to `:prepared`. + + An alias for `change_playback_state/2` with proper state. """ @spec prepare(pid) :: :ok def prepare(pid), do: change_playback_state(pid, :prepared) @doc """ - Alias for `change_playback_state(pid, :stopped)`. - See `c:#{__MODULE__}.change_playback_state/2`. + Changes playback state to `:stopped`. + + An alias for `change_playback_state/2` with proper state. """ @spec stop(pid) :: :ok def stop(pid), do: change_playback_state(pid, :stopped) @impl unquote(__MODULE__) - def change_playback_state(pid, new_state) do + @doc """ + Changes the playback state to the `new_state`. + """ + @spec change_playback_state(pid, Playback.state_t()) :: :ok + def change_playback_state(pid, new_state) + when Membrane.Core.Playback.is_playback_state(new_state) do alias Membrane.Core.Message require Message Message.send(pid, :change_playback_state, new_state)