private void Setup()
        {
            if (IsPopupVideo)
            {
                if (_videoWindow == null)
                {
                    _videoWindow = transform.GetComponentInChildren <VideoWindow>();
                }
                if (_player == null)
                {
                    _player = FindObjectOfType <VideoPlayerView>();
                }
                _player.OnStop += Reset;
                _player.OnEnd  += Reset;

                _videoWindow.Hide();
            }

            Reset();

            SetName(Names);
        }
Exemplo n.º 2
0
        public MediaPlugin()
        {
            try
            {
                var bot = VA.Components.Get <SimlBot>();
                MusicControl = new MusicControl();
                VideoWindow  = new VideoWindow();

                VideoWindow.Closing += (sender, args) =>
                {
                    try
                    {
                        args.Cancel = true;
                        VideoWindow.Hide();
                        VideoWindow.Player.Stop();
                    }
                    catch (Exception exception)
                    {
                        VA.Logger.Error(exception);
                    }
                };

                VA.Loaded += (sender, args) =>
                {
                    try
                    {
                        var dispatcher = VA.Components.Get <Dispatcher>();
                        MusicControl.Player.Indexer.IndexingCompleted += (sender1, args1) =>
                        {
                            dispatcher.Invoke(() =>
                            {
                                bot.Trigger("Music-Directory-Indexed");
                            });
                        };

                        VideoWindow.Player.Indexer.IndexingCompleted += (sender1, args1) =>
                        {
                            dispatcher.Invoke(() =>
                            {
                                bot.Trigger("Video-Directory-Indexed");
                            });
                        };
                    }
                    catch (Exception exception)
                    {
                        VA.Logger.Error(exception);
                    }
                };

                var musicDirectoryVariable = Settings["Music-Directory"];
                var videoDirectoryVariable = Settings["Video-Directory"];

                if (string.IsNullOrEmpty(musicDirectoryVariable.Value))
                {
                    var defaultMusicDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonMusic);;
                    musicDirectoryVariable.Value = defaultMusicDirectory;
                    MusicControl.Player.Indexer.ClearCache();
                }

                if (string.IsNullOrEmpty(videoDirectoryVariable.Value))
                {
                    var defaultVideoDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonVideos);
                    videoDirectoryVariable.Value = defaultVideoDirectory;
                    VideoWindow.Player.Indexer.ClearCache();
                }

                if (!string.IsNullOrEmpty(musicDirectoryVariable.Value))
                {
                    MusicControl.Player.Indexer.StartIndexing(musicDirectoryVariable.Value);
                }

                if (!string.IsNullOrEmpty(videoDirectoryVariable.Value))
                {
                    VideoWindow.Player.Indexer.StartIndexing(videoDirectoryVariable.Value);
                }

                //TopMost because Song player should stay on the top until closed.
                MusicPlayerDisplayItem = new DisplayItem(MusicControl)
                {
                    TopMost = true
                };
                bot.Adapters.Add(new MusicAdapter(this));
                bot.Sets.Add(new SongGenreSet(this));
                bot.Sets.Add(new SongTitleSet(this));
                bot.Sets.Add(new SongArtistSet(this));
                bot.Sets.Add(new SongAlbumSet(this));
                bot.Adapters.Add(new VideoAdapter(this));
                bot.Sets.Add(new VideoTitleSet(this));
            }
            catch (Exception exception)
            {
                VA.Logger.Error(exception);
            }
        }