using System using System IO using System Net using System Text using

 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
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using JsonClasses;
using Newtonsoft.Json;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
DateTime date;
public Form1()
{
InitializeComponent();
}
private void start_Click(object sender, EventArgs e)
{
date = DateTime.Now;
Timer timer = new Timer();
timer.Interval = 10;
timer.Tick += new EventHandler(tickTimer);
if (start.Text == "Stop")
{
timer.Stop();
label2.Text = "STOP";
}
else
{
timer.Start();
label2.Text = "Start";
}
getSong();
}
private void tickTimer(object sender, EventArgs e)
{
long tick = DateTime.Now.Ticks - date.Ticks;
DateTime stopWatch = new DateTime();
stopWatch = stopWatch.AddTicks(tick);
streamTime.Text = "Stream Time: " + String.Format("{0:HH:mm:ss}", stopWatch);
File.WriteAllText("timer.txt", streamTime.Text);
start.Text = "Stop";
}
private void getSong()
{
HttpWebRequest songRequest = (HttpWebRequest)WebRequest.Create("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=dockgg&api_key=e28039161acc777b14cfb09eb41ef896&limit=1&format=json");
HttpWebResponse songResponse = (HttpWebResponse)songRequest.GetResponse();
string songResult = new StreamReader(songResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd();
songResult = songResult.Replace("{\"#", "{\"");
songResult = songResult.Replace("@", "");
if (songResult.IndexOf("nowplaying") != -1)
{
var result = JsonConvert.DeserializeObject<RootObject>(songResult);
songName.Text = "Song: " + result.recenttracks.track[0].artist.text + " - " + result.recenttracks.track[0].name;
}
else
{
songName.Text = "Song: Doesn' t play";
}
}
}
}