WordPress: Playlist shortcode with external audio or video files
The [playlist] shortcode in WordPress 3.9 is great, but we can’t use it for external files.
Here’s a solution I wrote on WPSE to use it for external files.
The plugin is hosted on GitHub.
Here’s version 0.05b for those who use PHP 5.1.x or PHP 5.2.x.
WordPress 4.0 support:
Please update to version 0.0.5+ of the plugin due to some small playlist changes in WordPress 4.0. Thanks.
Version 0.0.6, now supports with autoplay and the GitHub Updater support. It works on WordPress 4.0+.
Version 0.0.7 introduced the new shortcodes _playlist and _track and the support for the shortcodes wpse_playlist and wpse_trac will phase out.
The current version is 0.0.9.
Example 1a
This audio playlist:
is generated by the following shortcode:
[_playlist type="audio" tracklist="true" tracknumbers="true" images="true" artist="true"] [_track title="Ain't Misbehavin'" src="//s.w.org/images/core/3.9/AintMisbehavin.mp3" type="audio/mpeg" caption="" description="" image="" meta_artist="Louis Armstrong and His Orchestra" meta_album="78 RPMs and Cylinder Recordings" meta_genre="" meta_length_formatted="3:21" image_src="//s.w.org/images/core/3.9/louis.jpg" image_width="308" image_height="240" thumb_src="//s.w.org/images/core/3.9/louis.jpg" thumb_width="308" thumb_height="240"] [_track title="Buddy Bolden's Blues" src="//s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3" type="audio/mpeg" caption="" description="" image="" meta_artist="Jelly Roll Morten" meta_album="78 RPMs and Cylinder Recordings" meta_genre="Jazz" meta_length_formatted="2:09"] [/_playlist]
Example 1b
Here’s the playlist from example 1a, but with
tracknumbers="false" images="false"
Example 2
Here’s the vanilla version of the above audio playlist:
generated from the shortcode:
[_playlist type="audio" current="no" tracklist="yes" tracknumbers="no" images="no" artist="no"] [_track title="Davenport Blues" src="//s.w.org/images/core/3.9/DavenportBlues.mp3"] [_track title="Dixie Blues" src="//s.w.org/images/core/3.9/Louisiana_Five-Dixie_Blues-1919.mp3"] [/_playlist]
Example 3
Here’s a video playlist:
from
[_playlist type="video"] [_track caption="Live widgets previews in WordPress 3.9" src="//s.w.org/images/core/3.9/widgets.mp4" image_src="/projects/wp-content/uploads/2014/04/widgets_screen.gif"] [/_playlist]
Here’s the native video playlist for comparison (without poster image):
from
[playlist type="video" ids="123"]
Happy watching/listening!
Changelog:
0.0.8 (2015-08-02)
– Fixed: Issue #7 by using true/false instead of 1/0 (Props: @X-PRESSIVE)
0.0.7 (2015-03-08)
– Added: New shortcodes [_playlist] and [_track].
– Deprecated: The support for the shortcodes [wpse_playlist] and [wpse_trac] will phase out.
0.0.6 (2015-03-07)
– Added: Support for the autoplay attribute.
– Added: Support for the GitHub Updater. (Probs: @BlaineMoore)
– Added: More info in the README.md file.
– Changed: Replaced filter_var() with wp_validate_boolean(), so we need WordPress 4.0+.
– Changed: Refactoring regarding late escaping.
– Fixed: Some minor adjustments.
0.0.5
– Fixed: added the missing script class to support WordPress 4.0 (Props: @ruLait)
Thanks for your great work!
Hi, this looks great. How would I go about providing a button for users to download the file as well? That would be excellent if this feature could be added. How could I do it?
Hi @Tom
I haven’t looked into download links recently, but played with it some time ago on StackExchange here:
http://wordpress.stackexchange.com/a/142974/26350.
@pggdt thanks for commenting
Glad to hear it’s useful to others as well 😉
This is an awesome way to get the wordpress media player working with external files, ideal for me as I want to use dropbox as CDN.
One issue I found though, the shortcode works in the page when I paste it there but I can’t seen to use it in other customizable areas of my skin. I have text boxes in Thesis 2 which work with shortcodes but this shortcode doesn’t work. Any ideas?
Hi @David, thanks for your comment.
I’m not sure why it isn’t working for you in some areas of your theme.
– Is the playlist missing there?
– Or do you just see the shortcode text?
– Does the native playlist work there?
– Any other errors?
– Can you share the url, where one can see this problem?
The native audio player works fine…
When I try your playlist with external files it doesn’t display a broken shortcode but shows a white rectangle which is empty.
See it working in content here: http://dev.gbcmag.com/playlist/
See it not working next to the header logo here
http://dev.gbcmag.com/
Any ideas?
Thanks for your great work here though and speedy response 🙂
Any ideas? 🙂 Easier to email you?
I’ve updated the plugin on GitHub to version 0.0.3.
Hopefully this issue is resolved.
Hey Birgir, great plugin! Really been trying to work with what wordpress has to offer natively. How hard would it be to get this to work with the native embed code?
Hi Dustin, thanks for your comment.
Can you elaborate on your suggestion.
Not sure what you mean by embed code, do you mean shortcode?
Any ideas are welcome, on how we can improve the plugin 😉
Thanks for the reply. I do mean shortcode.
It would be nice to take the way wordpress handles youtube or vimeo URLs and create a playlist there. Really what I am looking for is the ease of use. Something like that I think should go to the core.
What do you think?
Hi @Dustin
We need to fetch the media file metadata from somewhere. So the question is, where do we store it?
I guess one way would be use some kind of virtual media files in the Media Library, where one could store the metadata (i.e. external link to the media file, title, artist, …) .
Another way would be to use custom post types for this: one for playlists and another one for tracks.
But adding the metadata directly in the shortcode seems to be a straightforward solution.
Do you perhaps have another solutions in mind?
Sorry for the late reply, I don’t get notified of replies 🙁
I think it would be ideal to keep it in the shortcode itself. That seems most intuitive to me.
However coding wise, I don’t really know if that presents a challenge over doing it another way?
We could override the native [playlist] shortcode with our own callback. It should be possible with:
add_shortcode( ‘playlist’, array( $this, ‘playlist_shortcode’ ) );
instead of
add_shortcode( ‘wpse_playlist’, array( $this, ‘playlist_shortcode’ ) );
So instead of [wpse_playlist] we could use [playlist].
But we would have to make sure the playlist shortcode attributes works (like ids).
Maybe it would be a good idea to prefix the new attributes, to avoid any conflict.
Ya, you are probably right. Prefixing would be the more responsibile route.
Is it possible to continue this conversation over email? I keep forgeting to check this thread. Just use the email I have used with these comments.
Hi Birgir. Was so happy to find this plugin. Thanks for writing it!
One problem for me. It’s working great on my site that uses the default 2014 WP Theme, but on a different site, I use the PageLines DMS theme, and the the play/pause button and also the volume icon are disappearing when the plugin is used with the DMS theme.
Any suggestions? I’d love to be able to use it but have my users always seeing the play and volume features.
Thanks again!
Hi @Amy, thanks for your comment.
Do you have this issue for the native [playlist] shortcode as well?
Do you have a link where we can see this problem in action?
Hey, Birgir…
Seems like a great plugin, but I’m getting this error, and the plugin won’t activate:
Parse error: syntax error, unexpected T_STRING in /home/adamover/public_html/wordpress/wp-content/plugins/wpse-playlist-master/wpse-playlist.php on line 11
Any ideas?
Hello JR
What’s your PHP version?
It looks like the error is on the “namespace” part that’s not supported by your PHP version.
From the plugin description:
The code on WPSE should be useable on older PHP versions (ps: you might also consider applying these changes to that code on WPSE)
On my phpMyAdmin, it says: “Version information: 4.1.8, latest stable version: 4.2.6. A newer version of phpMyAdmin is available and you should consider upgrading. The newest version is 4.2.6, released on 2014-07-17.”
But you’re saying the plugin requires 5.3? Why wouldn’t that version be available to me?
Oops…my bad. I just realized that’s the phpMyAdmin version. I’m running PHP Version 5.2.17. How do I go about updating to 5.3.x? Do I have to contact my host for that?
This is usually in the hands of the hosting provider, if you’re on a shared server.
PHP 5.2.17 was released 06 January 2011 (here’s a list of all the PHP releases), so this is not the latest version 😉
But you can try the WPSE snippet as I explained earlier, it should support PHP 5.2.x.
Did you try it?
I’m sorry, Birgir…I didn’t even see that snippet you sent. Many thanks, and I’m sorry to keep taking your time, but I don’t understand. The green parts are already in the class.playlist.php file. Should I be replacing them with what’s in red? I tried that, but I’m still not able to activate the plugin. I’m still getting the same unexpected T_STRING error from line 11 in wpse-playlist.php as mentioned in my first post.
Here’s a single file plugin with a support for PHP 5.2.x (i.e. no namespaces, autoloading or anonymous functions)
https://gist.github.com/birgire/fbd961bc682276830a0d
Hopefully this will work for you?
I wanted to thank you, Birgir, for your individualized help. I ended up having to abandon WPSE for this project, but I may use it in the future. I’ve kept the resources you’ve sent…Thank you! 🙂
You’re welcome @JR, hope you can use it next time 😉
Hi, thanks for your plug-in.
but how use 3 short-code in template?
such as:
thanks in advanced
Hi @raskol
it looks like your example is missing or stripped out if you posted some code.
Thank you so much! this is really helpful
First i wanna to say thanks again for this great plugin, but i have one question, when using with a list of videos the last video when end just go to the first like a loop, is possible to make it stop when the last movie ends? i try to put loop=”false” on the last but not work
@JR thanks
It would be great if you could use the github issue tracker to report it
I will check it out.
ps: Please update to version 0.0.5 for WordPress 4.0 support.
thanks.
Is there a way to auto play stuff? I can’t figure it out. I’ve tried autoplay=on, autoplay=true, auto_play, with and without quotes.
Hi @Brains
The native [playlist] shortcode doesn’t support the autoplay attribute.
Check out the updated version (0.0.6) of the wpse-playlist plugin, it should now support it.
I also added support for the GitHub Updater.
I’ve always wanted to have a podcast on my blog but I wasn’t quite sure what plugin would work. This would make a great tool for bloggers!
Hey – great plugin!!
But looks like the tracknumbers=”no” images=”no” commands are not supported any more…? :o(
Hi Nadja, thanks for your comment.
Please check out Example 1a vs Example 1b here above.
It seems to work there.
How does your playlist code look like?
Thank for great plugin, have a nice day!
Great plugin! I’ve totally rated it with 5 stars!
Now I have a question; It’s possible to play the tracks in the playlist randomly? Like shuffle=”true” random=”true” or something like that. It could be awesome! Thanks in advance, cheers.
@sysknot thanks.
Random ordering is currently not supported, but it’s a good suggestion.
I will try to look into it for the next release.
Thanks for the response; I feel to ask cause I couldn’t find anything about it in the docs nor the code, so yeah, it would be a nice feature.
: ) Keep the good working!
How do I install this ? Which files do I upload to where (the plugins folder under wp-content?) and what folder if any do I put them in etc etc
Apologies, I usually just search for plugins and one-click install them from within wordpress.
Hi Ed
You can e.g. download the plugin zip file from here:
https://github.com/birgire/wpse-playlist/archive/master.zip
Then goto /wp-admin/plugin-install.php?tab=upload
There you just upload the plugin zip file and activate it (just few mouse clicks)
Then you can add the shortcodes into your content.
Best of luck.
Hi Birgir –
An almost instantaneous reply. Many thanks – I hadn’t found that link. I’ve been looking for this function for a long time so your plugin will come in most handy.
Many thanks.
Ed
You’re welcome, glad you can use the plugin.
cheers
Hi Birgir,
I join all the others who are grateful with this plugin. One question: is it possible to play Youtube video tracks?
This example doesn’t work:
[_track caption="Some music" type="video/youtube" src="http://www.youtube.com/watch?v=byyCfAQaMLQ" ]
Which could be the right setting?
Cheers and thanks!
Hi Diplo and thanks for your comment.
It would be cool to be able to use Youtube, but it must be a valid video file path (e.g. mp4).
The Youtube paths like you suggested, are just webpages that consists of html + js + css
But I like this idea, so we will see or maybe you have an idea how to support this?
Best regards
Hi Birgir,
Thanks to you again!
There’s a plugin that has a nice interface for this purpose: http://www.wonderplugin.com and it accepts Youtube videos.
The solution might be in wp-includes/media.php: there is the code to handle Youtube videos, something similar could be done by wp-includes/js/mediaelement/wp-playlist.js. The strange thing is that Mediaelements seems to be ready to handle audio/youtube and video/youtube types…
In the meantime, your plugin Youlist has been very useful to enjoy dynamic playlists 🙂
Kind regards and nice weekend!
Ps. Forgot to mention: apparently wonderplugin manages to find the path to Youtube with the type video/mp4, but I didn’t explore it much…
Hi. I’m completely new to WordPress. How do I install this plug in and get it to work. The only plugins i’m familiar with are those than can be installed through WordPress. Thanks.
Hi Jek Ng
You can fetch the latest zip file from here:
https://github.com/birgire/wpse-playlist/releases
Then you upload that plugin zip file here:
/wp-admin/plugin-install.php?tab=upload
and activate it. That’s it!
Then you can add the shortcode examples to a post/page in the HTML view of the post editor.
Best of luck.
When I tried adding two songs in playlist and it is working fine. When songs are increased the list is broken but rendered HTML is showing in source of page but while box in browser.
Can you get back on this problem please.
Has anybody else had an issue with the video resizing when switching between items in the playlist? It seems to happen when I switch from a local video to a YouTube one.
Hi. I stumbled upon your plugin and it’s exactly what I’m looking for! Being able to customize the track source. The shortcode works in the post’s content area.
But the shortcode doesn’t seem to work outside of it. Eg. when I use it in a template, and insert the shortcode in php using:
echo do_shortcode(‘[_playlist]‘);
Is there a way for it to work ouside of the_content ?
Okay. I figured it out. It had to do with the way you implement do_shortcode if there is an opening and closing. Which there is with [_playlist][/_playlist]
The correct implementation is…
echo do_shortcode(‘[_playlist type="audio"]‘ . ‘[_track src="url_1"]‘ . ‘[_track src="url_2"]‘ . ‘[/_playlist]‘);
Hope that helps somebody save a lot of time.
Thanks for sharing Kenny.
I have installed and used it.
This is a simple, practical, and very good audio-visual plug-in.
Thank you for your great work.
Thanks Tom, glad to hear you liked it.
Hello and thank you!
If we have only 1 file (link) how it can be appear like that: https://ibb.co/gyGbWKk
Hi John
Maybe hide .wp-playlist-tracks div with CSS ?
Hi, thanks for the plugin. How to make it works with audio from google drive?
I try “https://docs.google.com/uc?export=open&id=file_id”, but it doesn’t work. Thanks.
Hi try to make sure the first GET parameter is the id:
[_track title="Test" caption="Testing" meta_artist="Test" src="https://drive.google.com/uc?id=1lPriIg-Frd-OpEWnmbxvivrxNp6HOfh9"]
see
https://github.com/birgire/wpse-playlist/issues/20
Thanks, it works. But it doesn’t work with the file that have size large than 100mb due to the large file notification from google drive.
I try “https://www.googleapis.com/drive/v3/files/file_id/?key=api_key&alt=media” to bypass it, but it doesn’t work. Any suggestions?
This plugin came in like a boon but somehow doesn’t work for me. No idea what am I doing wrong. The plugin seems to work because from view source I see the generated HTML (pasted at https://codeshare.io/kmmPBp) but nothing shows up at https://www.podbharati.com/podcasts-sopaan/ (except a blank black block for the player). Even in the editor interface the short code shows up as is in visual editor. My PHP version is 5.6.40 and WordPress version is 5.7.2. Please help if possible.
Hi Deb, do you get any javascript errors?
Thanks, No JS error. Sorry I had removed that page mentioned in my comment, I created a test page at http://www.podbharati.com/test where everything works fine (the second block is for my podcast). But when I put it on my home page the upper box that has the Podcast details with the yellow thumbnail image vanishes, only the play list below shows. Anyways I settled for another plugin that will show this up based on the Podcast RSS feed and that will also save me the worry to update the page every time I publish a new podcast. This one sadly is too much effort.
Hi, it looks like there are some extra divs within the code (maybe from copy/paste?):
Good to hear you found a solution that suits you.
Thanks for your Good work!