-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
97 lines (80 loc) · 3.8 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Navigation;
using Microsoft.WindowsAPICodePack.Taskbar;
using mshtml;
namespace Grooveshark
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
private Player m_player;
private bool m_buttonsAdded;
public MainWindow()
{
InitializeComponent();
}
private void BrowserLoadCompleted(object sender, NavigationEventArgs e)
{
var document = browser.Document as IHTMLDocument2;
if (document == null) return;
m_player = new Player(document);
CreateToolbarButtons();
}
private void CreateToolbarButtons()
{
if (m_buttonsAdded) return;
var favorite = new ThumbnailToolbarButton(Properties.Resources.Favorite, "Add to Favorites");
favorite.Click += (sender, args) => m_player.FavoriteSong();
var next = new ThumbnailToolbarButton(Properties.Resources.Next, "Next Song");
next.Click += (sender, args) => m_player.NextSong();
var previous = new ThumbnailToolbarButton(Properties.Resources.Previous, "Previous Song");
previous.Click += (sender, args) => m_player.PreviousSong();
var playback = new ThumbnailToolbarButton(Properties.Resources.Play, "Play");
playback.Click += (sender, args) => m_player.TogglePlayback();
m_player.PlayerStatusChanged += (sender, args) =>
{
if (args.CurrentStatus == PlayerStatus.Playing ||
args.CurrentStatus == PlayerStatus.Loading)
{
playback.Icon = Properties.Resources.Pause;
playback.Tooltip = "Pause";
}
else
{
playback.Icon = Properties.Resources.Play;
playback.Tooltip = "Play";
}
};
m_player.SongChanged += (sender, args) =>
{
if (args.CurrentSong == null)
{
Title = "Grooveshark";
return;
}
Title = String.Format("{0} - {1} - {2}", args.CurrentSong.Name,
args.CurrentSong.ArtistName,
args.CurrentSong.AlbumName);
};
if (TaskbarManager.IsPlatformSupported)
TaskbarManager.Instance.ThumbnailToolbars.AddButtons(
new WindowInteropHelper(Application.Current.MainWindow).Handle,
previous,
playback,
favorite,
next);
m_buttonsAdded = true;
}
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
WindowState = WindowState.Minimized;
base.OnClosed(e);
}
}
}