Stream mp3 with twig

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:

{{ 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

I solved it! Here is the right code:

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

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

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.

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

Anything particular you were stumbling upon?

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.