-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from sgobotta/feature/add-voume-controls
feature/add voume controls
- Loading branch information
Showing
35 changed files
with
1,725 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule LivedjWeb.PlayerPreview do | ||
@moduledoc false | ||
|
||
use LivedjWeb, :live_component | ||
|
||
alias Livedj.Sessions.Player | ||
|
||
def render(assigns) do | ||
~H""" | ||
<div class="h-40 w-40 py-2 px-2"> | ||
<%= if player?(@player) && @player.media_thumbnail_url != "" do %> | ||
<img | ||
class="h-full w-full rounded-md ring-0 ring-white" | ||
src={get_player_thumbnail(@player)} | ||
/> | ||
<% else %> | ||
<div class={" | ||
h-full w-full rounded-md ring-0 ring-white bg-gray-200 dark:bg-gray-800 | ||
flex flex-wrap justify-center content-center | ||
#{if paused?(@player), do: "animate-pulse"} | ||
"}> | ||
<.icon name="hero-musical-note" class="h-12 w-12 text-zinc-500" /> | ||
</div> | ||
<% end %> | ||
</div> | ||
""" | ||
end | ||
|
||
def update(assigns, socket) do | ||
{:ok, | ||
socket | ||
|> assign(assigns)} | ||
end | ||
|
||
defp player?(nil), do: false | ||
defp player?(%Player{}), do: true | ||
|
||
defp paused?(%Player{state: :paused}), do: true | ||
defp paused?(_player), do: false | ||
|
||
defp get_player_thumbnail(%Livedj.Sessions.Player{ | ||
media_thumbnail_url: media_thumbnail_url | ||
}), | ||
do: media_thumbnail_url | ||
end |
34 changes: 34 additions & 0 deletions
34
lib/livedj_web/live/components/player_controls/fullscreen_control_component.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule LivedjWeb.Components.PlayerControls.FullscreenControlComponent do | ||
@moduledoc false | ||
|
||
use LivedjWeb, :live_component | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<div phx-click="on_click" phx-target={@myself}> | ||
<%= PhoenixInlineSvg.Helpers.svg_image( | ||
LivedjWeb.Endpoint, | ||
"fullscreen", | ||
"icons/misc", | ||
class: " | ||
h-4 w-4 stroke-2 cursor-pointer | ||
fill-zinc-700 hover:fill-zinc-900 focus:fill-zinc-700 active:fill-zinc-700 | ||
dark:fill-zinc-300 dark:hover:fill-zinc-50 dark:focus:fill-zinc-300 dark:active:fill-zinc-300 | ||
scale-100 hover:scale-[1.1] focus:scale-100 active:scale-100 | ||
" | ||
) %> | ||
</div> | ||
""" | ||
end | ||
|
||
@impl true | ||
def update(assigns, socket) do | ||
{:ok, assign(socket, assigns)} | ||
end | ||
|
||
@impl true | ||
def handle_event("on_click", _params, socket) do | ||
{:noreply, push_event(socket, "fullscreen", %{})} | ||
end | ||
end |
109 changes: 109 additions & 0 deletions
109
lib/livedj_web/live/components/player_controls/volume_control_component.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
defmodule LivedjWeb.Components.PlayerControls.VolumeControlComponent do | ||
@moduledoc false | ||
|
||
use LivedjWeb, :live_component | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<div class=" | ||
hidden sm:inline-flex w-24 | ||
fill-zinc-700 hover:fill-zinc-900 focus:fill-zinc-700 active:fill-zinc-700 | ||
dark:fill-zinc-300 dark:hover:fill-zinc-50 dark:focus:fill-zinc-300 dark:active:fill-zinc-300 | ||
"> | ||
<div class="m-2" phx-click="on_volume_click" phx-target={@myself}> | ||
<%= PhoenixInlineSvg.Helpers.svg_image( | ||
LivedjWeb.Endpoint, | ||
get_volume_icon(@muted?, @level), | ||
"icons/volume", | ||
class: " | ||
h-5 w-5 | ||
" | ||
) %> | ||
</div> | ||
<div class="self-center"> | ||
<.form | ||
:let={f} | ||
for={@player} | ||
id="volume-controls-slider" | ||
class="" | ||
phx-target={@myself} | ||
phx-change="on_volume_change" | ||
> | ||
<.input | ||
field={f[:volume]} | ||
class="seek-bar w-full !m-0 shadow-none !bg-transparent" | ||
id="volume-slider" | ||
value={if @muted?, do: 0, else: @level} | ||
type="range" | ||
min="0" | ||
max="100" | ||
step="1" | ||
phx-debounce={500} | ||
phx-value-key="volume" | ||
/> | ||
</.form> | ||
</div> | ||
</div> | ||
""" | ||
end | ||
|
||
@impl true | ||
def mount(socket) do | ||
{:ok, | ||
socket | ||
|> assign(player: to_form(%{}))} | ||
end | ||
|
||
@impl true | ||
def update(assigns, socket) do | ||
{:ok, | ||
socket | ||
|> assign(assigns)} | ||
end | ||
|
||
@impl true | ||
def handle_event( | ||
"on_volume_click", | ||
_params, | ||
%{assigns: %{muted?: muted?}} = socket | ||
) do | ||
{:noreply, | ||
socket | ||
|> assign(muted?: !muted?) | ||
|> push_event(if(muted?, do: "unmute", else: "mute"), %{})} | ||
end | ||
|
||
@impl true | ||
def handle_event("on_volume_change", %{"volume" => volume}, socket) do | ||
{:noreply, | ||
socket | ||
|> assign( | ||
level: String.to_integer(volume), | ||
muted?: false | ||
) | ||
|> push_event("change_volume", %{volume_level: volume})} | ||
end | ||
|
||
defp get_volume_icon(true, _volume_level) do | ||
"speaker-0" | ||
end | ||
|
||
defp get_volume_icon(_muted?, volume_level) do | ||
get_volume_icon_by_volume_level(volume_level) | ||
end | ||
|
||
defp get_volume_icon_by_volume_level(0), do: "speaker-0" | ||
|
||
defp get_volume_icon_by_volume_level(volume) when volume <= 10, | ||
do: "speaker-1" | ||
|
||
defp get_volume_icon_by_volume_level(volume) when volume <= 30, | ||
do: "speaker-2" | ||
|
||
defp get_volume_icon_by_volume_level(volume) when volume <= 70, | ||
do: "speaker-3" | ||
|
||
defp get_volume_icon_by_volume_level(_volume), do: "speaker-4" | ||
end |
Oops, something went wrong.