In this post you will find a step by step explanation on how to make the CCK audio field display 1 Pixel Out MP3 player. Currently I am working on a project that needs a content type where members of the staff can add audio files with a name and a description. The audio file was required to be played with a simple flash player, 1PixelOut preferably. I found that audiofile CCK field, part of Media Field Project worked fine but it did not display a flash player to hear the audio. It just gives you a link to download the file.
Steps
1. Install mediafield, this module requires getID3() library 1.7.7. I install this library in /misc/lib/getid3/getid3/*.php
2. I installed SWF Tools which allowed me to embed audio files with a simple syntax like:
<?php
print swf('test.mp3');
?>
This module is helpful because it already have integration with 1 Pixel Out MP3 Player.
3. Then I downloaded the 1 Pixel Out MP3 Player and installed it in /sites/all/modules/swftools/shared/1pixelout/player.swf. You can remove all other files in the audio-player.zip
4. Now we need to edit audiofield.module to make it display our 1 Pixel Out Player. In the code look for the last function called theme_audiofield(). Replace the content with this code:
<?php
/**
* Themed output for audiofield on a node view page. Called from formatter hook.
*/
function theme_audiofield($file, $item, $field) {
$file = (array)$file;
if (is_file($file['filepath'])) {
$name = $file['filename'];
return swf($name);
}
}
?>
5. There is an error in audiofield.module that we need to fix, you can find more info here. In a function called audiofield_field_formatter() add a reference to multimediafile.inc
<?php
/**
* Implementation of hook_field_formatter().
*/
function audiofield_field_formatter($field, $item, $formatter) {
require_once(drupal_get_path('module', 'audiofield') .'/multimediafile.inc');
if (!isset($item['fid'])) {
return '';
}
$file = _field_file_load($item['fid']);
return theme('audiofield', $file, $item, $filed);
}
?>
6. Now create a new content type and add Audio field to it. Leave blank the field called "Path to save uploaded file to" because 1 Pixel Out will look in the /files directory only.
That's it you should have a simple Audio player working with your new content type.
Comments
Audio (1pixeloout.swf)Player is not playing the Audio mp3 files
All,
I am very new to Drupal.I have followed the above steps but still the player is not playing the mp3 file. Intially i got a link for my Audio file.. After doing these changes, i get a button for my player. once i click on play .. no output. Can anybody help me?
some problem
i follow all the steps and i get "error opening file" after i click 1pixeloout play button. anybody can help us?
Mediafield Display
Now that there's a Mediafield Display module, you shouldn't have to deal with any of this. Hopefully it'll help you. It really did the trick for me!
wrong encoding of media url
i think the problem is a wrong encoded media url.
the returned url to the embeded mp3 file starts with http%3A/%252Fwww.mydomain.org/files/myaudio.mp3, which decodes to http:/%2www.mydomain.org/files/myaudio.mp3 - at least, if I try zo open the link in amarok mp3 player.
It seems to be problemtaik for flash to decode that string correctly.
Quick workaround for this bug:
modify swftools.module to use this function:
URL Encoding
I forgot to add in the instructions my fix for this encoding issue in swftools module. But your solution is way better than mine, so I will use this one now. Thanks suit4.
Thanks a million for this
Thanks a million for this code. Now I got 1pixelout working in Firefox, IE6 and IE7. regards
----------------------------------------------------------------------
http://www.bwv810.com/
I am a writer and researcher. In my spare time I build websites with Drupal.
Je peux communiquer en français. / Я могу общаться на русском языке.
I wish I could say that this
I wish I could say that this helped but I seem to get the same issue even after applying your fix here.
My audio posts gives me a flash "play" button but then "error opening file" which is because it looks for a file at;
http://myurl.com/%2Fmyurl.com/path/to/file - can't seem to get rid of that %2F
Found a solution
Found a solution here!
http://drupal.org/node/202591#comment-751063
nice work antd thank you for
nice work and thank you for sharing!
I have the problem that I need to get a bunch of mp3-files into a playlist. inserting a set of files to a node is not the problem, but to tell a mp3-player that there is a playlist is not easy - for me.
thanx for your help!
1 pixel out with Drupal 7 on ubercart product page
I couldn't find a great way to embed audio (mp3) on a page (node) on Drupal 7. One can insert it as a CCK field, but I needed to insert it into an ubercart product page.
My Solution:
I downloaded the 1pixelout code from http://wpaudioplayer.com/download/ from which I got 3 main files and uploaded it to my server like this:
http://www.fakedomain.com/myname/audio/player.swf
http://www.fakedomain.com/myname/audio/audio-player.js
http://www.fakedomain.com/myname/audio/music.mp3
and followed the tutorial here http://www.macloo.com/examples/audio_player/
I inserted the following code on the product page of my ubercart online music store:
For a second player on a page I used this HTML:
I hope it will work for you too in Drupal 7