public Task <KodiPlayerInfo> Volume(int volume = -1) { return(Task.Run(() => { try { if (volume >= 0) { volume = Math.Max(0, Math.Min(100, volume)); var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Application.SetVolume", Params = new KodiJSON.Kodi_Params { Volume = volume } }; var raw = sendJson(jsonrpc); if (raw != null) { var obj = Newtonsoft.Json.Linq.JObject.Parse(raw); PlayerInfo.Volume = obj.Value <int>("result"); } } else { _properties(); } } catch { } return PlayerInfo; })); }
public Task <KodiPlayerInfo> Stop(KodiJSON pl = null) { return(Task.Run(() => { try { if (PlayerID != null) { var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Player.Stop", Params = new KodiJSON.Kodi_Params() { PlayerID = PlayerID, } }; var raw = sendJson(jsonrpc); PlayerInfo.Status = KodiPlayerStatus.Stopped; } } catch { } return PlayerInfo; })); }
public Task <KodiPlayerInfo> Pause() { return(Task.Run(() => { if (this.PlayerID != null) { var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Player.PlayPause", Params = new KodiJSON.Kodi_Params() { PlayerID = this.PlayerID, } }; var raw = sendJson(jsonrpc); try { var obj = Newtonsoft.Json.Linq.JObject.Parse(raw); var speed = obj.Last.Last.Value <int>("speed"); PlayerInfo.Status = (speed == 0 ? KodiPlayerStatus.Pause : KodiPlayerStatus.Playing); return PlayerInfo; } catch { } } PlayerInfo.Status = KodiPlayerStatus.Stopped; return PlayerInfo; })); }
public Task <bool> Input(KodiInput input) { return(Task.Run(() => { try { var method = ((input == KodiInput.Fullscreen) ? "GUI.Set" : "Input.") + Enum.GetName(typeof(KodiInput), input); var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = method, Params = (input == KodiInput.Fullscreen) ? new KodiJSON.Kodi_Params { Fullscreen = true } : null }; var raw = sendJson(jsonrpc); var json = Newtonsoft.Json.Linq.JObject.Parse(raw); return (json["result"].Equals("OK")); } catch { } return false; })); //var obj = Newtonsoft.Json.Linq.JObject.Parse(raw); }
private KodiPlayerInfo _currentItem() { var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Player.GetItem", Params = new KodiJSON.Kodi_Params() { PlayerID = PlayerInfo.PlayerID, Properties = new List <string>() { "title", "album", "artist", "season", "episode", "duration", "showtitle", "tvshowid", "thumbnail", "file", "fanart", "streamdetails" } } }; var raw = sendJson(jsonrpc); try { var json = Newtonsoft.Json.Linq.JToken.Parse(raw); json = json["result"]["item"]; var file = json.Value <string>("file"); var title = json.Value <string>("label"); if (string.IsNullOrEmpty(title)) { title = json.Value <string>("title"); } PlayerInfo.FileName = file; PlayerInfo.Title = title; var thumb = json.Value <string>("thumbnail"); if (!string.IsNullOrEmpty(thumb)) { thumb = System.Web.HttpUtility.UrlDecode(thumb); thumb = thumb.Replace("image://", "").Trim('/'); } PlayerInfo.Thumbnail = thumb; } catch { } return(PlayerInfo); }
public Task <KodiPlayerInfo> Play(string url) { return(Task.Run(async() => { try { if (!url.StartsWith("http") && File.Exists(url)) { url = System.Web.HttpUtility.UrlEncode(url); url = "http://" + HTTP_Stream_Server.GetLocalIPAddress() + ":" + StreamPort + "/" + url; } var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Player.Open", Params = new KodiJSON.Kodi_Params() { Properties = null, PlayerID = null, Item = new KodiJSON.Kodi_Item { File = url } } }; var raw = sendJson(jsonrpc); var obj = Newtonsoft.Json.Linq.JObject.Parse(raw); if (obj.Value <string>("result").Equals("OK")) { return await GetProperties(); } else { PlayerInfo.Status = KodiPlayerStatus.Stopped; return PlayerInfo; } } catch (Exception x) { System.Windows.Forms.MessageBox.Show(x.ToString()); } PlayerInfo.Status = KodiPlayerStatus.Error; return PlayerInfo; })); }
private KodiPlayerInfo _position() { try { if (PlayerID != null) { var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Player.GetProperties", Params = new KodiJSON.Kodi_Params() { PlayerID = PlayerID, Properties = new List <string>() { "percentage", "totaltime", "time" } } }; var raw = sendJson(jsonrpc); var pi = JsonConvert.DeserializeObject <KodiPlayerInfo>(raw); PlayerInfo.PositionInfo = pi.PositionInfo; PlayerInfo.Status = (PlayerInfo.Duration.Ticks > 0) ? KodiPlayerStatus.Playing : KodiPlayerStatus.Stopped; if (PlayerInfo.Status > KodiPlayerStatus.Stopped) { _currentItem(); } } else { PlayerInfo.Status = KodiPlayerStatus.Stopped; } } catch { } return(PlayerInfo); }
private KodiPlayerInfo _properties() { var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Application.GetProperties", Params = new KodiJSON.Kodi_Params() { Properties = new List <string>() { "muted", "volume" } } }; var raw = sendJson(jsonrpc); if (raw != null) { try { var json = Newtonsoft.Json.Linq.JToken.Parse(raw); json = json["result"]; var muted = json.Value <bool>("muted"); var volume = json.Value <int>("volume"); PlayerInfo.Muted = muted; PlayerInfo.Volume = volume; if (PlayerInfo.Status == KodiPlayerStatus.Error) { PlayerInfo.Status = KodiPlayerStatus.Stopped; } } catch { PlayerInfo.Status = KodiPlayerStatus.Error; } } else { PlayerInfo.Status = KodiPlayerStatus.Error; } return(PlayerInfo); }
private int?_playerID() { try { var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Player.GetActivePlayers", Params = null }; var raw = sendJson(jsonrpc); var res = JsonConvert.DeserializeObject <KodiJSON>(raw); if (res.Status != null && res.Status.Length > 0) { PlayerInfo.PlayerID = res.Status[0].PlayerID; return(res.Status[0].PlayerID); } } catch { } return(PlayerInfo.PlayerID = null); }
public Task <KodiPlayerInfo> Mute() { return(Task.Run(() => { var jsonrpc = new KodiJSON() { Id = 1, Jsonrpc = "2.0", Method = "Application.SetMute", Params = new KodiJSON.Kodi_Params { Mute = !PlayerInfo.Muted } }; var raw = sendJson(jsonrpc); try { var obj = Newtonsoft.Json.Linq.JObject.Parse(raw); var muted = obj.Value <bool>("result"); PlayerInfo.Muted = muted; } catch { } return PlayerInfo; })); }