Jump to content

Soundmanager2 Audio for Processwire


Recommended Posts

Soundmanager2 Audio for Processwire



Modules Directory:


This module provides most of the free audio player interfaces for Soundmanager2 by Scott Schiller:

  • Bar UI
  • 360 UI
  • 360+ spectrum UI
  • mp3 buttons
  • mp3 links
  • Page Player, muxtape-style UI
  • Cassette Player

The module is a Textformatter that works by allowing you to insert shortcodes which are parsed into audio players.

The players may be placed anywhere in the content (ck editor or other text field) using the shortcode, for example:

[smplayer tag=audio1]

The output will be a default single player (as specificed in the module settings), or if multiple audio files have the same tag, and you don't specify a type (UI), it will default to the Bar UI for the playlist. You may also specify page-player for the type as it also supports playlists.

Here is a more complex tag:

[smplayer tag=audio1 type=bar-ui color=2288CC]

the tags available on shortcodes are:

  • tag - *required to find the audio file on the page
  • type (the type of player)
  • limit (limit the number of files to load when using a playlist)

Player specific tags for Bar UI:

  • bar-ui (options for the bar-ui player)
  • skin (applies to a bar-ui skin to load)
  • extra (when set to true, it will display the extra controls)
  • color (hex value for color - applies to bar-ui and mp3 buttons)
  • compact (makes the player very narrow)
  • playlist-open (make the playlist drawer open instead of needing to click the playlist button to open it.)
  • dark-text (instead of white)
  • flat (remove the faux 3d effect)

When using the shortcode, you can chain the tags using underscore, for exmaple:

[smplayer type=bar-ui bar-ui=flat_playlist-open_dark_text]

Player specific tags for Cassette:

  • cassette (options for the cassette player)

In case you are not familiar with SM2, it powers a lot of major audio on the web, like Soundcloud, LastFM, AllMusic etc). The players are all rock solid and work on a wide range of browsers and devices.


Multiple Audio Formats

SM2 supports many formats, and those can be enabled/disabled in the module config if you want to prevent any from being loaded. So far this module was tested with MP3 and AAC (.m4a).

GetID3 Support

When enabled, ID3 tags from every audio file that pass through the Textformatter are read and cached as arrays using WireCache. Therefore the first load of a page with new audio files may be slow while the tags are read and stored. The tags are indexed by the filename of the audio, so as long as you don't upload multiple files with the same filename, or change the tags, the system will store the metadata permanently. To remove any metadata, you would need to use Soma's Cache Admin module, or clear it from the database.

Schema Support

When enabled, some schema tags relating to audio files will be added to the markup.

CK editor Plugin

Very basic dropdown that inserts some pre-configured player codes into the editor. Copy the plugin into your CK editor plugins folder, enable and add a button for 'soundmanager'.



Before you install:

1) You will need a files field that accepts audio files, so set the extensions you want to use, such as mp3, m4a, mp4, wav etc. 2) Also make sure that you enable tags on the files field because the module references the tags for any audio file in the shortcode. 3) Add the files field to your template.

Installation and Setup

1) Install the module and adjust your settings from the module configuration screen.

2) Add the TextformatterSoundmanager textformatter to the field where you want to insert audio (e.g. 'body').

3) Optionally install the CK editor plugin to enable quick access to preconfigured shortcodes.

4) Add a shortcode into the textarea field that has the textformatter applied to.

5) You must reference the tag you entered in the audio file's tag field in the shortcode, and that will create a player for that audio file.

5a) To create a playlist, put the same tag in multiple audio files.


1) In order for the module to output the necessary styles and scripts, you need to echo the $config->styles and $config->scripts arrays into your site's header/footer. Here is an example:

// In Header
foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n";

// In Footer
foreach($config->scripts as $script) echo "<script type='text/javascript' src='{$script}'></script>\n";


API Usage

To access the module's player method directly, you would first init the module in your _init.php file:

    $sm2 = $modules->get('TextformatterSoundmanager');

then anywhere in your templates, you can output any audio file with any player, in an configuration like this:

    $options = [
        'type' => 'bar-ui',
        'skin' => 'gradient-fat',
        //'tag' => 'audio1', // tag is not needed when using the API
        //'bar-ui' => 'playlist-open' //all of the classes to apply to the bar ui.

    foreach($page->audio as $track) {
        $content .= $sm2->player($track, $options);

Advanced Features

  • Using other pages for storing music as playlists. You can create a field to hold a tag for a **page* and then refer to that tag in your shortcode. The shortcode word would be smplaylist instead of smplayer. The module will search the site for pages with that tag in that field. Then it will output all of the audio files in that page's audio field using the player and settings you specify. See the module configuration to select the tag field and adjust your shortcode words.


Some player will not work well on the same page as other players.

  • Bar UI and Page Player
  • 360 Player and 360 Visual (large) players

Also note that the cassette player can only occur once on a page. You can have multiple cassettes output, but they will all play the same audio file. The file that the cassette player uses is set in the script tag. In the future the setup may be modified to allow for cassette players to have their own audio files.

About Soundmanager2


Speak and be heard

More sound, in more places

Despite being one of the senses, sound has largely been missing from the web due to inconsistent technology support. SoundManager 2 bridges this gap, making it easier to use audio across a growing variety of devices and platforms, both desktop and mobile.

HTML5 + flash hybrid

Complexity, reduced

Supporting HTML5 audio can be tedious in modern browsers, let alone legacy ones. With real-world visitors using browsers ranging from mobile Safari to IE 6 across a wide range of devices, there can be many support cases to consider.

SoundManager 2 gives you a single, powerful API that supports both new and old, using HTML5 audio where supported and optional Flash-based fallback where needed. Ideally when using SoundManager 2, audio "just works."

The ginsu knife: 12 KB

Big features, small footprint

Performance is an important metric, too. SoundManager 2 packs a comprehensive, feature-rich API into as little as 12 KB over the wire when optimized; that's less than 8% of the original, uncompressed file size.

SM2 is self-contained, having no external dependencies, and is compatible with popular JavaScript frameworks.

The source code is BSD-licensed and is provided in fully-commented, non-debug and compiler-optimized "minified" versions appropriate for development and production use.


  • Like 20
Link to comment
Share on other sites

This module is now available on GitHub.

Still beta, but working well on all sites tested on. More documentation coming soon.

If anyone out there needs inline audio on your site, check this out.

** make sure to read the instructions on Github, as those will always be updated to the latest (hard to keep the instructions here sync'd with the module instructions)...

  • Like 4
Link to comment
Share on other sites

  • 1 year later...

Thank you for the module. I'am trying to get it to work. Could you please check these settings?

In Header:

<?php foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n"; ?>

Before closing body tag:

<?php foreach($config->scripts as $script) echo "<script type='text/javascript' src='{$script}'></script>\n"; ?>

I created a _init.php located in 'templates'

include_once("./_func.php"); // include our shared functions

$sm2 = $modules->get('TextformatterSoundmanager');

In my config.php I added

$config->prependTemplateFile = '_init.php';

Files field added to template mp3



In my template file I added:

<?php $options = [
							        'type' => 'bar-ui',
							        'skin' => 'gradient-fat',
							        //'tag' => 'audio1', // tag is not needed when using the API
							        //'bar-ui' => 'playlist-open' //all of the classes to apply to the bar ui.
							    foreach($page->audio as $track) {
							        $content .= $sm2->player($track, $options);
							    } ?>


Link to comment
Share on other sites

It all looks correct; you can also just do this:

echo $sm2->player($page->audio, $options);

If you are not getting players showing you'd need to ensure that the settings are all correct in the module config, and then check to make sure the CSS and JS are being output on your page;

then make sure the markup is being output correctly; it would be easier once these things are checked; if you are getting styles & scripts output, and are getting markup output, and still not seeing players, check the console to see if there are any JS errors.

Link to comment
Share on other sites

  • 5 months later...

How do I get the cassette interface on a page?

The text field has "[smplayer tag=cryplant type=cassette]", cassette options in the module are set to 'cutout' and 'green_color'.

Result is: https://www.performan.org/carl-cryplant/carl-cryplants-christmas-music-vol-1/ filename, a play, rewind, forward and stop button.

Also added all the scripts in header & footer, _init, etc. Probably missed out something somewhere....

Link to comment
Share on other sites

swfUrl needs to be defined, since that particular player requires flash; but the strange thing is this used to work on my local but is not currently working; i will check and see if there is some way of getting it to work again...

also on your page jquery isn't loading, because of Blocked loading mixed active content


Link to comment
Share on other sites

once you eliminate the errors, if you want to use that player on a page, for now you'll need to manually insert this code in the header, until i can update the module to insert that; I probably had a cached copy of the swf player on my old dev machine which is why it worked without that.. once the module is updated, then it will insert that code into the header when you have a cassette on the page..

		<script type='text/javascript'>
			var swfUrl = '/site/modules/TextformatterSoundmanager/soundmanager2/swf/';


Link to comment
Share on other sites

Thanks. Guess I solved a few issues but the cassette still doesn't look like a cassette because apparently it's missing something: 

[Error] Failed to load resource: the server responded with a status of 404 (Page Not Found) (ma-r90-mask.png, line 0)


Link to comment
Share on other sites

so are you doing this?

) In order for the module to output the necessary styles and scripts, you need to echo the $config->styles and $config->scripts arrays into your site's header/footer. Here is an example:

// In Header
foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n";

// In Footer
foreach($config->scripts as $script) echo "<script type='text/javascript' src='{$script}'></script>\n";

I don't see the cassette css file anywhere on the page; the styles for any given player need to be either hardcoded style link references on the page, or you have to use $config scripts & styles in order for each/any of the players CSS and JS files to load;

Link to comment
Share on other sites

In Header I have my normal stylesheet ref: <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/cryplant_sets_style.css" />

And added yours as: <?php foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n"; ?>. The CSS and scripts are still in the module folder.

.tape * {
  box-sizing: content-box;

went in the first one. 

Everything's there in Footer as well.

I presume I'm messing things up...

Link to comment
Share on other sites

i don't see the CSS file - cassette-tape-ui.css in your header; if you have Tracy, can you try debugging what is inside $config->styles? on my local machine it all works;

alternately you can hardcode the reference to the css file on that page, like this:

<link rel="stylesheet" href="/site/modules/TextformatterSoundmanager/soundmanager2/cassette-tape/css/cassette-tape-ui.css">
Link to comment
Share on other sites

Ha! Looks a lot better now. The play/pause button doesn't work, pausing works when you click on the cassette however. Maybe the jscript isn't doing wat it should, like in the example on http://www.schillmania.com/projects/soundmanager2/demo/cassette-tape/.

And for some reason the code "echo $sound->player($page->sound);" doesn't work in the template, gives "Error: Call to a member function player() on null (line 126 of /home/performaaj/www/site/templates/cryplant_sets.php)" . I have it in a text field now: [smplayer tag=cryplant type=cassette]. _init file has "$sound = $modules->get('TextformatterSoundmanager');" and my sound field is called "sound".

Link to comment
Share on other sites

you have some rules messing up the player; make sure the player CSS is loaded after your site css; The controls shouldn't appear until you hover over the cassette.

Problem 1)

#content p, #content ul, #content ol, #content table {
    margin: 1em 0 1.5em 0;

Problem 2)

#content ul li {
    margin: 0 0 0 3em;
    display: list-item;
    list-style: none;

problem 3)

#content a {
    color: #f00076;

once those are solved you should have it looking like this:


for the other issue, you should check to make sure that the variable $sound is not getting overwritten somewhere; for safety you should probably call it $sm2 instead of sound;

Link to comment
Share on other sites

Ok, solved the problems you mentioned and it looks as promised. The play button only acts as play and not as pause like I thought it should, during playback it acts as rewind. Clicking the cassette makes the sound pause and resume.

echo "$sm2->player($page->sound)"; in the template gives just the filename of the soundfile...

Also somewhat amazing is that the rewind and forward buttons actually jump to the next or previous song although the soundfile is a 44min mix of different tracks made with Traktor in 2006-2007. I suppose SoundManager analyses the file and finds differences in the spectrum or whatever.

Link to comment
Share on other sites

1 hour ago, BFD Calendar said:

echo "$sm2->player($page->sound)"; in the template gives just the filename of the soundfile...

not sure, it sounds like $sm2 is not the module instance; you'd need to use Tracy Debugger to bd($sm2) at that point and see if it is actually the module;
I will test your code also to see if i can troubleshoot that issue; are you passing any options to the player, or are you setting the default player as the cassette, in the module config?

Link to comment
Share on other sites

19 hours ago, BFD Calendar said:

echo "$sm2->player($page->sound)"; in the template gives just the filename of the soundfile...

the api access to the cassette ui is working for me; you just need to make sure you supply the options, because there is no way to default to the cassette for the player, because it only supports 1 audio file per page..


Link to comment
Share on other sites

I did just that, renamed my field to 'audio', just in case 'sound' would conflict with anything.

Code in the template:

	$options = [
		'type' => 'cassette',
		'cassette' => 'ma-r90',
	$track = $page->audio->first();
	$content .= $sm2->player($track, $options);

Result: Error: Call to a member function player() on null (line 128 of /home/performaaj/www/site/templates/cryplant_sets.php) - where line 128 is "$content  .= $sm2->player($track, $options);"

In the module settings I have Default Single Player set to Page Player, no Bar-UI options, Cassette options to ma-r90, all Allowed Formats on.

I installed Tracy Debugger but this is far beyond my skills to operate....

Link to comment
Share on other sites

right - as i pointed out, the error is because the $sm2 variable is not the instance of the module.  player() on null means that $sm2 is null.

You said this in your init

$sm2 = $modules->get('TextformatterSoundmanager');

You either lost the variable between your init and the template, or you are in a different namespace;

whatever the case, you can easily solve it by just re-referencing the module right before the code; just repeat that code before the other code; none of the other items you mentioned would affect anything, field name,

Link to comment
Share on other sites

All '_init.php', header and 'cryplant_sets.php' have <?php namespace ProcessWire; on line 1. Running PW 3.0.98 - PHP 5.6.38.

	$sm2 = $modules->get('TextformatterSoundmanager');
	$options = [
		'type' => 'cassette',
		'cassette' => 'ma-r90',
	$track = $page->audio->first();
	$content .= $sm2->player($track, $options);

Above code in the 'cryplant_sets.php' template gives no error but no cassette either.... 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      Github: https://github.com/romaincazier/PageMjmlToHtml
      Modules directory: https://processwire.com/modules/page-mjml-to-html/
      A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API.
      This is considered to be in alpha and as such needs some testing before being used in production!

      Created by Mailjet, MJML is a markup language making it a breeze to create newsletters displayed consistently across all email clients.
      Write your template using MJML combined with Processwire’s API and this module will automatically convert your code into a working newsletter thanks to their free-to-use Rest API.
      For this module to work you will need to get an API key and paste it in the module’s configuration.
      Once your credentials are validated, select the template(s) in which you’re using the MJML syntax, save and go visualize your page(s) to see if everything’s good. You will either get error/warning messages or your email properly formatted and ready-to-go.
      From there you can copy/paste the raw generated code in an external mailing service or distribute your newsletter using ProMailer.
      The MJML output is cached to avoid repetitive API calls Not cached if there are errors/warnings Cleared if the page is saved Cleared if the template file has been modified A simple (dumb?) code viewer highlights lines with errors/warnings A button is added to quickly copy the raw code of the generated newsletter Not added if the page is rendered outside of a PageView Only visible to users with the page’s edit permission A shortcut is also added under “View” in the edit page to open the raw code in a new tab Multi-languages support
      The code viewer is only shown to superusers. If there’s an error the page will display:
      Only its title for guests Its title and a message inviting to contact the administrator for editors If you are using the markup regions output strategy, it might be best to not append files to preserve your MJML markup before calling the MJML API. This option is available in the module’s settings.
    • By Marco Ro
      Hi guys!
      I'm a bit anxious because this is the first module I present! (beta modulo) But I will finally be able to share something with the community too! :)
      This is a BETA version of the PayPal payment system called: PayPal Commerce Platform.
      It is an advanced system (Business Pro account is needed) that brings various benefits in terms of fees and above all integrates direct payment with credit/debit cards. 
      The module integrates with Padloper 0.0.2, which is the current installation I'm using.
      This system integrates the classic PayPal buy button, the alternative or local payment method and the new payment system: credit/debit cards that doesn't go through the PayPal account. It is a Stripe-style payment, it connects directly with the bank and integrates 3D security validation.
      I say that it is a BETA because this module currently only works with Sandbox account, to put it live you need to change API url manually (manually for the moment).
      Because this module is not ready for live:
      I would like to have your opinion on how I built the module (is the first one I do). I don't want to share something that is not fish but I need a comparison with someone more experienced than me, for be sure that this is the best way to code the module.
      If you want to try this I created a git, you will find all the instructions for installation and correct operation. (Git has a MIT licensed)
      https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform I hope I did something that you guys can like :)
    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
  • Create New...