diff --git a/src/Applications/UI.elm b/src/Applications/UI.elm index a17f5876..cb9b8602 100644 --- a/src/Applications/UI.elm +++ b/src/Applications/UI.elm @@ -257,6 +257,12 @@ update msg = NoteProgress a -> Audio.noteProgress a + Pause -> + Audio.pause + + Play -> + Audio.play + Seek a -> Audio.seek a @@ -520,6 +526,8 @@ subscriptions model = -- Audio ----------------------------------------- , Ports.noteProgress NoteProgress + , Ports.requestPause (always Pause) + , Ports.requestPlay (always Play) , Ports.requestPlayPause (always TogglePlay) , Ports.requestStop (always Stop) , Ports.setAudioDuration SetAudioDuration diff --git a/src/Applications/UI/Audio/State.elm b/src/Applications/UI/Audio/State.elm index aee9011e..c9e59fc0 100644 --- a/src/Applications/UI/Audio/State.elm +++ b/src/Applications/UI/Audio/State.elm @@ -35,6 +35,11 @@ noteProgress { trackId, progress } model = Return.singleton model +pause : Manager +pause model = + return model (Ports.pause ()) + + playPause : Manager playPause model = if Maybe.isNothing model.nowPlaying then @@ -47,6 +52,15 @@ playPause model = communicate (Ports.play ()) model +play : Manager +play model = + if Maybe.isNothing model.nowPlaying then + Queue.shift model + + else + return model (Ports.play ()) + + seek : Float -> Manager seek percentage = Return.communicate (Ports.seek percentage) diff --git a/src/Applications/UI/Ports.elm b/src/Applications/UI/Ports.elm index bb30d990..173a3fa6 100644 --- a/src/Applications/UI/Ports.elm +++ b/src/Applications/UI/Ports.elm @@ -70,6 +70,12 @@ port preferredColorSchemaChanged : ({ dark : Bool } -> msg) -> Sub msg port requestNext : (() -> msg) -> Sub msg +port requestPause : (() -> msg) -> Sub msg + + +port requestPlay : (() -> msg) -> Sub msg + + port requestPlayPause : (() -> msg) -> Sub msg diff --git a/src/Applications/UI/Types.elm b/src/Applications/UI/Types.elm index ccaacdcc..216e3845 100644 --- a/src/Applications/UI/Types.elm +++ b/src/Applications/UI/Types.elm @@ -195,6 +195,8 @@ type Msg -- Audio ----------------------------------------- | NoteProgress { trackId : String, progress : Float } + | Pause + | Play | Seek Float | SetAudioDuration Float | SetAudioHasStalled Bool diff --git a/src/Javascript/index.js b/src/Javascript/index.js index 44d1030c..d3dcd613 100644 --- a/src/Javascript/index.js +++ b/src/Javascript/index.js @@ -539,12 +539,12 @@ document.addEventListener("MediaNext", () => { if ("mediaSession" in navigator) { navigator.mediaSession.setActionHandler("play", () => { - app.ports.requestPlayPause.send(null) + app.ports.requestPlay.send(null) }) navigator.mediaSession.setActionHandler("pause", () => { - app.ports.requestPlayPause.send(null) + app.ports.requestPause.send(null) })