Aug 4, 2021

Create Alexa music player skill with Audioigniter or MP3 Music Player by Sonaar plugins for WordPress

Many musicians have their own music websites with their creations. Like with everything on the Internet, many of them are using WordPress to achieve that. Some of the plugins that can help you with it are Audioigniter or MP3 Music Player by Sonaar.

We have previously created an article which describes how to create an Alexa Audio Player skill. In that example we used the standard WordPress media library for mp3’s to be played. Since Audioigniter and MP3 Music Player by Sonaar use a bit different structure which represent the songs (grouped into albums), we had to create a new context component WP_Query album mp3 source.

To make yourself familiar with the Searchable Player template, please check out the mentioned article here.

Modifying the Searchable Player template

In a few simple steps, you’ll be able to modify the existing Searchable Player to work with either Audioigniter or MP3 Music Player by Sonaar.

First of all, enable convo-wp-plugin-pack in the Configure Package section This will add WP_Query album mp3 source in the Contexts tab of your workflow. Feel free to replace the existing context with the new one WP_Query album mp3 source in the Contexts Container. Modify it to your needs following the examples like in Fetching the Songs While Using Audioigniter or Fetching the Songs While Using MP3 Music Player by Sonar.

And that’s it. This is all you need to do for the modification of the Searchable Player template.

WP_Query Album MP3 Source

First of all, we assume that you are already familiar with Audioigniter or MP3 Music Player by Sonar and you know how to create playlists. This element is very similar to the WP_Query MP3 Source, but there are some differences that have to be considered. In the WP_Query MP3 Source context mp3’s were treated as regular WP Posts, but in case of Audioigniter or MP3 Music Player by Sonaar, the songs are stored in form of playlists.

Examples of fetching the songs for Audioigniter and MP3 Music Player by Sonar are located below.

Fetching the Songs While Using Audioigniter

In this section we are going to use the example which is related to Audioigniter.

Since Audioigniter stores it songs in so called Playlists, in form of post_type => ai_playlist and post_meta_key => _audioigniter_tracks as an array, we have to use WP_Query album mp3 source context to fetch the songs.

Several WP Query arguments should be set to fetch the Audioigniter albums correctly: post_type = ai_playlist and post_status = publish . For now we just have the playlists, but we need the songs of those fetched playlists.

To get the songs of a playlist, we need to populate the Songs of Album and Song of Album fields like this:

  • Songs of Album – ${get_post_meta(post.ID,"_audioigniter_tracks", true)}
  • Song of Album – song_of_album

Songs retrieved from a playlist have a bit different structure than the plain post attachments and you’ll have to manually map them to the corresponding properties.

So, the final context settings looks like this:

  • Song URL – ${song_of_album.track_url}
  • Song Title – ${song_of_album.title}
  • Artist – ${song_of_album.artist}
  • Song Image – ${wp_get_attachment_url(song_of_album.cover_id)}

And that’s it, now we have our songs from Audioigniter.

Fetching the Songs While Using MP3 Music Player by Sonar

In this example you can refer to Audioigniter, since we are still using WP_Query album mp3 source. Although, the configuration will be slightly different by post_type in WP Query arguments, Songs of Album and the structure of fetched songs because the songs are stored in the same manner as in Audioigniter. Songs are also stored in Playlists in form of post_type => album and post_meta_key => alb_tracklist as an array.

The configuration of WP_Query album mp3 source for MP3 Music Player by Sonar might look like this:

  • In WP Query arguments add post_type = album and post_status = publish
  • Songs of Album – ${get_post_meta(post.ID,"alb_tracklist",true)}
  • Final context settings looks like this:
    • Song URL – ${song_of_album.track_mp3}
    • Song Title – ${get_post(song_of_album.track_mp3_id).post_title}
    • Artist – ${wp_get_attachment_metadata(song_of_album.track_mp3_id)["artist"]}
    • Song Image – ${song_of_album.track_image}

And that’s it for this example, now we have our songs from MP3 Music Player by Sonar.

What about the Search Capability?

The search capability will work with playlist titles and you can also add an meta_query to WP_Query Args to retrieve albums that contain part of your search query. This will work just fine in case your playlists are well organized.

This is an example how to prepare an meta_query for the WP_Query Args:


After you have created your meta_query, you can add it in the WP_Query Args of your WP_Query album mp3 source like this: meta_query – ${meta_query}

Conclusion

Now with the new WP_Query album mp3 source context you are able to modify the Searchable Player template to play your playlists or albums created with Audioigniter or MP3 Music Player by Sonaar in a matter of minutes and listen to your creations on your smart speaker or smart display.

Mark Marčec

Mark Marčec