2014-01-07 15:26:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2014-01-10 07:09:14 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
2014-02-01 12:52:33 +00:00
|
|
|
|
using System.IO;
|
2014-01-07 15:26:03 +00:00
|
|
|
|
|
|
|
|
|
namespace SpotifyAPIv1
|
|
|
|
|
{
|
2014-02-01 12:52:33 +00:00
|
|
|
|
public class SpotifyMusicHandler
|
2014-01-07 15:26:03 +00:00
|
|
|
|
{
|
2014-01-10 07:09:14 +00:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
2014-02-01 12:52:33 +00:00
|
|
|
|
[DllImport("nircmd.dll")]
|
|
|
|
|
public static extern bool DoNirCmd(String NirCmdStr);
|
2014-01-10 07:09:14 +00:00
|
|
|
|
|
2014-01-08 22:22:54 +00:00
|
|
|
|
RemoteHandler rh;
|
|
|
|
|
StatusResponse sr;
|
2014-01-10 07:09:14 +00:00
|
|
|
|
const byte VK_MEDIA_NEXT_TRACK = 0xb0;
|
|
|
|
|
const byte VK_MEDIA_PREV_TRACK = 0xb1;
|
|
|
|
|
|
2014-02-01 12:52:33 +00:00
|
|
|
|
public SpotifyMusicHandler()
|
2014-01-07 15:26:03 +00:00
|
|
|
|
{
|
2014-01-08 22:22:54 +00:00
|
|
|
|
rh = RemoteHandler.GetInstance();
|
|
|
|
|
}
|
2014-01-10 07:09:14 +00:00
|
|
|
|
void PressKey(byte keyCode)
|
|
|
|
|
{
|
|
|
|
|
const int KEYEVENTF_EXTENDEDKEY = 0x1;
|
|
|
|
|
const int KEYEVENTF_KEYUP = 0x2;
|
|
|
|
|
keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
|
|
|
|
|
keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
|
|
|
|
|
}
|
2014-01-08 22:22:54 +00:00
|
|
|
|
public Boolean IsPlaying()
|
|
|
|
|
{
|
|
|
|
|
return sr.playing;
|
|
|
|
|
}
|
2014-02-01 12:52:33 +00:00
|
|
|
|
public double GetVolume()
|
|
|
|
|
{
|
|
|
|
|
return sr.volume;
|
|
|
|
|
}
|
|
|
|
|
public void PlayURL(String url)
|
|
|
|
|
{
|
|
|
|
|
rh.SendPlayRequest(url);
|
|
|
|
|
}
|
|
|
|
|
public Boolean IsAdRunning()
|
|
|
|
|
{
|
|
|
|
|
return !sr.next_enabled && !sr.prev_enabled;
|
|
|
|
|
}
|
2014-01-08 22:22:54 +00:00
|
|
|
|
public Track GetCurrentTrack()
|
|
|
|
|
{
|
|
|
|
|
return sr.track;
|
2014-01-07 15:26:03 +00:00
|
|
|
|
}
|
2014-01-10 07:09:14 +00:00
|
|
|
|
public void Skip()
|
|
|
|
|
{
|
|
|
|
|
PressKey(VK_MEDIA_NEXT_TRACK);
|
|
|
|
|
}
|
|
|
|
|
public double GetTrackPosition()
|
|
|
|
|
{
|
|
|
|
|
return sr.playing_position;
|
|
|
|
|
}
|
2014-02-01 12:52:33 +00:00
|
|
|
|
public void Mute()
|
|
|
|
|
{
|
|
|
|
|
if(File.Exists("nircmd.dll"))
|
|
|
|
|
DoNirCmd("muteappvolume spotify.exe 1");
|
|
|
|
|
}
|
|
|
|
|
public void UnMute()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists("nircmd.dll"))
|
|
|
|
|
DoNirCmd("muteappvolume spotify.exe 0");
|
|
|
|
|
}
|
2014-01-10 07:09:14 +00:00
|
|
|
|
public void Previous()
|
|
|
|
|
{
|
|
|
|
|
PressKey(VK_MEDIA_PREV_TRACK);
|
|
|
|
|
}
|
|
|
|
|
public void Pause()
|
|
|
|
|
{
|
|
|
|
|
rh.SendPauseRequest();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void Play()
|
|
|
|
|
{
|
|
|
|
|
rh.SendPlayRequest();
|
|
|
|
|
}
|
2014-01-08 22:22:54 +00:00
|
|
|
|
public StatusResponse GetStatusResponse()
|
2014-01-07 15:26:03 +00:00
|
|
|
|
{
|
2014-01-08 22:22:54 +00:00
|
|
|
|
return sr;
|
|
|
|
|
}
|
2014-01-07 15:26:03 +00:00
|
|
|
|
|
2014-01-08 22:22:54 +00:00
|
|
|
|
internal void Update(StatusResponse sr)
|
|
|
|
|
{
|
|
|
|
|
this.sr = sr;
|
2014-01-07 15:26:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|