Hi,
Sorry, I did not look at the LiveView tutorial.
I have worked with polling model for music player a couple of years ago: local_assistant/lib/local_assistant/player/player.ex at f02e6779d011a612a317d41a97aad4c330a7034d · RomanKotov/local_assistant · GitHub
This was a local player. We used it in the office to play tracks.
Pros:
- Easy to implement.
Cons: - The player I used to play track (mopidy) could be blocked on long operations. For example, loading very large playlist could crash the whole application. Or the UI was unstable.
I took the issues into account and created another application to play music, and some other stuff (it will be Elixir-based Smart Home). Now it uses PubSub (indirectly) and the other player (mpv).
New examples:
- How I use player state: exshome/lib/exshome_player/live/player.ex at 31ea257f1554eaf0d6b73a0888fb9fb0c864903a · exshome/exshome · GitHub
- Player layout: exshome/lib/exshome_player/live/player.html.heex at 31ea257f1554eaf0d6b73a0888fb9fb0c864903a · exshome/exshome · GitHub
- Place, where I broadcast player events: exshome/lib/exshome_player/services/mpv_socket.ex at 31ea257f1554eaf0d6b73a0888fb9fb0c864903a · exshome/exshome · GitHub
- PubSub itself: exshome/lib/exshome/pub_sub.ex at 31ea257f1554eaf0d6b73a0888fb9fb0c864903a · exshome/exshome · GitHub
- This part allows to make 100% async tests for PubSub: exshome/lib/exshome/pub_sub.ex at 31ea257f1554eaf0d6b73a0888fb9fb0c864903a · exshome/exshome · GitHub
I like how newer approach. It works better
Have streamed the implementation process some time. Here is a thread about the Exshome: Exshome - DIY Elixir Smart Home
Hope this helps