MyBB Community Forums

Full Version: auto embed MP3 urls
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2016-09-17, 09:26 PM)alley Wrote: [ -> ]Does not work

Try the Event code again, it should work now.

I had to change it again since it was missing the for() loop. (I had a real trouble posting the code initially with constant anti-flood/bot/spam popping up from cloudflare every edit :/)
(2016-09-18, 03:50 AM)stryderunknown Wrote: [ -> ]
(2016-09-17, 09:26 PM)alley Wrote: [ -> ]Does not work

Try the Event code again, it should work now.  

I had to change it again since it was missing the for() loop.  (I had a real trouble posting the code initially with constant anti-flood/bot/spam popping up from cloudflare every edit :/)

I did not use the eventhandler code, I used this one: 
<script>
if (! url2media){

// don't edit url2media variable if you have the script exist multiple times in a page
var url2media="1";
var links = document.getElementsByTagName("a");

for (var i = 0; i < links.length; i++) {
if (links[i].href.search("mp3") !== -1) {
links[i].outerHTML ='<video id="mediamp3" controls=""><source src="'+links[i]+'" type="audio/mpeg"></video>';
 }
}
</script>
Okay I can see the error (sorry for the inconvenience). It's part to do with my attempt to stop the code being created too many times and part to do with how javascript handles if !(variable)

So rather than using the original method I was trying to do, it's simpler just to use the eventhandler version as it will only call once, even if there are multiple issues of code inserted and it will be called when the document is loaded, so you could insert it nearly anywhere in a template.

If you check the post with original code, I've edited it to reflect the changes (rather than keep quoting similar code multiple times)
Hey, thanks so much @stryderunknown  ... it works!  Big Grin stryderunknownstryderunknownstryderunknown
(2016-09-16, 12:14 AM)alley Wrote: [ -> ]
(2016-09-15, 11:49 PM)Starnova Wrote: [ -> ]I use the mod Automedia.. it just requires adding any link and plays. I much prefer jplayer but I cannot get it to work on mybb. 1.86  you can take a look if you wish here:

https://www.ebook-mecca.com/Thread-Love-...e-Chickens

it is not a pretty player at all and I really do not like it but it is practically the only thing that works ,,  I guess mybb does not find a use for players like jplayer, but many users do..

THanks, but what in the hell does "love among the chickens" have to do with myBB?  Dodgy

That is the mp3 file in comedy on my e-book site to show you the working program. Wink

(2016-09-16, 12:14 AM)alley Wrote: [ -> ]
(2016-09-15, 11:49 PM)Starnova Wrote: [ -> ]Its the only thing I could get to work .. I have tried everything else.
@stryderunknown 
This is great, but I noticed that this code seems to put the mp3 player way down at the bottom of the post. Is there a way to have it display the mp3 player at the top of the post?
@Alley
Sorry for the delay in replying, Placement is done through the use of the CSS entry using a relative position and top/bottom/left/right adjustments.
Pages: 1 2