A little help ? (1 Viewer)

wizard123

Retired Team Member
  • Premium Supporter
  • January 24, 2012
    2,569
    2,680
    Home Country
    United Kingdom United Kingdom
    • Thread starter
    • Moderator
    • #31
    Hi!
    This look like fun, so I tried to do something simple. Adding the dll, and the property that is it use is : #ImagePlugin.Image

    Place the plugin i process plugin folder. Changing picture every 20s. Needs a folder C:\ProgramData\Team MediaPortal\MediaPortal\ImagePlugin

    Pasting source soon.[DOUBLEPOST=1420896086][/DOUBLEPOST]Ther is nothing random at all here, but that should be easy to fix. Place your images in the above mentioned folder ImagePlugin


    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.IO;
    using MediaPortal.GUI.Library;
    
    namespace ImagePlugin
    {
        public class ImagePlugin : IPlugin, ISetupForm
        {
            bool _directoryLoaded = false;
            private List<string> _fileList = new List<string>();
            int _currentImage = 0;
            Timer timer;
    
            // Returns the author of the plugin which is shown in the plugin menu
            public string Author()
            {
                return "Ministerk";
            }
    
            // Indicates whether plugin can be enabled/disabled
            public bool CanEnable()
            {
                return true;
            }
    
            // Indicates if plugin is enabled by default;
            public bool DefaultEnabled()
            {
                return true;
            }
    
            // Returns the description of the plugin is shown in the plugin menu
            public string Description()
            {
                return "Image";
            }
    
            /// <summary>
            /// If the plugin should have it's own button on the main menu of MediaPortal then it
            /// should return true to this method, otherwise if it should not be on home
            /// it should return false
            /// </summary>
            /// <param name="strButtonText">text the button should have</param>
            /// <param name="strButtonImage">image for the button, or empty for default</param>
            /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
            /// <param name="strPictureImage">subpicture for the button or empty for none</param>
            /// <returns>true : plugin needs it's own button on home
            /// false : plugin does not need it's own button on home</returns>
    
            public bool GetHome(out string strButtonText, out string strButtonImage,
              out string strButtonImageFocus, out string strPictureImage)
            {
                strButtonText = PluginName();
                strButtonImage = String.Empty;
                strButtonImageFocus = String.Empty;
                strPictureImage = String.Empty;
                return false;
            }
    
            // indicates if a plugin has it's own setup screen
            public bool HasSetup()
            {
                return false;
            }
    
            // Returns the name of the plugin which is shown in the plugin menu
            public string PluginName()
            {
                return "ImagePlugin";
            }
    
            // show the setup dialog
            public void ShowPlugin()
            {
    
            }
    
            public int GetWindowId()
            { return 0; }
    
            void IPlugin.Start()
            {
                timer = new Timer(new TimerCallback(TimerProc));
                timer.Change(1000, 20000);
            }
    
            void IPlugin.Stop()
            {
                timer.Dispose();
            }
    
            private void TimerProc(object state)
            {
                if (GUIWindowManager.ActiveWindow > 0)
                {
                    LoadDirectory();
                    if(_directoryLoaded && _fileList.Count > 0)
                    {
                            if (_currentImage >= _fileList.Count())
                                _currentImage = 0;
                            GUIPropertyManager.SetProperty("#ImagePlugin.Image", _fileList[_currentImage]);
                            Log.Debug("ImagePlugin change picture");
    
                            _currentImage++;
                    }
                }
            }
    
            private void LoadDirectory()
            {
                if (_directoryLoaded)
                {
                    return;
                }
    
                // Unload any images from our texture bundle first
                _fileList.Clear();
    
                // Folder of images
                try
                {
                    string imageFolder = MediaPortal.Configuration.Config.GetSubFolder(MediaPortal.Configuration.Config.Dir.Config, @"ImagePlugin");
                    // Try to use the provided folder as an absolute path
                    if (!Directory.Exists(imageFolder))
                        return;
                    // Load the image files
                    string[] files = Directory.GetFiles(imageFolder);
                    foreach (string file in files)
                    {
                        if (MediaPortal.Util.Utils.IsPicture(file))
                        {
                            _fileList.Add(file);
                        }
                    }
                    if (_fileList.Count() > 0)
                        _directoryLoaded = true;
                }
                catch (UnauthorizedAccessException)
                {
                    return;
                }
                catch (Exception)
                {
                    return;
                }
            }
    
    
        }
    }
    If i create a project and add your source code i get
    Error 1 The type or namespace name 'Config' does not exist in the namespace 'MediaPortal.Configuration' (are you missing an assembly reference?)
     

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    826
    Uppsala
    Home Country
    Sweden Sweden
    And if you read the you might notice that I shamelessly stole parts of LoadFolder() method from GuiMultiImages, hence some out off place comments... I also did
    this beauty:
    Code:
    if (_fileList.Count() > 0)
        _directoryLoaded = true;
    
    // Can (should??) be simplified to:
    //_directoryLoaded = _fileList.Count() > 0;
    Hence it tries to load images until there is any in the ImagePlugin folder. Remove this statement if you only would to try once. And set _directoryLoaded = true; instead.
     

    wizard123

    Retired Team Member
  • Premium Supporter
  • January 24, 2012
    2,569
    2,680
    Home Country
    United Kingdom United Kingdom
    • Thread starter
    • Moderator
    • #35
    Thanks, it's far more complicated than i was expecting lol. I have your code working as plugin now i just want to make the images random and to fade between :eek: it baffles me with all the public voids and methods etc lol.
     

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    826
    Uppsala
    Home Country
    Sweden Sweden
    With the fading stuff I would add another property and alter the property to set

    Eg:
    Odd _currentImage:
    GUIPropertyManager.SetProperty("#ImagePlugin.Image.1", _fileList[_currentImage]);
    GUIPropertyManager.SetProperty("#ImagePlugin.Image.2", " "); //Note the space!
    Even _currentImage:
    GUIPropertyManager.SetProperty("#ImagePlugin.Image.1", " ");
    GUIPropertyManager.SetProperty("#ImagePlugin.Image.2", _fileList[_currentImage]));

    And add visibility condition:
    for the one showing #ImagePlugin.Image.1:
    <visible>!string.equals(#ImagePlugin.Image.1,)</visible>
    and #ImagePlugin.Image.2:
    <visible>!string.equals(#ImagePlugin.Image.2,)</visible>
     

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    826
    Uppsala
    Home Country
    Sweden Sweden
    I tried it myself, changed to this:
    Code:
    GUIPropertyManager.SetProperty("#ImagePlugin.Image.1", (_currentImage % 2 != 0) ? " " : _fileList[_currentImage]);
    GUIPropertyManager.SetProperty("#ImagePlugin.Image.2", (_currentImage % 2 == 0) ? " " : _fileList[_currentImage]);

    and used this in skin:
    Code:
        <control>
          <description>Imageplugin</description>
          <type>image</type>
          <id>0</id>
          <posX>123</posX>
          <posY>360</posY>
          <width>200</width>
          <height>200</height>
          <texture>#ImagePlugin.Image.1</texture>
          <animation effect="fade" time="300">visible</animation>
          <animation effect="fade" time="300" delay="300">hidden</animation>
          <visible>!string.equals(#ImagePlugin.Image.1,)</visible>
        </control>
        <control>
          <description>Imageplugin</description>
          <type>image</type>
          <id>0</id>
          <posX>123</posX>
          <posY>360</posY>
          <width>200</width>
          <height>200</height>
          <texture>#ImagePlugin.Image.2</texture>
          <animation effect="fade" time="300">visible</animation>
          <animation effect="fade" time="300" delay="300">hidden</animation>
          <visible>!string.equals(#ImagePlugin.Image.2,)</visible>
        </control>

    Worked alright.
     

    wizard123

    Retired Team Member
  • Premium Supporter
  • January 24, 2012
    2,569
    2,680
    Home Country
    United Kingdom United Kingdom
    • Thread starter
    • Moderator
    • #38
    Just tried it, works great thank you :D
    Out of interest what does the c# section do ? i would really love to learn c# but struggling to take it in.
     

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    826
    Uppsala
    Home Country
    Sweden Sweden
    It's an inline if-then-else statement:
    Eg:
    string hello = booleanStatement ? "Hello booleanStatement is true!" : "Hello booleanStatement is false!";

    % is the modulo operator. If you take modulo 2 of an integer, odd numbers evaluates to the value 1 and even numbers the value 0
     

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    826
    Uppsala
    Home Country
    Sweden Sweden
    Hi again. Did get some time to check this random/shuffle stuff also:

    You could do like this:
    Code:
    // This is already in the TimerProc method:
    if (_currentImage >= _fileList.Count())
         _currentImage = 0;
    
    //Add this shuffles the list if _currentImage is 0
    if (_currentImage == 0)
        _fileList = _fileList.OrderBy(x => Guid.NewGuid()).ToList<string>();

    This will shuffle the images every time _currentImage is zero => shuffles the images every time all in the collection has been shown.
     

    Users who are viewing this thread

    Top Bottom