How-to for Plugin Developers with Code Examples (1 Viewer)

Was it useful?


  • Total voters
    11

Edalex

Community Plugin Dev
  • Premium Supporter
  • January 3, 2008
    2,919
    1,228
    Saratov
    Russian Federation Russian Federation
    Country flag
    Hi guys!
    As you maybe know it's a pain in ... to find how to interact with MediaPortal and get needed data from plugin because of MP code's complexity and lack of comments and documentation sometimes. So what about sharing some useful method which could help new plugin devs to code?
    Let me start from my noob point of view :) :

    How to get Channel Groups from TV Server
    C#:
    using TvDatabase;
    ...
    public static TvBusinessLayer layer = new TvBusinessLayer();
    IList<ChannelGroup> tvGroups = ChannelGroup.ListAll();
    IList<RadioChannelGroup> radioGroups = RadioChannelGroup.ListAll();
    IList<Channel> channels = layer.GetChannelsInGroup(selectedGroup);
    How to check if another plugin is available and enabled:
    C#:
            publicstatic bool IsAssemblyAvailable(string name,Version ver){
                bool result =false;
                Assembly[] assemblies =AppDomain.CurrentDomain.GetAssemblies();
                foreach(Assembly a in assemblies)
                    try
                    {
                        if(a.GetName().Name== name && a.GetName().Version>= ver)
                        {
                            result =true;
                            break;
                        }
                    }
                    catch
                    {
                      
                    }
                if(!result){
                  
                    try{
                        //Assembly assembly = AppDomain.CurrentDomain.Reflection(new AssemblyName(name));
                        Assembly assembly =Assembly.ReflectionOnlyLoad(name);
                        result =true;
                    }
                    catch(Exception e){
                    }
                }
                return result;
            }
            public static bool IsPluginEnabled(string name){
                using (MediaPortal.Profile.Settings xmlreader =newMediaPortal.Profile.MPSettings()){
                    return xmlreader.GetValueAsBool("plugins", name,false);
                }
            }
    Source https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/Helper.cs#701

    How to interact with trakt plugin
    C#:
    using TraktPlugin.TraktAPI;
    using TraktPlugin.TraktAPI.DataStructures;
    ...
                IEnumerable<TraktSearchEpisode> myep = TraktAPI.SearchEpisodes("Scars");
                IEnumerable<TraktMovie> searchmovie = TraktAPI.SearchMovies("Tron");
                IEnumerable<TraktShow> searchshow = TraktAPI.SearchShows("eureka");
                IEnumerable<TraktMovie> recmovies = TraktAPI.GetRecommendedMovies();
                IEnumerable<TraktMovie> tronrelated = TraktAPI.GetRelatedMovies("tt0084827");
                IEnumerable<TraktUserProfile> newfriend = TraktAPI.SearchForFriends("edalex");
    How to use TMDB provider from Moving Pictures:
    C#:
    using MediaPortal.Plugins.MovingPictures.DataProviders.TMDbAPI;
    ...
    MovieSearch mymovie = TheMovieDbAPI.SearchMovies("Tron");
    Get Series List from MP-TVSeries:
    C#:
    using WindowPlugins.GUITVSeries;
    ...
                    List<DBOnlineSeries> myseries = DBOnlineSeries.getAllSeries();
                    foreach (DBOnlineSeries tvshow in myseries)
                    {
                        DBSeries mytv = Helper.getCorrespondingSeries(tvshow[DBOnlineSeries.cID]);
                        if (mytv != null)
                        {
                            string ishidden = mytv[DBSeries.cHidden];
                            if (ishidden != "1")
                            {                         
                            }
                        }
                    }
    How to create own custom GUI Dialog
    1) Choose of existing dialog to modify it. https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/Dialogs/Dialogs
    2) Create your own dialog by overriding one of them
    Examples:
    https://code.google.com/p/mediaport...k/LogoManager/LogoManager/GUIDIalogPreview.cs
    https://code.google.com/p/mediaport...LogoManager/LogoManager/GUICheckListDialog.cs
    https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIPinCodeDialog.cs
    https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIGeneralRating.cs
    https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIUserRating.cs
    https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIPinCode.cs
    3) Create skin files for your new dialog
    Take skin file of Dialog you overrided and modify it for your needs. Change Windowd ID, add new control etc.
    Skin files for standart skins (better start with supporting them) located here:
    https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/MediaPortal.Base/skin/
    4) Now you can use custom dialog just as like as standart one
    Code:
    GUICheckListDialog dlg = (GUICheckListDialog)GUIWindowManager.GetWindow(GUICheckListDialog.ID);
                if (dlg == null)
                     return;
                dlg.Reset();
                dlg.SetHeading(...);
                dlg.Add(...);
                 dlg.Add(...);
                }
                dlg.DoModal(GUIWindowManager.ActiveWindow);
    How to create custom GUI Control (untested)
    1) Create your control's code overridingone of existing controls or GUIControl class itself
    Examples:
    https://github.com/MediaPortal/Medi...portal/WindowPlugins/GUISudoku/CellControl.cs
    https://github.com/MediaPortal/Medi...al/WindowPlugins/GUITetris/MyTetrisControl.cs
    2) Register your custom control in Init:
    C#:
    GUIControlFactory.RegisterControl("cell", typeof (CellControl));
    3) ...

    If you would like to continue my efforts, please, share your code samples!
    Many thanks!
     
    Last edited:

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    825
    Uppsala
    Sweden Sweden
    Country flag
    Great!
    Spent several hours trying to produce a custom user rate dialog with own artwork, finally found my example code in the trakt plugin.
    Sadly the development is on pause right now, but all tips'n'tricks are welcome!
     

    breese

    Retired Team Member
  • Premium Supporter
  • July 11, 2011
    3,903
    769
    61
    Arlington Heights, Illinois
    United States of America United States of America
    Country flag
    This is a fantastic idea!! :D(y)
    Suggestion.... It appears to be geared towards MP1. With all the MP2 development going on, would it be possible to include the same samples for MP2? ;)
    Just might help newbies and current MP1 dev's a little more active into MP2... :whistle:
     

    regeszter

    Retired Team Member
  • Premium Supporter
  • October 29, 2005
    5,335
    4,954
    Hungary Hungary
    How to get the GUI messages in MediaPortal plugin:

    Code:
    public void Start()
    {
      GUIWindowManager.Receivers += new SendMessageHandler(this.OnMessage);
    }
    
    private void OnMessage(GUIMessage message)
    {
      if (message.Message == GUIMessage.MessageType.GUI_MSG_MANUAL_RECORDING_STARTED)
      {
         //your code
      }
    }
    
    public void Stop()
    {
      GUIWindowManager.Receivers -= new SendMessageHandler(this.OnMessage);
    }
    How to get the GUI messages in TV server plugin:

    Code:
    public void Start(IController controller)
    {
      Controller = controller as TvService.TVController;
    
      ITvServerEvent events = GlobalServiceProvider.Instance.Get<ITvServerEvent>();
      if (events != null)
      {
        events.OnTvServerEvent += new TvServerEventHandler(events_OnTvServerEvent);
      }
    }
    
    public void Stop()
    {
      ITvServerEvent events = GlobalServiceProvider.Instance.Get<ITvServerEvent>();
      events.OnTvServerEvent -= new TvServerEventHandler(events_OnTvServerEvent);
    }
    
    private void events_OnTvServerEvent(object sender, EventArgs eventArgs)
    {
      TvServerEventArgs tvEvent = (TvServerEventArgs)eventArgs;
    
      if (eventArgs == null || tvEvent == null)
      {
         return;
      }
    
      if (tvEvent.EventType == TvServerEventType.StartTimeShifting)
      {
        //your code
      }
    }
     

    Edalex

    Community Plugin Dev
  • Premium Supporter
  • January 3, 2008
    2,919
    1,228
    Saratov
    Russian Federation Russian Federation
    Country flag
    It appears to be geared towards MP1.
    That's why this section calls MediaPortal 1 Plugins
    Also Homey asked for "Tale of building plugin" but I dont know if I could do it...
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,430
    10,248
    France
    France France
    Country flag
    Hi :)

    Good Job m8 and usefull critical information too :

    1) Plugins shouldn't do any long lasting work (more than few ms) in plugin startup
    2) Plugins shouldn't do any processing in MP Main thread at all. All work should be dispatched to a worker thread(s). Reason for this is that if you have 10 plugins that are all doing 1 ms work in the main trhead you are already eating 50% of the frame rendering time on 50fps screen updates.
    3) Any network or local HD access is always more than 1 ms so they need worker thread(s) to be used even if plugin startup shouldn't do such.

    Thanks Guys :)
     
    Last edited:

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    825
    Uppsala
    Sweden Sweden
    Country flag
    Either the link is broken, or i really have no permissions to read that .
    Thanks!
    I think the ellipsis ... is missing in the link. If I copy the url and add ... to it it works.

    EDIT: Also there is the old plugin development tips & tricks wiki page: http://wiki.team-mediaportal.com/in...ORTAL_1/18_Contribute/6_Plugins/Tips_&_Tricks

    Maybe add put a "see also link" in both pages?
     
    Last edited:

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    OP Similar threads Forum Replies Date
    P MP2: US user, OTA - can NOT get SchedulesDirect plugin to work on MP1 or MP2 --> how do I get OTA schedule? General 4
    E aktuelle englische Forums Webseite von - Showtime Plugin v3 Plugins & Erweiterungen 2
    mrmojo666 [Tv Server Plugin ]Direct Show Video Control Plugin 0.0.0.1 for Hauppauge PVR cards MediaPortal 1 Plugins 0
    joecrow MultiShortcut Plugin (Uavailable) in DWHD skin General Support 58
    vapourEyes Building TV Plugin General Development (no feature request here!) 49
    Golf4 Nach Windows-Updates läuft TV-Plugin nicht mehr Allgemeines Support- und Diskussionsforum 0
    joecrow How about a Launcher plugin for MP1? MediaPortal 1 6
    D [solved] TVServer Plugin must be missing something. General Development (no feature request here!) 1
    framug Nouveau plugin XmlTvFR pour récupérer le guide télé français Kazer / ZguideTv (WebEPGfr) 11
    emphatic Allow remote control mapping of all plugins Improvement Suggestions 0
    D Where should plugins be located on hard drive? General Support 0
    D how to disengage from one version of a plugin to use another Newcomers Forum 0
    cbr954rr How to disable a pre-configured plugin? General 2
    mrmojo666 [Plugin]Marantz Control Plugin 0.0.0.2 MediaPortal 1 Plugins 2
    mrmojo666 beginner: trying to write a plugin, need help to catch event General Development (no feature request here!) 3
    framug [Rejected] Fix PowerScheduler plugin for MP2 single seat Submit: Code Patches 9
    doskabouter [Question] Stale plugins Developer Discussions 9
    M MP1 stops responding after Starting Plugins General Support 14
    Terra LAVFilter Plugin cannot be updated (MP1.23) MediaPortal 1 Plugins 10
    L Mediaportal 1.21 and Windows 10: user schedules de-activated when powerscheduler plugin is selected General Support 1
    C Can the XmlTv Plugin handle 600+ channels? General 3
    M Online Video Plugin V.2.32 keine Installtion unter MediaPortal 1.22 ? TV / Streaming 3
    emphatic Pictures in the cloud - would a plugin be possible for services like Google Photos MediaPortal 1 Plugins 1
    C where is the Online Videos plugin General Support 1
    S Missing plugin for MP2 Plugin Development 1
    Similar threads

























    Top Bottom