using System using System Collections Generic using System ComponentMo

 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;
using Newtonsoft.Json;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
DateTime date;
public Form1()
{
InitializeComponent();
}
private void buttonStart_Click(object sender, EventArgs e)
{
//timer
date = DateTime.Now;
Timer timer = new Timer();
timer.Interval = 10;
timer.Tick += new EventHandler(tickTimer);
timer.Start();
//playSong
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();
string json = songResult;
var definition = new { name = "" };
var customer1 = JsonConvert.DeserializeAnonymousType(json, definition);
songName.Text = customer1.name;
}
private void tickTimer(object sender, EventArgs e)
{
long tick = DateTime.Now.Ticks - date.Ticks;
DateTime stopWatch = new DateTime();
stopWatch = stopWatch.AddTicks(tick);
labelTime.Text = "Stream Time: " + String.Format("{0:HH:mm:ss}", stopWatch);
File.WriteAllText("timer.txt", labelTime.Text);
}
}
}