An MP3 Player for Inline MP3 Attachments in phpBB3
phpBB has some really neat features for file attachments that you might use automatically with a post. For example, if you upload an image and hit the button “Place Inline”, some BBcode will be added to the text box and when you preview or submit your post the image will be rendered inside of the post instead of just a link to download the image. Similarly, if you upload a .wma file and place it inline, you will get the Windows media player to play this file back to anybody viewing that post. Unfortunately, no such thing exists by default for .MP3 files, the popular audio format.
I’ve previously covered how to create a BBcode that will take the URL to an MP3 file and create an embedded Flash player for that file in a post (along with other very handy BBcodes). You could even upload an MP3 file as an attachment and then take the URL to that file and put it into the MP3 BBcode and everything would work just fine.

Now, we’re going to take that modification a step further and make it so that if you upload an MP3 file and you click the “Place Inline” button, it will put the file URL in the text box and wrap it in the [mp3][/mp3] BBcodes automatically.

Step 1: Download the player
You’ll need to download this player (right-click, Save as…). It is an .swf file; this is the actual flash player that provides an interface and the means to playback .mp3 files.
Step 2: Upload the player to your server
Upload the .swf file you just downloaded to some location on your server and note the path to it. It will need to have permissions set to be publicly readable.
Step 3: Create the BBcode
In order to add more BBcodes, log into the Administration Control Panel. There, go to the Posting tab, and then BBCodes. Click the ‘Add a new BBCode’ grey button to get to the next page where you can configure your new entries. Create a new BBcode with the following information. You can decide for yourself if you want it shown on the posting page or not. If you need further help with this step, see my previous post on Essential BBcodes. Be sure to use the correct code that points to where you uploaded the player.swf file you downloaded in step 1.
BBCode: [mp3]{URL}[/mp3]
HTML:
<object type="application/x-shockwave-flash" data="http://www.404techsupport.com/mp3player/player.swf" id="audioplayer1" height="24" width="290">
<param name="movie" value="http://www.yoursite.com/mp3player/player.swf" />
<param name="FlashVars" value="playerID=1&soundFile={URL}" />
<param name="quality" value="high" />
<param name="menu" value="true" />
<param name="wmode" value="transparent" />
</object>Help line: [mp3]URL to file[/mp3]
Step 4: Modify two files.
Create a back up copy of each of these files. Then modify these files and upload them back to your server.
phpbbRoot/styles/prosilver/template/editor.js
Find:
/**
* Add inline attachment at position
*/
function attach_inline(index, filename)
{
insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
document.forms[form_name].elements[text_name].focus();
}
Replace with (Be sure to update the code so that it is pointing to the correct location for your forum):
/**
* Add inline attachment at position
*/
function attach_inline(index, filename, attach_id)
{
if (filename.match(".mp3"))
{
insert_text('[mp3]' +'http://yourforumURL.com/download/file.php?id=' + attach_id +'[/mp3]'+' ' + filename);
document.forms[form_name].elements[text_name].focus();<br />
}
else
{
insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
document.forms[form_name].elements[text_name].focus();
}
}
phpbbRoot/styles/prosilver/template/posting_editor.html
Find:
<input type="button" value="{L_PLACE_INLINE}" onclick="attach_inline({attach_row.ASSOC_INDEX}, '{attach_row.A_FILENAME}');" /> <!-- ENDIF -->
Replace with:
<input type="button" value="{L_PLACE_INLINE}" onclick="attach_inline({attach_row.ASSOC_INDEX}, '{attach_row.A_FILENAME}', '{attach_row.ATTACH_ID}');" /> <!-- ENDIF -->
Step 5: Purge the cache
In the Administration Control Panel, under the General tab, click the ‘Run now’ button across from “Purge the cache.”
Step 6: Test it out!
Go to your forum and create a new post. Upload an .mp3 file and hit the button to “Place Inline” as soon as the upload finishes. In the text area, you should get some text inserted that appears like in the following screenshot.
Original credit goes to this site, The Koumjian Review, but I use a different Flash player, only edit two files, and corrected a number of bugs and syntax errors from that post. If you’d like to test this functionality out, you can post in the comments to this article in the forum by following the link below.
Comment on this post in our forums
Related posts:




August 12th, 2009 at 10:01 PM
A demo:
September 28th, 2009 at 8:02 PM
hello,
i followed your tutorial (and the fella who wrote it first) on how to set up attached mp3 thingies : http://www.404techsupport.com/2009/08/12/an-mp3-player-for-inline-mp3-attachments-in-phpbb3/
but i tried to adapt this to try get my flash videos working from attachments instead of mp3s
i made a bbcode for flv instead of mp3 and replaced all the mp3 bits with flv.
the [flash][/flash] tags that installed/came with phpbb (phpbb 3.0.4 then i updated to 3.0.5) doesnt work for me either embedding or from attachments. i just get white boxes.
anyway i made this flv. thats works when embed but not from attachments
…and adapting your mp3 code can get a flash player to appear inline from an attachment but it does not play the file. i get a "unknown playlist format: html" error on the player.
if i add ,flv to the end before the [/flv] tag i get the error "video not found or access denied" error
im guessing must have something to do with the file.php?id= bit ???
this is pretty much the two codes i have just tried and explained to you
[flv]http://mysite.com/subfolder/download/file.php?id=29[/flv][flv]http://mysite.com/subfolder/download/file.php?id=29.flv[/flv]so how can i get my original [flash=][/flash] working ?
or how can i edit somewhere to get that working correctly?
or how can i get this mp3 lark to work for me with flash .flvs instead or mp3s?
any ideas?
thanks loads.
things you may also like to know:
- im on phpbb 3.0.5 automod installed and acpadduser mod and mchat mod
- im on windows vista 64
- im using firefox latest version
- i have flash 10 i think
- the player i have on the phpbb is jw or something player which works when i embed the absolute url manually myself without the file.php?id= bit to files with proper names for example vid.flv not like the files after they’ve been attached which seem to be called random strings like 5j5kjkfg779ffgfdsg in the attachment folder that i declared in the acp under posting > attachments menu
September 29th, 2009 at 8:40 AM
Can you post the [flv] bbcode you’re using?
You might also be interested in the YouTube bbcode that I list in another article to compare:
http://www.404techsupport.com/2009/03/0 … pbb-forum/
Can you point me to the .flv or .swf files you’re trying to use and I can see if I can get it working on my site here with the normal Flash tag or a custom flv tag like you made?
September 29th, 2009 at 8:52 AM
this is the [flv][/flv] phpbb code i made but works fine embedding an url
<embedsrc="http://mysite/subfolder/styles/prosilver_se/template/mediaplayer.swf"
width="480"height="360"
allowscriptaccess="always"
allowfullscreen="true"
autostart="false"
flashvars="height=360&width=480&skin=http://mysite/subfolder/skin.swf&file={URL}"/>
if i use this phpcode below to embed the file
[flv]http://mysite/file.flv[/flv]i get it working fine (though this will not play straight from an attachment rather than an embed)
if i use this phpcode below to embed the file
[flash=480,360]http://mysite/file.flv[/flash]i get a white box (and this will not play straight from an attachment)
i have a
[youtube][/youtube]bbcode that works fine too with you tube video urls.
the problem is i cant get either the original [flash] tag to work or i canont get flash to appear inline from attachments and play correctly.
here is the file i was using:
my flash video file
thanks for replying
September 29th, 2009 at 10:08 AM
As a URL to the flv with bbcode:
width='480'
height='360'
bgcolor='undefined'
allowscriptaccess='always'
allowfullscreen='true'
flashvars='file=http://spence-animator.co.uk/flashvideo.flv'
/>
As an attachment:
width='480'
height='360'
bgcolor='undefined'
allowscriptaccess='always'
allowfullscreen='true'
flashvars='file=http://par.404techsupport.com/download/file.php?id=244.flv'
/>
September 29th, 2009 at 10:52 AM
Okay cool.
So how can i get mine working since it doesn’t for me?
you used all my codes to do this? that what it seems like.
So then it it something to do with where a player should be?
i have just 1 mediaplayer and 1 skin which ive linked/directed to in my [flv] bbcode with the scr= bit of code
should these be somewhere esle ?
where is the original bit of [flash][/flash] code so i can take a look maybe its pointing to a player that isnt there?
do i need a object.swf or something or is just the player enough?
are there some permissions somewhere in missing. it says flash is on in my post a file section when i go to attach a file.
any ideas why this doesn’t work for me then?
thanks
September 29th, 2009 at 11:02 AM
Sorry, I deleted a post that had this on it while I was still messing around:
Now that I’ve got it working, let me synthesize the steps I took and remove the ones that didn’t work then I’ll post a complete run-through as to how to get it to work.
It’ll be along shortly, probably a little later this afternoon when I get the next chance to sit down.
September 29th, 2009 at 11:06 AM
Ok that would be great.
i have feeling your gonna say [flash][/flash] just worked though and ill never work it out. :S
ill be looking forward to seeing your next post,
thanks for all help and effort so far. its very much appreciated
September 29th, 2009 at 11:23 AM
Just posting this screen grab to show you what I get:
September 29th, 2009 at 1:06 PM
Have no worries. That’s definitely not the solution. Flash won’t work because .flv files need a player to control them. The solution definitely seems inline with what you’re looking for.
Also, all the smilies here and you went with a simple :S
September 29th, 2009 at 2:01 PM
i have a player to control them though dont i ? other wise the [flv][/flv] wouldn’t work when embedded which it does?
im confused, have you given up on helping me find a solution now or?
see ya
September 29th, 2009 at 2:36 PM
You have the player, which the [flv] bbcode uses. I was explaining why the [flash] bbcode does not work directly.
I’m working on writing up a formal solution to your request. Screenshots and code are required, so it’s taking some time and effort.
September 29th, 2009 at 3:20 PM
Oh phew, thanks. Thought I was back on my own again then.
I still dont understand what you mean about the [flash] not working directly not having a player. Isn’t that [flash] just suposed to work straight off after install?
Do I have to put another player somewhere then and somehow and link that up myself then? Perhaps you mean [flash] was intended for .swf and not .flv which is why most seem to write their own [flv] bb codes?
Maybe your writing that up in your formal solution as well as the [flv] bit. Ill just shut up and be patient I guess. Finding it difficult though cos this been driving me nuts for a week, and there doesn’t seem much on the internet any other place that explains all this very clearly for new users of phpbb.
Thanks.
September 29th, 2009 at 8:03 PM
There ya go. There’s your full write up: http://www.404techsupport.com/2009/09/2 … in-phpbb3/
Any follow up questions should be redirected to the respective comments thread in this same forum: http://par.404techsupport.com/viewtopic.php?f=19&t=1382
November 21st, 2009 at 5:27 AM
Hello,
I have been reading your tips about including inline multimedia players into posts very carefully. Very good, I have only one question, concerning subsilver styles. There is no posting_editor.html where I could replace any code. Would you please be so kind to give me a hint how to include the ATTACH_ID in the BBCode by modifying a template file!
Thank you very much. It is important for me.
Bernd
November 21st, 2009 at 6:52 AM
It looks like the comparable code can be found here:
\styles\subsilver2\template\posting_body.html
Around line 231:
<td class="row2"><select name="attachments">{S_INLINE_ATTACHMENT_OPTIONS}</select> <input type="button" class="btnbbcode" accesskey="a" value="{L_PLACE_INLINE}" name="attachinline" onclick="attach_form = document.forms[form_name].elements['attachments']; attach_inline(attach_form.value, attach_form.options[attach_form.selectedIndex].text);" onmouseover="helpline('a')" onmouseout="helpline('tip')" />The attachment ID needs to be passed into the attach_inline function in editor.js. I’m not familiar enough with Subsilver2 to know how to do that. This just automates the task for .mp3 files, users could:
Upload their attachment.
Right-click on the attachment and copy the link location.
Paste the link into the text field.
Wrap the link with the mp3 bbcode ([mp3]).
November 21st, 2009 at 11:16 AM
Dear Jason!
Thank you very much for your quick reply. I think my users are not clever enough to include the attachment id themselves.
If I i.e. change
into
attach_inline(attach_form.value, attach_form.options[attach_form.selectedIndex].text,'1564')… it is working for a special mp3-file
but I would like to have the attach_id, doesn’t it come from posting.php? There I can find something like this:
There must be a possibility to bulid a variable that could be passed to posting_body.html and then passed to edit.js!?
Somwhere, I think here:
What do you think?
Greetings
Bernd
November 21st, 2009 at 3:53 PM
I agree and I looked into it quite a bit this morning. Clearly the variable exists because it is used to build the link to the file in the posting window for the Subsilver2 style. It seems lost somewhere in translation between the editor.js file and the posting_body.html and the posting_attach_body.html template files.
I did the exact same test you did with hard coding the attachment value into the javascript function and it worked as well. If it was known where the
attach_form.value = the index value
attach_form.options[attach_form.selectedIndex].text = the filename
functions were getting their values, the problem could easily be solved.
If you look for inline inside \includes\functions_posting.php, it might clarify some things.
The Place Inline button in the Subsilver2 style determines the attachments index by the value the drop-down entry is assigned. It also gets its filename from the text value of that drop-down. Basically it’s an indirect route to pass the needed information. Unfortunately for us, that doesn’t leave much room for passing other information, like the AttachID along.
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>';November 21st, 2009 at 4:29 PM
Linkin Park – Breaking the Habit.mp3
November 21st, 2009 at 4:42 PM
Ok, so I figured out a way to do it for the Subsilver2 style. It’s more complicated and would have been easier to switch your users to the Prosilver theme, but anywho… here goes. This assumes you have taken no other steps besides uploading the .swf file to your server and created the mp3 BBCode.
Open \includes\functions_posting.php
Find
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>';Replace with
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . ',' . $attachment['attach_id'] . '</option>';Open \styles\subsilver2\template\editor.js
Find
/**
* Add inline attachment at position
*/
function attach_inline(index, filename)
{
insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
document.forms[form_name].elements[text_name].focus();
}
Replace with
/**
* Add inline attachment at position
*/
function attach_inline(index, filenameID)
{
var splitresults = filenameID.split(",");
var filename = splitresults[0];
var attach_id = splitresults[1];
if (filenameID.match(".mp3"))
{
insert_text('[mp3]' +'http://yourforumURL.com/download/file.php?id=' + attach_id +'[/mp3]'+' ' + filename);
document.forms[form_name].elements[text_name].focus();
}
else
{
insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
document.forms[form_name].elements[text_name].focus();
}
}
Essentially, what this does is concatenate the filename in the posting window (and drop-down menu) with a comma and the attachment ID in the functions_posting.php file. Then, when you hit the ‘Place Inline’ button, the editor.js will parse that string we made on the comma and assign the filename variable the filename and the attach_id variable the attachment ID. It then puts it in the URL like normal and wraps it in a BBCode.
That took a little too long for me to wrap my head around. Hope that works for you. I tested it out here on my own forum and it seemed to work, but let me know how it turns out for you.
November 21st, 2009 at 4:52 PM
You could use the same method for embedding .flv videos into your forum as well. I wrote about that here:
http://www.404techsupport.com/2009/09/2 … in-phpbb3/
November 22nd, 2009 at 10:40 PM
Dear Jason,
thank you for your assistance indeed. Of course, next time I setup a forum with phpbb I will use the standard template prosilver, but as you know, there are so many stylish templates …
and I thought subsilver2 might be always supported, like you have.
When I will come home today from work I’ll try your modification.
Many thanks and Goodbye from Germany,
Thanks for the music demonstration, Joe McTesterson
I use the longtail flv player for mp3 and video.
Bernd
November 23rd, 2009 at 2:00 PM
Dear Jason!
Everything is working quite well with our subsilver2 style.
Until now we only could include external ressources with our multimedia player. Now we can show audio files and flash movies inline.
Bye, from Black Forest,
Bernd