Add option to stop player.

This commit is contained in:
Pim Kunis 2020-10-10 20:57:11 +02:00
parent dcc2391094
commit 60361b02ae

View file

@ -19,6 +19,10 @@ defmodule MIDITools.Player do
GenServer.call(__MODULE__, {:set_repeat, repeat})
end
def stop_playing do
GenServer.call(__MODULE__, :stop_playing)
end
# Server callbacks
@impl true
@ -57,6 +61,11 @@ defmodule MIDITools.Player do
{:reply, :ok, %{state | repeat: repeat}}
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
def handle_info(
:play,