Exemplo n.º 1
0
        public async Task PlayVideoAsync(string mediaUrl)
        {
            try {
                var req = WebRequest.CreateHttp(new Uri(_device.Location, $"/input/15985?t=v&u={WebUtility.UrlEncode(mediaUrl)}&k=(null)"));
                req.Method    = "POST";
                req.UserAgent = Program.UserAgent;
                using (var resp = await req.GetResponseAsync())
                    using (var s = resp.GetResponseStream()) { }
            } catch (Exception ex) {
                throw new Exception("Could not send media to Roku.", ex);
            }

            if (ShowControls)
            {
                using (var f = new RokuRemote(_device.Input)) {
                    f.LabelText = $"Currently playing video on {Name}.";
                    f.Text      = Name;
                    f.ShowDialog();
                    await f.LastTask;
                }
            }
        }
Exemplo n.º 2
0
        public async Task PlayAudioAsync(string mediaUrl, string contentType = null)
        {
            try {
                string mediatype;
                switch (contentType)
                {
                case "audio/mpeg":
                    mediatype = "mp3";
                    break;

                case "audio/mp4":
                    mediatype = "m4a";
                    break;

                default:
                    mediatype = mediaUrl.Split('.').Last();
                    break;
                }
                var req = WebRequest.CreateHttp(new Uri(_device.Location, $"/input/15985?t=a&u={WebUtility.UrlEncode(mediaUrl)}&songname=(null)&artistname=(null)&songformat={WebUtility.UrlEncode(mediatype)}&albumarturl=(null)"));
                req.Method    = "POST";
                req.UserAgent = Program.UserAgent;
                using (var resp = await req.GetResponseAsync())
                    using (var s = resp.GetResponseStream()) { }
            } catch (Exception ex) {
                throw new Exception("Could not send media to Roku.", ex);
            }

            if (ShowControls)
            {
                using (var f = new RokuRemote(_device.Input)) {
                    f.LabelText = $"Currently playing video on {Name}.";
                    f.Text      = Name;
                    f.ShowDialog();
                    await f.LastTask;
                }
            }
        }