jon9china Posted October 22, 2015 Share Posted October 22, 2015 Is there a way to insert instances of audio files (playable when viewed) using the textarea field? If 'no', then what is the way to include playable mp3 files without having to specify in a template file where they might occur? Thanks for helping out a newbie! Jon (edited: I am going to try to do this using the Hanna Code module - is this a recommended solution?) Link to comment Share on other sites More sharing options...
jon9china Posted October 22, 2015 Author Share Posted October 22, 2015 I did solve this using a simple PHP Hannah code bit. Still finding my way around Processwire basics. I'm curious if this solution is somewhat overkill? Link to comment Share on other sites More sharing options...
kixe Posted October 22, 2015 Share Posted October 22, 2015 Choose 'Fieldtype File' and set allowed format under details tab to mp3 or wav.call the file via API. Here a code snippet I used once $playlist = "<ol id=\"playlist\">\n"; foreach($page->audio as $file) { $playlist .= "<li><a href=\"$page->path?src=$file->url\" data-src=\"$file->url\">$file->description</a></li>\n"; } $playlist .= "</ol>\n"; $body = <<< _OUT <!-- Media Page --> <section id="basic"> <div class="container"> <div class="col-lg-12 text-center"> <h2 class="section-heading">$page->title</h2> <h3 class="section-subheading text-muted">$page->subheader</h3> </div> <div class="col-sm-8 col-sm-offset-2 audio-player"> <audio$src preload="auto" controls> $html5error </audio> $playlist </div> </div> </section> _OUT; 2 Link to comment Share on other sites More sharing options...
jon9china Posted October 22, 2015 Author Share Posted October 22, 2015 Choose 'Fieldtype File' and set allowed format under details tab to mp3 or wav. call the file via API. Thanks for this kixe. Can you tell me, where is the code where you 'call the file via API' to be placed? In the template file? I was looking for a solution where I can simply put an audio player (native controls are fine) at any spot on my page, within any text. I don't want the audio to be tied to region specified in a template. I did find a solution using the Hannah code module which seems to be great. But I was curious if there is a simpler way, such as a way to include html tags for audio or video that don't get stripped out of a textarea by the editor, by using some syntax or setting or something like that. Link to comment Share on other sites More sharing options...
Macrura Posted October 22, 2015 Share Posted October 22, 2015 Hanna code is certainly a great way to place an audio file into a textarea, the files themselves loaded into your files field and then referenced in the RTE; to make it easier for editors you could add tagging on the files and then reference the tag in your hanna code. Using the RTE itself, you could simply use the link button and then select the audio file. Then you can initialize that with something like Soundmanager2. So in other words, you would end up with an anchor in your textarea linking to an audio file, which then using a jQuery selector could be turned into a player. For more control, you could check the field (e.g. using strpos) at the top of your template file, and then do a str_replace on the field. The main advantage in that is that you could initialize the audio players and load specific assets based on the existence of said mp3 link, instead of on all pages, and you could also replace the simple anchor with more specific markup that might be required for your player. Lastly you could make a module that would essentially do the same thing, and apply it as a textformatter to the field. 3 Link to comment Share on other sites More sharing options...
jon9china Posted October 23, 2015 Author Share Posted October 23, 2015 Thanks. I see there are all kinds of levels of sophistication you can go to. Nice. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now