Skip to content
Snippets Groups Projects
Verified Commit a83ad720 authored by dos's avatar dos
Browse files

sim: Implement seeking and duration in media fake using pymad

parent ef001e61
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,7 @@ For running the simulator, you'll need Python 3 with pygame and wasmer:
::
$ python3 -m venv venv
$ venv/bin/pip install pygame requests
$ venv/bin/pip install pygame requests pymad
$ venv/bin/pip install wasmer wasmer-compiler-cranelift
.. warning::
......
......@@ -746,7 +746,7 @@ environment with the required packages:
$ git clone https://git.flow3r.garden/flow3r/flow3r-firmware
$ cd flow3r-firmware
$ python3 -m venv venv
$ venv/bin/pip install pygame requests
$ venv/bin/pip install pygame requests pymad
$ venv/bin/pip install wasmer wasmer-compiler-cranelift
.. warning::
......
import pygame
from _sim import path_replace
try:
import mad
except ImportError:
mad = None
_loaded = False
_duration = 0
def stop():
......@@ -18,11 +24,13 @@ def load(path, paused=False):
"""
Load path
"""
global _loaded
global _loaded, _duration
if path.startswith(("http://", "https://")):
return
pygame.mixer.music.load(path_replace(path))
pygame.mixer.music.play()
if mad:
_duration = mad.MadFile(path_replace(path)).total_time()
if paused:
pygame.mixer.music.pause()
_loaded = True
......@@ -90,10 +98,14 @@ def seek(pos):
return
pygame.mixer.music.play()
pygame.mixer.music.rewind()
if mad:
pygame.mixer.music.set_pos(pos * get_duration())
def get_duration():
if not mad:
return 99999
return _duration / 1000
def is_visual():
......
pygame
requests
pymad
wasmer
wasmer-compiler-cranelift
......@@ -29,6 +29,10 @@ try:
except ImportError:
print("Warning: `requests` is missing so no `urequests` mock will exist")
try:
import mad
except ImportError:
print("Warning: `mad` is missing, MP3 support in `media` mock will be limited")
sys_path_orig = sys.path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment