serpent

serpent

Basic music player with Membrane

First, thanks to the Membrane team for creating this awesome framework!

Based on SimplePipeline I’m trying to build a simple music player. Following functionality is required:

  • Start playback from file, get notification on finish
    • use handle_element_(start|end)_of_stream/4 hooks on sink
  • Get current playback position
    • Save Time.monotonic_time() on playback start and calculate difference to now?
  • Nice to have: play/pause

I made some experiments on how to get the current timestamp. First intuition was to create a :tick timer and then query the current time from the sink – couldn’t quite figure it out, yet.

For some reason the timer runs very unsteady. My above example gives me (expected interval: 5000, off is a factor):

handle_element_start_of_stream:
16:03:34.304 [debug] Membrane.Demo.SimplePipeline/:portaudio received start of stream
:portaudio
:input
===============================
handle_tick:
:tick
last_tick: -576460742608535951
interval: 5068.75382 (off 1.013750764)
===============================
handle_tick:
:tick
last_tick: -576460737539782131
interval: 2.763771 (off 5.527542e-4)
===============================
handle_tick:
:tick
last_tick: -576460737537018360
interval: 2148.508728 (off 0.42970174559999996)
===============================
handle_tick:
:tick
last_tick: -576460735388509632
interval: 2558.596995 (off 0.511719399)
===============================
handle_tick:
:tick
last_tick: -576460732829912637
interval: 2535.085853 (off 0.5070171706)
===============================

My clock subscription does not seem to have any effect.

When terminating the pipeline (Pipeline.terminate) and starting it again, I start to notice artifacts in the output, everything seems to slow down. CPU load is <5%, though. Is there anything else to do for a clean restart?

Sincerely,
Steffen

Most Liked

WojciechBarczynski

WojciechBarczynski

Membrane Core Team

Hi :slight_smile:
Usually, business logic like the one you described is handled in filter elements, rather than in the pipeline itself.

Assuming your audio files have correct PTS values (or that they are somehow adjusted before entering the business logic element), you can easily read timestamps from buffers.

In your case, I would simply use handle_info in Pipeline to receive application event (like pausing/playing), pass notification to custom element with notify_child and handle it there on handle_info.
In case of pausing/playing audio, you can enqueue your audio in the element state if needed.

WojciechBarczynski

WojciechBarczynski

Membrane Core Team

Hi, sorry for the late response.

Element in the pipeline can operate in three flow control modes - “auto”, “manual” and “push”. If you expect long pauses, you are right that it would be better to use “manual” mode to prevent any extensive data accumulation and memory consumption. You will need to implement handle_demand in such case.

Keep in mind, that if previous elements work in “push” mode (e.g. some elements receiving data via the network connection without flow control), Membrane will still enqueue them under the hood (basically it’s impossible to handle that without dropping buffers), which may result in toilet overflow error.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement