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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Stream mp3 with twig

Started by Shane 7 years ago · 5 replies · 918 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 Thomas, 1 week ago
2 56 13 hours ago
Support · by Anna, 3 days ago
2 61 16 hours ago
Support · by Justin Young, 17 hours ago
1 32 17 hours ago
Support · by Duc , 1 week ago
2 66 5 days ago
Support · by Colin Hume, 1 week ago
2 59 5 days ago