Drupal 7 audio player with download
In this post, I would like to explain how to have a download button for an audio file along with an audio player. My objective was to allow users to play the audio file using a media player and also allow them to download the file using a button.
For this purpose, I created a content type called "Media" with "field_audio" as the audio file field. I chose Mediafront module for the audio player. I hope setting up the audio player won't be that difficult, so let's move into the coding part.
I used hook_menu() for registering drupal path to define how audio download link should be handled.
function kf_menu() {
$items['download/media/%file'] = array(
'page callback' => 'kf_download_file',
'page arguments' => array(2),
'access arguments' => array('view media'),
'type' => MENU_CALLBACK,
);
return $items;
}
The important part of the code is in the menu callback, as this part of the code transfers the file to the client using HTTP.