RadioDJ - Free Radio Automation Software Forum

Plugin Tutorial

Re: Plugin Tutorial
« Reply #15 on: November 02, 2020, 03:19:07 AM »
Sorry for the late reply, RFU tried to reach me on Facebook, but I don't really use Facebook anymore.

I wrote the SongPoster plugin for 1.8 back in the day using C# instead of VB.Net (as I'm not familiar with Basic other than QBasic, but that was in the early 90s) and published the sourcecode over here:

I'm not even sure Marius supplies the code for creating plugins for 1.8.2 any more.  :bash:
Was there ever any code or examples? As far as I remember you pretty much had to look at the plugins shipped with RadioDJ and work your way from there.

Thanks to using just plain .NET-Code without any obfuscation/encryption you can get a pretty good idea of what the actual sourcecode (minus variable names and comments) might have looked like.

I pretty much modeled my plugin after the Plugin_PlayingInfo.dll that ships with RadioDJv1.

The basic way to go about this is to import the PluginInterface.dll from the parent folder [make sure it's a relative path!] (as your plugin.dll will live inside the Plugins folder and PluginInterface.dll is inside the main RadioDJ folder)

Then implement the IPlugin interface and implement any of the functions published by it.

Inside showMain and showConfig you can call and show a Windows Forms Form - That's your config screen.

For the SongPoster plugin all you need now is to implement the TrackChanged function and from there look at the song that's being passed to it and make your API calls.

Apparently the PluginInterface has loads more options, you can not only react to things, but also trigger stuff inside RadioDJ by either calling one of the actual classes in PluginInterface or by implementing the Initialize callback and then storing the passed IHost entity somewhere. (i.e.: a class property MyHost)
You can then interact with that IHost entity from all other functions inside your Plugin class as the Initialize callback is the first thing that's called after or inside your class constructor.
My Plugin only uses this to save/load settings in the plugin XML file, but you can access all public methods and variables exposed by the IHost interface as well. (i.e. AddPlaylist and Add2Playlist)

Since I come from web programming and haven't done much Windows Application programming before, this whole callback thing is still crazy to me.
For example, not having to loop your program to keep it running or simply waiting for a callback with the changed track instead of actively checking the currently playing track and then actively waiting until the next track was mind-blowing.

There's no documentation or description about the Plugin Interface, but the DLL ships with RadioDJ (PluginInterface.dll in the main folder) and you can simply import it into your Visual Studio project to inspect and work with all the exposed stuff.
Implement IPlugin with all methods and properties and use the TrackChanged method to perform your web activity whenever the playing track changes.