How-to for Plugin Developers with Code Examples (2 Viewers)

Was it useful?


  • Total voters
    11

Edalex

Community Plugin Dev
  • Premium Supporter
  • January 3, 2008
    2,955
    1,264
    Saratov
    Home Country
    Russian Federation Russian Federation
    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
    826
    Uppsala
    Home Country
    Sweden Sweden
    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,902
    770
    65
    Arlington Heights, Illinois
    Home Country
    United States of America United States of America
    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
    Home Country
    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,955
    1,264
    Saratov
    Home Country
    Russian Federation Russian Federation
    It appears to be geared towards MP1.
    That's why this section calls MediaPortal 1 Plugins [emoji12]
    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,583
    10,403
    France
    Home Country
    France France
    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
    826
    Uppsala
    Home Country
    Sweden Sweden

    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

    Top Bottom