Audio player display on homepage for featured item

I am trying to insert the html5 audio player on the homepage for featured item containing audio file, any idea how this can be done?


I still didn't find any solution, can someone help me?

You should be able to make a copy of the items/random-featured.php file from application/views/scripts and put that in your theme.

Editing that copied file will change how the random featured items are displayed. You probably want to use the file_markup or files_for_item functions to display the files. That will use any plugins that alter the item display, like HTML5 Media does.

Thanks for the reply. I already have a item/random-featured.php file in my theme, and I already made some trivial editing to change some display options. But unfortunately my knowledge of php is almost zero, and I cannot manage to use the functions you mention.

Can you precise which lines I should add to the file?


I managed to use the files_for_item function in the items/browse.php file (in application/view/scripts), by simply adding the following code:

<?php echo files_for_item(); ?>

But when I try to use the same code in the items/random-featured.php file of my theme directory, I get the following error :


A current item variable has not been set to this view.

How can I fix this?

By the way, is there an equivalent to files_for_item that only displays the first file attached to an item? Or only the audio files?


The loop through items in random-featured.php doesn't use the same looping structure that lets files_for_item() dig up an item to use.

You can explicitly pass in the item inside the loop like this:

echo files_for_item(array(), array('class'=>'item-file'), $item);

Thank you very much, it works perfectly!

files_for_item returns all the files associated to the featured item. Is there a way to return only the first file? Or only the audio files?

To get just the audio files, you could try something like...

foreach (loop('files', $item->Files) as $file):
     $mime = metadata($file,'MIME Type');
     $audio = array('application/ogg','audio/aac','audio/mp3'); // expand this array of audio mime types as needed

     if( array_search($mime,$audio) !== false ){
          // Do something