Jump to content

Soundmanager2 Audio for Processwire


Macrura
 Share

Recommended Posts

@protro

You just need to make sure to pass the files array to the player() method, so your code won't work because you don't have audio on the $page.

$page is always the current page; You can reference the other page using $pages->get([pageid]);

You can also make your own array of files by creating a WireArray and then adding your audio files to that and then pass the WireArray to the player() method.

Based on your description, first you have to get the page array for the playlist, $songPages = $pages->get(/path/to/playlist/parent or Page ID)->children;

Then iterate the child pages, adding the audio file from each:

$audioFiles = WireArray new();
foreach($songPages as $songPage) {
   $audioFiles->import($songPage->audio);
   // if a single audio file field, then $audioFiles-add($songPage->audio);
}

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

 

  • Like 1
Link to comment
Share on other sites

Thank you so much @Macrura you set me on the right path. I appreciate you taking the time explaining something this elementary.

Since I am using Rockfrontend with the Latte engine, I had to do some alteration to the syntax, but the playlist/GUI is working now ?

{var $options = ['type' => 'bar-ui', 'skin' => 'gradient-fat',]}
{var $songPages = $pages->get('creative')->children}
{var $empty = new \ProcessWire\WireArray()}
                
{foreach $songPages as $song}
	{var $playlist = $empty->import([$song->audio_file])}
{/foreach}

{$sm2->player($playlist, $options)|noescape}

I had to make sure to call \ProcessWire\WireArray from within this .latte template file, and to add a noescape to the $sm2 object. I was also getting stuck by not wrapping the audio_file File Field in an array, as I was doing this initially, which returned WireArray cannot import non arrays or non-iterable objects

{$playlist->import($song->audio_file)}

Looking forward to playing with this module some more. Many thanks.

Link to comment
Share on other sites

Thanks @Macrura,

Also is there a way to pass in a Page's fields to control to Bar-UI Track Title Template if I didn't want to rely on ID3 tags? What are these tokens {title} referencing ?

 <span itemprop="name">{title}</span>
Link to comment
Share on other sites

Nevermind I realize now that it's pulling from the file field description

// default title source and formatting:
$titleOut = $mp3->description ?: $mp3->name; // default
$titleAtt = $mp3->description ?: $mp3->name; // attribute

 

Link to comment
Share on other sites

23 hours ago, protro said:

Thanks @Macrura,

Also is there a way to pass in a Page's fields to control to Bar-UI Track Title Template if I didn't want to rely on ID3 tags? What are these tokens {title} referencing ?

 <span itemprop="name">{title}</span>

those should be replacing with the corresponding ID3 tag - title, composer, artist, album and track.  So if you're not using ID3, then you'd just use the file description field...

  • Like 1
Link to comment
Share on other sites

  • 11 months later...
1 hour ago, Mailte said:

Is there a way to add a download button in the compact ui?

I don't think there is a native download feature in soundmanager, and nothing in this module that I'm aware of;

I used plyr (https://plyr.io/) recently to have downloadable audio: https://sfcmp.org/media/artist-chats/

There may be a way to modify the output of the bar ui player though and add a download button.

But more recent audio players like plyr are working well for me, and you could implement it using a simple hanna code.

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
 Share

×
×
  • Create New...