Jump to content
Macrura

Soundmanager2 Audio for Processwire

Recommended Posts

Soundmanager2 Audio for Processwire

Github:

https://github.com/outflux3/TextformatterSoundmanager

Modules Directory:

http://modules.processwire.com/modules/textformatter-soundmanager/

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.

Features

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'.

Edit_Page__Soundmanager2_Audio_Testing_Page_•_localhost.jpg

Instructions

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.

Output

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.

Caveats

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

http://www.schillmania.com/projects/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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Here are some of the custom skins provided for the Bar-UI, and the shortcodes used:

 

Soundmanager2_Bar_UI.jpg

  • Like 4

Share this post


Link to post
Share on other sites

Here are some of the pre-configured cassette ui players:

Soudmanager2_Cassette.jpg

  • Like 2

Share this post


Link to post
Share on other sites

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'

<?php
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

1923846095_Schermafbeelding2018-06-29om14_06_48.thumb.png.4e471c6ecaaf1c7dd8058a2d2f2b7cb5.png1923846095_Schermafbeelding2018-06-29om14_06_48.thumb.png.4e471c6ecaaf1c7dd8058a2d2f2b7cb5.png

 

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);
							    } ?>

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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....

Share this post


Link to post
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

 

Share this post


Link to post
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/';
		</script>

 

Share this post


Link to post
Share on other sites

if the tape doesn't look right you might also have to use this css:

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

the next version will have that in the tape css file..

Share this post


Link to post
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)
https://www.performan.org/carl-cryplant/christmas-music-vol-1/image/ma-r90-mask.png

 

Share this post


Link to post
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;

Share this post


Link to post
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...

Share this post


Link to post
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">

Share this post


Link to post
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".

Share this post


Link to post
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:

2083216618_ScreenShot2018-12-26at11_58_19AM.jpg.d4d98691a1a405e2a0e2135b0986555a.jpg

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;

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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..

Soudmanager2_Cassette___Soundmanager2_Mixed_Types_Testing___My_Great_Site.thumb.jpg.4914641fae6f7fae4a4e5beda59acef6.jpg

Share this post


Link to post
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....

Share this post


Link to post
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,

Share this post


Link to post
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.... 

Share this post


Link to post
Share on other sites

well you're probably not doing delayed output, so that code won't output anything; you'd need to echo if you are doing direct output, like

echo $sm2->player($track, $options);

Share this post


Link to post
Share on other sites

for some reason the 2nd one has the wrong class name, it looks like the classname is added 2x - this is what your api version classname looks like: ma-r90ma-r90 but it should only be ma-r90

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By ukyo
      FieldtypeFontIconPicker
      Supported Icon Libraries
      FontAwesome 4.7.0 Uikit 3.0.34 IonicIcons 2.0.1 Cahangelog
      NOTE: Module store data without prefix, you need to add "prefix" when you want to show your icon on front-end, because some of front-end frameworks using font-awesome with different "prefix".
      Module will search site/modules/**/configs/IconPicker.*.php and site/templates/IconPicker.*.php paths for FieldtypeFontIconPicker config files.
      All config files need to return a PHP ARRAY like examples.
      Example config file : create your own icon set.
      File location is site/configs/IconPicker.example.php
      <?php namespace ProcessWire; /** * IconPicker : Custom Icons */ return [ "name" => "my-custom-icons", "title" => "My Custom Icon Set", "version" => "1.0.0", "styles" => array( wire("config")->urls->templates . "dist/css/my-custom-icons.css" ), "scripts" => array( wire("config")->urls->templates . "dist/js/my-custom-icons.js" ), "categorized" => true, "attributes" => array(), "icons" => array( "brand-icons" => array( "title" => "Brand Icons", "icons" => array( "google", "facebook", "twitter", "instagram" ) ), "flag-icons" => array( "title" => "Flag Icons", "icons" => array( "tr", "gb", "us", "it", "de", "nl", "fr" ) ) ) ]; Example config file : use existing and extend it.
      File location is site/configs/IconPicker.altivebir.php
      <?php namespace ProcessWire; /** * IconPicker : Existing & Extend */ $resource = include wire("config")->paths->siteModules . "FieldtypeFontIconPicker/configs/IconPicker.uikit.php"; $url = wire("config")->urls->templates . "dist"; $resource["scripts"] = array_merge($resource["scripts"], ["{$url}/js/Altivebir.Icon.min.js"]); $resource["icons"]["flag-icons"] = [ "title" => "Flag Icons", "icons" => array("tr", "en", "fr", "us", "it", "de") ]; $resource["icons"]["brand-icons"]["icons"] = array_merge($resource["icons"]["brand-icons"]["icons"], array( "altivebir" )); return $resource; After you add your custom config file, you will see your config file on library select box. Library Title (Location Folder Name).

      If your library categorized and if you have categorized icons set like uikit and fontawesome libraries, you will have category limitation options per icon field or leave it empty for allow all categories (default).

      Example : output
      if ($icon = $page->get("iconField")) { echo "<i class='prefix-{$icon}' />"; } MarkupFontIconPicker Usage
      // MarkupFontIconPicker::render(YourIconField=string, Options=array) echo MarkupFontIconPicker::render($page->YourIconField, [ 'prefix' => 'uk-icon-', // Icon class prefix, if you have different prefix, default is : "fa fa-" 'tag' => 'span', // Icon tag default is : "i" 'class' => 'fa-lg', // If you have extra cutom classes, for example : icons sizes, Array or Sting value 'style' => 'your custom styles if you have' // Array or String Value ]); Theme support

      Search support

      Category support

       
×
×
  • Create New...