Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            library = new Library();
            playlist = new LibraryPlaylist(library);
            player = new Player<Track>(playlist, new AudioControl<Track>(rt => rt.FilePath));
            player.StatusChanged += player_StatusChanged;

            Settings s;

            try
            {
                s = Settings.LoadSettings("Settings.xml");
            }
            catch (FileNotFoundException e)
            {
                s = new Settings();
            }

            foreach (var path in s.Mediapaths)
            {
                scanner = new ScannerBackgroundWorker(
                new AudioScanner(new MediaParser(), path));

                scanner.FileParsed += scanner_FileParsed;
                scanner.RunAync();
            }

            icon = new TaskbarIcon();
            icon.Icon = Properties.Resources.headset;

            var ctal = ModifierKeys.Control | ModifierKeys.Alt;

            hotkeys = new Hotkeys.HotKeyManager(this);
            hotkeys.AddHotKey(Key.J, ctal, () => { this.Show(); textbox.Focus(); textbox.Text = ""; });
            hotkeys.AddHotKey(Key.Q, ctal, () => this.Close());
            hotkeys.AddHotKey(Key.Insert, ctal, () => player.Play());
            hotkeys.AddHotKey(Key.Home, ctal, () => player.Pause());
            hotkeys.AddHotKey(Key.End, ctal, () => player.Stop());
            hotkeys.AddHotKey(Key.PageUp, ctal, () => playlist.MovePrevious());
            hotkeys.AddHotKey(Key.PageDown, ctal, () => playlist.MoveNext());
            hotkeys.AddHotKey(Key.Right, ctal, () => player.Seek(PlayerSeekOrigin.CurrentForwards, 5000));
            hotkeys.AddHotKey(Key.Left, ctal, () => player.Seek(PlayerSeekOrigin.CurrentBackwards, 5000));

            textbox.Focus();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load settings from an xmlfile into the application
        /// </summary>
        /// <param name="path">Path to the settings file</param>
        /// <returns></returns>
        public static Settings LoadSettings(string path)
        {
            Settings settings = new Settings();

            if (!File.Exists(path))
                throw new FileNotFoundException("No settings.xml found");

            using (FileStream filestream = File.OpenRead(path))
            {
                XmlReaderSettings s = new XmlReaderSettings();

                using (XmlReader reader = XmlReader.Create(filestream, s))
                {
                    reader.ReadToFollowing("media");
                    XmlReader inner = reader.ReadSubtree();
                    settings.AddMediaPaths(ReadMedia(inner));
                }
            }

            return settings;
        }