Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Easiest way to play audio in page.media?

Started by Muut Archive 11 years ago · 8 replies · 959 views
11 years ago

Video seems very well covered by grav but I couldn't figure out how to play audio. What would be the easiest way to add html5 audio tags to play audio files in page.media? I tried

TWIG
<audio controls>
  <source src="{{ page.media['audio.ogg'].url }}" type="audio/ogg">
</audio>

but it's not processed as twig.
(I'm only an end user, I don't think I can write a plugin... And twig was just a funny English word two or three days ago.)

11 years ago

Well, that was unexpected! Success! I digged through system/src/Grav, duplicated VideoMedium.php, changed it to AudioMedium.php, created the class AudioMedium, added it in MediumFactory.php and now I have a fully functional <audio> tag. Just adding

TXT
![](audio.ogg)

renders a nice html5 audio player. Mind blown! :)

11 years ago

If you submit your new class as a pull request, i can look at adding it to the Grav core.

11 years ago

Nice! True, if working fine please send a pull request to the repository ^^

11 years ago

OK, I knew at some point I would have to figure out how to do a pull request. I'll look into it.

11 years ago

I see you created one just fine, and i've already merged it! Thanks for your contribution. This is how we all make Grav even better!

11 years ago

Glad to be able to contribute, even if it's just a drop in the bucket. I wish I could do more to repay what you guys are already giving us.

11 years ago

Yup, not gotten around to this yet. If no one else does it first, i'll add it to my list.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1338 9 years ago
Archive · by Muut Archive, 9 years ago
2 927 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago