• Welcome to RadioDJ - Free Radio Automation Software Forum. Please log in or sign up.

Getting started writing a plugin

Started by beclawat, August 26, 2015, 04:04:15 AM

beclawat

I am looking to write a plugin that will fill the playlist as close as possible to exactly fit either a time or an event. First, my main problem is how to get a plugin to load. I am referencing PluginInterface.dll and System.Windows.Forms.dll. I have the Class and, Class file and Namespace all with the same name. Is there anything else I need to do to get the plugin to load.

AndyDeGroo

Hi,

First, your main plugin class must implement IPlugin interface.

Some actual plugin source code was provided by SnowHow in this post. That may help.

Also, get ILSpy.

beclawat

I am of course implementing IPlugin. DOH Should have mentioned that in the first place.

AndyDeGroo

One thing that may not be obvious - assembly has to target .NET 2.0.
I know, it sucks if you want to use all the shiny new toys available in .NET 4.x but, hey, 2.0 assemblies can (in theory) run under Windows 98. :D

beclawat

I had to target 3.5 as PluginInterface.dll references an assembly that only comes with 3.5. That got it to load.

AndyDeGroo

Ah, yes. .NET 3.5 it is. Sorry for misleading.

beclawat

Well I have code firing on song/track change which is a good start. Now to figure out how best to do what I want to do. I am sure there are lots of people on these forums that have ideas on how to fill out to a time. I should probably figure out actions and be event driven rather than trying to sort out filling time on track change (I should be able to figure that out for now). Thank you for getting my plugin loading and firing however.

AndyDeGroo

Well, there are not many on here who could help with plugin development. AFAIK, Marius, SnowHow and myself.

I'm not sure if hooking on track change will work, because TrackChanged() is called after current track starts to play and after playlist has changed, which may result in new tracks added to playlist before you can react. You should also note that this method is called from a separate thread.
Instead, your plugin could use PlaylistChanged(). Despite its name the it is called before playlist is changed. Your plugin could modify the playlist even before Plugin_Playlist reflects changes in UI if your plugin is loaded before Plugin_Playlist, which is determined by *.dll file order in Plugins directory.

Since RadioDJ does not keep track of total playlist duration, your plugin will have to iterate over playlist items and sum durations to determine if tracks fit in the hour.
If the conditions are met, stop Auto DJ and do your magic.
That could slow down Auto DJ but I can't tell for sure without testing.

beclawat

#8
What I meant by there being lots of users with ideas was that there will be lots of people with ideas as to if I should try to clip a few seconds of up coming tracks to fit an extra in or insert jingles and idents or an instrumental loop or a mix of those previously mentioned. I will have a look at PlayListChanged as well.

Does PlayListChanged fire each time a new track is added or removed from the playlist? That is what I seem to be noticing in my testing. If that is the case then my job requires a little bit less complexity as I don't have to loop over the playlist to calculate the total time.

AndyDeGroo

IMO, you should focus on basic functionality first and test the best approach. More features, like choosing between clipping music/adding jingles/whatnot, can be added later.
Creating a poll would be a good way to understand what folks want and which direction to go.

beclawat

I am trying to figure out how best to implement basic functionality first :). So does PlayList changed fire when any change is made to the playlist?

Marius

Yes, whenever a file is inserted/deleted from the playlist, it is called PlaylistChanged().
DOWNLOADS PAGE

HOW TO FIX RADIODJ DATABASE
----------------
Please don't PM me for support requests. Use the forums instead.

beclawat

I am looking at using Event Actions as I can see doing it automatically every hour is not what I want and probably what many don't want. I have the following code set up:
double mainPlayListLength = 0;
List<rdjInterface.Events.EventAction> myEvents = new List<Events.EventAction>();
bool IPlugin.HasActions
        {
            get
            {
                return true;
            }
        }
List<Events.EventAction> IPlugin.AvailableActions()
        {
            return myEvents;
        }
void IPlugin.Initialize(IHost Host)
        {
            host = Host;

            myEvents.Add(new Events.EventAction("TimeFiller", "FillTime", PluginActionTypes.Other, "Fit playlist to the hour."));
        }
        bool IPlugin.RunAction(string ActionName, string[] args)
        {

            DateTime newsStart = DateTime.Parse(DateTime.Now.AddHours(1).Hour + ":00:24");

            if (ActionName.Equals("FillTime"))
            {
                String output = "";
                MessageBox.Show("Test");
                foreach (TrackPlayer tp in host.MainPlaylist)
                {
                   
                    mainPlayListLength += tp.TrackData.Duration;
                    output += "Title: " + tp.TrackData.Title + Environment.NewLine + "Duration: " + tp.TrackData.Duration + Environment.NewLine + "TotalPlayListTime: " + mainPlayListLength + Environment.NewLine + "Time playlist will end: " + DateTime.Now.AddSeconds(mainPlayListLength).ToShortTimeString() + Environment.NewLine;
                    System.IO.File.AppendAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\RDJPlugin.log", output);
                    MessageBox.Show(output);
                }
                MessageBox.Show(mainPlayListLength.ToString());
            }
           
            return true;
        }

If I set up an event, I can add the action FillTime to the event, however none of the MessageBoxes appear nor does the output file I expect.

Anny advice is appreciated.

Marius

When you are adding the new event action, you need to make sure that the plugin name is correct, otherwise the plugin won't be found when the action is called.

You can use reflection to avoid this problem:
myEvents.Add(new Events.EventAction(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name(), "FillTime", PluginActionTypes.Other, "Fit playlist to the hour."));
DOWNLOADS PAGE

HOW TO FIX RADIODJ DATABASE
----------------
Please don't PM me for support requests. Use the forums instead.

Major Armstrong

This would be an excellent plug-in!  Best of luck in your work.
:cool:
Major Edwin H. Armstrong
(1890 - 1954)
Inventor of FM Radio