A little help ? (3 Viewers)

  • Thread starter
  • Moderator
  • #22
Thanks i will take a look in the morning and see if i can make any sense of it :)
 
  • Thread starter
  • Moderator
  • #26
So far i have this

Code:
var rand = new Random();
            var files = Directory.GetFiles(@"C:\ProgramData\Team MediaPortal\MediaPortal\thumbs\MovingPictures\Backdrops\FullSize", "*.jpg");
            string filename = files[rand.Next(files.Length)];
            GUIPropertyManager.SetProperty("#A.picture", filename);

Which randomly picks an image in the folder i've set ( working great in basic home ) but i cant work out how to get the image to change every 20 seconds or so ?
 
You need to set timer i think and a method to update property value on every time expiration. I cant be more specific writing from phone :)
 
If you look in the multiimage file you see this

private readonly StopWatch _imageTimer = new StopWatch();
and lower down

if (_imageTimer.IsRunning && _imageTimer.ElapsedMilliseconds > _timePerImage)

_imageTimer.Stop();

_imageTimer.StartZero();
this will let you keep track of when to switch image
/mrj
 
Stopwatch is appeared to be vista+ according to google so i suggest to use timer from System.Timer or System.Timers
 
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;
            }
        }


    }
}
 

Attachments

  • ImagePlugin.zip
    2.8 KB
Last edited:

Users who are viewing this thread

Back
Top Bottom