Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Create a new plugin

SilverDimond edited this page Sep 7, 2023 · 3 revisions

Warning
This program is licensed under the GNU General Public License v3.0 which may impose restrictions on the license of the plugins/extensions https://www.gnu.org/licenses/gpl-faq.en.html#GPLAndPlugins

The current guide assumes you have previous knowledge of the usage of c#, dotnet and visual studio. And assumes you have all installed. First create a class library image

Warning SilverAudioPlayer relies on your plugins name to know if its compatible with the current runtime (OS). Please name it according to these following instructions.

If your plugin runs on linux and windows name it by using this SilverAudioPlayer.Any.<CompanyName.>[PluginName]
If your plugin is windows only name it by using this SilverAudioPlayer.Windows.<CompanyName.>[PluginName]
If your plugin is windows 10 only name it by using this SilverAudioPlayer.Windows10.<CompanyName.>[PluginName]
If your plugin is linux only name it by using this SilverAudioPlayer.Linux.<CompanyName.>[PluginName]

Right click Dependancies and click on manage nuget packages
image

In the window that appears search for silveraudioplayer.shared image
click on it and click on install image
image click on ok image Visual studio will ask you to accept the license, by clicking I accept you agree to the terms of the GPL license (READ IT). You can now return to the Class1.cs file visual studio automatically created for you.
image
Rename it to something more appropriate image

Now its time to choose an interface

  • IPlayProvider for implementing new players (most of the time you should just implement INaudioWaveStreamWrapper if a new player isn't needed to play that file)
  • IMetadataProvider for implementing new metadata providers (the things that read metadata from files/streams)
  • IMusicStatusInterface for implementing things that track/control playback (eg. discord rich presence/SMTC/Cd Art Display)
  • IWakeLockProvider for implementing ways to let the OS know NOT to go to sleep
  • IPlayStreamProvider for implementing ways of letting the user add new tracks from an external source (eg. internet radio streams, media servers (jellyfin, dlna, etc.))
    Consider looking through the already implemented modules as a reference (copy the good aspects of them, not the bad ones)
    This tutorial will focus on creating a IPlayStreamProvider module but you may want to create a module of a different type for your usage.
    Implement IPlayStreamProvider by adding : IPlayStreamProvider after its name image

Visual studio already knows what this interface requires so let it do the easy writing part for you
image

Change the modules name by changing

public string Name => throw new NotImplementedException();
public string Description => throw new NotImplementedException();
public WrappedStream? Icon => throw new NotImplementedException();
public Version? Version => throw new NotImplementedException();
public string Licenses => throw new NotImplementedException();
public List<Tuple<Uri, URLType>>? Links => throw new NotImplementedException();
public IPlayStreamProviderListner ProviderListner { set => throw new NotImplementedException(); }
public void ShowGui()
       {
           throw new NotImplementedException();
       }

to

public string Name => "Example Plugin";
public string Description => "An example plugin";
public WrappedStream? Icon => null;
public Version? Version => typeof(ExamplePlugin).Assembly.GetName().Version;
public string Licenses => "ExamplePlugin - GPL-3.0"; //CHANGE THIS TO YOUR LICENSE
 public List<Tuple<Uri, URLType>>? Links => new()
    {
        /*new Tuple<Uri, URLType>(
            new Uri(
                "https://github.com/yourusername/yourrepo"),
            URLType.Code),*/ //Uncomment after filling

    };
        public IPlayStreamProviderListner ProviderListner { set => _ProviderListner=value; }
        private IPlayStreamProviderListner _ProviderListner;

 public void ShowGui()
        {
            //Do something cool
            Process.Start("cmd.exe");
        }

Export your module by adding [Export(typeof(IPlayStreamProvider))] Your module should look like image Try it out by building your project and putting its dll in silveraudioplayer's directory (or its extensions subdirectory), then restart/launch silveraudioplayer. After (re)launching click on the settings button. image Find your plugin image And click its use button image And voilà! Let's try adding a song to the player's queue when the user clicks the Use button

public void ShowGui()
        {
            _ProviderListner.LoadSong(new WrappedHttpStream("https://archive.org/download/canyon_202011/CANYON.MID"));
        }

Recompile your plugin, copy your dll to the SilverAudioPlayer directory (or its extensions subdirectory, you can create), and relaunch silveraudioplayer. It might take a second or so to show but that is one downside of the wrappedhttpstream image And here it is, playing Dont trust me? Click on the blank square reserved for album art image The song metadata will contain your wrappedhttpstream with its url set to the one you provided

Clone this wiki locally