private void AudioStationRemote_Load(object sender, EventArgs e)
        {
			config = json.Value.fromString(File.ReadAllText("config.json"));
			audioStation.login(config["user"], config["pass"]);

			volumeSlider = new ToolStripTraceBarItem();
			volumeSlider.tb.TickStyle = TickStyle.None;
			volumeSlider.tb.AutoSize = false;
			volumeSlider.tb.Size = new Size(200, 32);
			volumeSlider.tb.Minimum = 0;
			volumeSlider.tb.Maximum = 100;

			volumeSlider.tb.MouseDown += (o, args) => { mouseDownVolume = true;  };
			volumeSlider.tb.MouseUp += (o, args) => { pingTimer.Stop(); mouseDownVolume = false;  audioStation.setVolume(volumeSlider.tb.Value); pingTimer.Start(); };
			volumeSlider.tb.ValueChanged += (o, args) =>{ pingTimer.Stop(); if (!mouseDownVolume) audioStation.setVolume(volumeSlider.tb.Value); lblVolume.Text = "Volume: " + volumeSlider.tb.Value; pingTimer.Start(); };
			volumeSlider.ToolTipText = "Volume";
			volumeSlider.Alignment = ToolStripItemAlignment.Right;
			toolStrip1.Items.Add(volumeSlider);


			playbackSlider = new ToolStripTraceBarItem();
			playbackSlider.tb.TickStyle = TickStyle.None;
			playbackSlider.tb.AutoSize = false;
			playbackSlider.tb.Size = new Size(500, 32);
			playbackSlider.tb.Minimum = 0;
			playbackSlider.tb.Maximum = 1000;
			playbackSlider.ToolTipText = "Playback";
			toolStrip1.Items.Insert(toolStrip1.Items.Count-2, playbackSlider);

			Hooker.callback += (Keys key) =>
			{
				if (key == Keys.MediaNextTrack)
					audioStation.next();
				else if (key == Keys.MediaPreviousTrack)
					audioStation.prev();
				else if (key == Keys.MediaPlayPause)
				{
					btnPlayPause_Click(null, null);
                }
				

			};

			Task.Run(async () =>
			{
				var rootDir = await audioStation.getDirectory();
                for (int i = 0; i < rootDir.data.items.Count; i++)
				{
                    TreeNode n = new TreeNode(rootDir.data.items[i].title.Value) { Tag = rootDir.data.items[i].id.Value };
					n.Nodes.Add(new TreeNode("...") { Tag = "dummy" });
					Invoke(() => treeView1.Nodes.Add(n));
                }
			});


			Task.Run(async () =>
			{
				var queueData = await audioStation.getplaylist();

				PlayListItem playlistItem = new PlayListItem();
				List<ListViewItem> rows = new List<ListViewItem>();
				queuePlayList = new PlayList(null, null);
				queuePlayList.listview = queue;

				for (int i = 0; i < queueData.data.songs.Count; i++)
				{
					if (i > 0)
					{
						rows.Add(playlistItem.listViewItem());
						queuePlayList.items.Add(playlistItem);
						playlistItem = new PlayListItem();
					}
					playlistItem.Set(queueData.data.songs[i]);


				}
				rows.Add(playlistItem.listViewItem());
				queuePlayList.items.Add(playlistItem);
				Invoke(() =>
				{
					queue.Items.Clear();
					queue.Items.AddRange(rows.ToArray());
					queue.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
				});



			});
			


		}
Example #2
0
        private void AudioStationRemote_Load(object sender, EventArgs e)
        {
            config = json.Value.fromString(File.ReadAllText("config.json"));
            audioStation.login(config["user"], config["pass"]);

            volumeSlider = new ToolStripTraceBarItem();
            volumeSlider.tb.TickStyle = TickStyle.None;
            volumeSlider.tb.AutoSize  = false;
            volumeSlider.tb.Size      = new Size(200, 32);
            volumeSlider.tb.Minimum   = 0;
            volumeSlider.tb.Maximum   = 100;

            volumeSlider.tb.MouseDown    += (o, args) => { mouseDownVolume = true; };
            volumeSlider.tb.MouseUp      += (o, args) => { pingTimer.Stop(); mouseDownVolume = false;  audioStation.setVolume(volumeSlider.tb.Value); pingTimer.Start(); };
            volumeSlider.tb.ValueChanged += (o, args) => { pingTimer.Stop(); if (!mouseDownVolume)
                                                           {
                                                               audioStation.setVolume(volumeSlider.tb.Value);
                                                           }
                                                           lblVolume.Text = "Volume: " + volumeSlider.tb.Value; pingTimer.Start(); };
            volumeSlider.ToolTipText = "Volume";
            volumeSlider.Alignment   = ToolStripItemAlignment.Right;
            toolStrip1.Items.Add(volumeSlider);


            playbackSlider = new ToolStripTraceBarItem();
            playbackSlider.tb.TickStyle = TickStyle.None;
            playbackSlider.tb.AutoSize  = false;
            playbackSlider.tb.Size      = new Size(500, 32);
            playbackSlider.tb.Minimum   = 0;
            playbackSlider.tb.Maximum   = 1000;
            playbackSlider.ToolTipText  = "Playback";
            toolStrip1.Items.Insert(toolStrip1.Items.Count - 2, playbackSlider);

            Hooker.callback += (Keys key) =>
            {
                if (key == Keys.MediaNextTrack)
                {
                    audioStation.next();
                }
                else if (key == Keys.MediaPreviousTrack)
                {
                    audioStation.prev();
                }
                else if (key == Keys.MediaPlayPause)
                {
                    btnPlayPause_Click(null, null);
                }
            };

            Task.Run(async() =>
            {
                var rootDir = await audioStation.getDirectory();
                for (int i = 0; i < rootDir.data.items.Count; i++)
                {
                    TreeNode n = new TreeNode(rootDir.data.items[i].title.Value)
                    {
                        Tag = rootDir.data.items[i].id.Value
                    };
                    n.Nodes.Add(new TreeNode("...")
                    {
                        Tag = "dummy"
                    });
                    Invoke(() => treeView1.Nodes.Add(n));
                }
            });


            Task.Run(async() =>
            {
                var queueData = await audioStation.getplaylist();

                PlayListItem playlistItem = new PlayListItem();
                List <ListViewItem> rows  = new List <ListViewItem>();
                queuePlayList             = new PlayList(null, null);
                queuePlayList.listview    = queue;

                for (int i = 0; i < queueData.data.songs.Count; i++)
                {
                    if (i > 0)
                    {
                        rows.Add(playlistItem.listViewItem());
                        queuePlayList.items.Add(playlistItem);
                        playlistItem = new PlayListItem();
                    }
                    playlistItem.Set(queueData.data.songs[i]);
                }
                rows.Add(playlistItem.listViewItem());
                queuePlayList.items.Add(playlistItem);
                Invoke(() =>
                {
                    queue.Items.Clear();
                    queue.Items.AddRange(rows.ToArray());
                    queue.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                });
            });
        }