Add option to stop player.
This commit is contained in:
parent
dcc2391094
commit
60361b02ae
1 changed files with 9 additions and 0 deletions
|
@ -19,6 +19,10 @@ defmodule MIDITools.Player do
|
||||||
GenServer.call(__MODULE__, {:set_repeat, repeat})
|
GenServer.call(__MODULE__, {:set_repeat, repeat})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stop_playing do
|
||||||
|
GenServer.call(__MODULE__, :stop_playing)
|
||||||
|
end
|
||||||
|
|
||||||
# Server callbacks
|
# Server callbacks
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
@ -57,6 +61,11 @@ defmodule MIDITools.Player do
|
||||||
{:reply, :ok, %{state | repeat: repeat}}
|
{:reply, :ok, %{state | repeat: repeat}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_call(:stop_playing, _from, %{timer: timer} = state) do
|
||||||
|
Process.cancel_timer(timer, info: false)
|
||||||
|
{:reply, :ok, %{state | timer: nil}}
|
||||||
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info(
|
def handle_info(
|
||||||
:play,
|
:play,
|
||||||
|
|
Loading…
Reference in a new issue