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

Stream mp3 with twig

Started by Shane 7 years ago · 5 replies · 1029 views
7 years ago

I was successfully able to get my mp3 file to play when I moved my mp3 file into the directory the page was located in with this line:

TWIG
{{ page.media['file.mp3'].preload('metadata') }}<br>

However, I want to use this with many pages, and don't want to move my audio files into the page directory. I want them to be loaded from /user/pages/audio. That example above is loaded from something like this: /user/pages/005chapter/003page/. So I need to be able to load it from the location, /user/pages/audio or something similar. I haven't been able to get the right code. Thanks in advance for the help.

Shane

last edited 11/19/19 by Shane
7 years ago

I solved it! Here is the right code:

TWIG
 {{ page.media['user://pages/audio/audiofile.mp3'].preload('metadata') }}<br>
7 years ago

For anyone else who wants to know in which locations media files can be placed, the documents have a dedicated chapter on it: Where to put your media files

7 years ago

Yes, that is the chapter I had been looking at quite a while. The examples are very clear for the images... however, it took me a while to connect the two ideas between the images, and audio files. That page probably could be divided in two, one for pictures (which is very complete and excellent), and one for audio, which could use a little more clarity. Thanks for the input though.

7 years ago

@shane, as far as I know the syntax is the same for different media types...

Anything particular you were stumbling upon?

7 years ago

No, you are right, the syntax is the same. I wasn't aware the syntax was the same between the two. That is where my confusion was.

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 4 weeks ago
19 484 5 days ago
Support · by Lauw, 7 days ago
2 99 7 days ago
Support · by Anna, 3 weeks ago
4 426 1 week ago
Support · by gtx, 4 weeks ago
4 377 3 weeks ago
Support · by Anna, 1 month ago
9 484 3 weeks ago