Exemple #1
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            Loaded   += GeneralSettingsPage_Loaded;
            Unloaded += GeneralSettingsPage_Unloaded;

            SelectMixingEncoding.Options = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "None", Value = "None"
                },
                new SelectListItem {
                    Text = "Dolby", Value = "Dolby"
                },
                new SelectListItem {
                    Text = "Dolby Pro-Logic II", Value = "DPLII"
                }
            };

            SelectMixingLayout.Options = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Stereo", Value = "Stereo"
                },
                new SelectListItem {
                    Text = "Quadraphonic", Value = "Quadraphonic"
                },
                new SelectListItem {
                    Text = "5.1", Value = "FiveDotOne"
                },
                new SelectListItem {
                    Text = "6.1", Value = "SixDotOne"
                },
                new SelectListItem {
                    Text = "7.1", Value = "SevenDotOne"
                }
            };

            SelectMixingSetting.Options = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Untouched Stereo", Value = "1"
                },
                new SelectListItem {
                    Text = "Normalize Matrix", Value = "2"
                },
                new SelectListItem {
                    Text = "Clip Protection", Value = "4"
                }
            };

            SelectAudioDevice.Options = new List <SelectListItem>();
            Dictionary <string, string> audioDevices = AudioConfigurationUtils.GetAudioDevices();

            foreach (string bsOption in audioDevices.Keys)
            {
                SelectAudioDevice.Options.Add(new SelectListItem {
                    Text = bsOption, Value = audioDevices[bsOption]
                });
            }

            SelectSpeakerLayout.Options = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Stereo", Value = "Stereo"
                },
                new SelectListItem {
                    Text = "Quadraphonic", Value = "Quad"
                },
                new SelectListItem {
                    Text = "Surround", Value = "Surround"
                },
                new SelectListItem {
                    Text = "5.1", Value = "FiveDotOneSurround"
                },
                new SelectListItem {
                    Text = "7.1", Value = "SevenDotOneSurround"
                }
            };
        }
        private void ProcessRequestInternal(HttpListenerContext context, string localPath)
        {
            var  command       = localPath.Split('/').LastOrDefault();
            long?positionTicks = null;

            if (string.Equals(command, "config", StringComparison.OrdinalIgnoreCase))
            {
                var response = context.Response;

                var bytes = Encoding.UTF8.GetBytes(_json.SerializeToString(_player.GetConfiguration()));

                response.ContentType     = "application/json";
                response.ContentLength64 = bytes.Length;
                response.OutputStream.Write(bytes, 0, bytes.Length);
                return;
            }
            if (string.Equals(command, "configsave", StringComparison.OrdinalIgnoreCase))
            {
                var config = _json.DeserializeFromStream <DirectShowPlayerConfiguration>(context.Request.InputStream);
                _player.UpdateConfiguration(config);

                var response = context.Response;

                var bytes = Encoding.UTF8.GetBytes(_json.SerializeToString(_player.GetConfiguration()));

                response.ContentType     = "application/json";
                response.ContentLength64 = bytes.Length;
                response.OutputStream.Write(bytes, 0, bytes.Length);
                return;
            }
            else if (string.Equals(command, "getaudiodevices", StringComparison.OrdinalIgnoreCase))
            {
                var response  = context.Response;
                var jsnString = _json.SerializeToString(AudioConfigurationUtils.GetAudioDevices());
                var bytes     = Encoding.UTF8.GetBytes(jsnString);

                response.ContentType     = "application/json";
                response.ContentLength64 = bytes.Length;
                response.OutputStream.Write(bytes, 0, bytes.Length);
                return;
            }
            else if (Regex.IsMatch(command, "configresetdefaults-\\w+$", RegexOptions.IgnoreCase))
            {
                Match configType = Regex.Match(command, "configresetdefaults-(\\w+)$", RegexOptions.IgnoreCase);

                if (configType.Success)
                {
                    _player.ResetConfiguration(configType.Groups[1].Value);
                }

                var response = context.Response;
                var bytes    = Encoding.UTF8.GetBytes(_json.SerializeToString(_player.GetConfiguration()));

                response.ContentType     = "application/json";
                response.ContentLength64 = bytes.Length;
                response.OutputStream.Write(bytes, 0, bytes.Length);
                return;
            }

            if (string.Equals(command, "play", StringComparison.OrdinalIgnoreCase))
            {
                var playRequest = _json.DeserializeFromStream <PlayRequest>(context.Request.InputStream);

                Play(playRequest.url, playRequest.startPositionTicks ?? 0, playRequest.isVideo, playRequest.mediaSource, playRequest.item, playRequest.fullscreen);
            }
            else if (string.Equals(command, "pause", StringComparison.OrdinalIgnoreCase))
            {
                Pause();
            }
            else if (string.Equals(command, "unpause", StringComparison.OrdinalIgnoreCase))
            {
                UnPause();
            }
            else if (string.Equals(command, "stopfade", StringComparison.OrdinalIgnoreCase))
            {
                positionTicks = GetPositionTicks();
                Stop(true);
            }
            else if (string.Equals(command, "stop", StringComparison.OrdinalIgnoreCase))
            {
                positionTicks = GetPositionTicks();
                Stop(false);
            }
            else if (string.Equals(command, "mute", StringComparison.OrdinalIgnoreCase))
            {
                SetMute(true);
            }
            else if (string.Equals(command, "unmute", StringComparison.OrdinalIgnoreCase))
            {
                SetMute(false);
            }
            else if (string.Equals(command, "volume", StringComparison.OrdinalIgnoreCase))
            {
                float value;
                if (float.TryParse(context.Request.QueryString["val"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    SetVolume(value);
                }
            }
            else if (string.Equals(command, "positionticks", StringComparison.OrdinalIgnoreCase))
            {
                long value;
                if (long.TryParse(context.Request.QueryString["val"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    SetPositionTicks(value);
                }
            }
            else if (string.Equals(command, "setAudioStreamIndex", StringComparison.OrdinalIgnoreCase))
            {
                int value;
                if (int.TryParse(context.Request.QueryString["index"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    _player.SetAudioStreamIndex(value);
                }
            }
            else if (string.Equals(command, "setSubtitleStreamIndex", StringComparison.OrdinalIgnoreCase))
            {
                int value;
                if (int.TryParse(context.Request.QueryString["index"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    _player.SetSubtitleStreamIndex(value);
                }
            }

            SendResponse(context, positionTicks);
        }
Exemple #3
0
        private void ProcessRequestInternal(HttpListenerContext context, string localPath)
        {
            var  command       = localPath.Split('/').LastOrDefault();
            long?positionTicks = null;

            if (string.Equals(command, "getaudiodevices", StringComparison.OrdinalIgnoreCase))
            {
                var response  = context.Response;
                var jsnString = _json.SerializeToString(AudioConfigurationUtils.GetAudioDevices());
                var bytes     = Encoding.UTF8.GetBytes(jsnString);

                response.ContentType     = "application/json";
                response.ContentLength64 = bytes.Length;
                response.OutputStream.Write(bytes, 0, bytes.Length);
                return;
            }

            if (string.Equals(command, "play", StringComparison.OrdinalIgnoreCase))
            {
                var playRequest = _json.DeserializeFromStream <PlayRequest>(context.Request.InputStream);

                var playerWindowHandle = new IntPtr(long.Parse(playRequest.windowHandle, CultureInfo.InvariantCulture));

                Play(playRequest.url, playRequest.startPositionTicks ?? 0, playRequest.isVideo, playRequest.mediaSource, playRequest.item, playRequest.fullscreen, playRequest.playerOptions, playerWindowHandle);
            }
            else if (string.Equals(command, "pause", StringComparison.OrdinalIgnoreCase))
            {
                Pause();
            }
            else if (string.Equals(command, "unpause", StringComparison.OrdinalIgnoreCase))
            {
                UnPause();
            }
            else if (string.Equals(command, "playpause", StringComparison.OrdinalIgnoreCase))
            {
                var currentState = _player.PlayState;
                if (currentState == PlayState.Paused)
                {
                    UnPause();
                }
                else if (currentState == PlayState.Playing)
                {
                    Pause();
                }
            }
            else if (string.Equals(command, "stopfade", StringComparison.OrdinalIgnoreCase))
            {
                positionTicks = GetPositionTicks();
                Stop(true);
            }
            else if (string.Equals(command, "stop", StringComparison.OrdinalIgnoreCase))
            {
                positionTicks = GetPositionTicks();
                Stop(false);
            }
            else if (string.Equals(command, "mute", StringComparison.OrdinalIgnoreCase))
            {
                SetMute(true);
            }
            else if (string.Equals(command, "unmute", StringComparison.OrdinalIgnoreCase))
            {
                SetMute(false);
            }
            else if (string.Equals(command, "volume", StringComparison.OrdinalIgnoreCase))
            {
                float value;
                if (float.TryParse(context.Request.QueryString["val"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    SetVolume(value);
                }
            }
            else if (string.Equals(command, "positionticks", StringComparison.OrdinalIgnoreCase))
            {
                long value;
                if (long.TryParse(context.Request.QueryString["val"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    SetPositionTicks(value);
                }
                else
                {
                    _logger.Error("Unrecognized positionticks value {0}", context.Request.QueryString["val"]);
                }
            }
            else if (string.Equals(command, "setAudioStreamIndex", StringComparison.OrdinalIgnoreCase))
            {
                int value;
                if (int.TryParse(context.Request.QueryString["index"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    _player.SetAudioStreamIndex(value);
                }
                else
                {
                    _logger.Error("Unrecognized setAudioStreamIndex value {0}", context.Request.QueryString["index"]);
                }
            }
            else if (string.Equals(command, "setSubtitleStreamIndex", StringComparison.OrdinalIgnoreCase))
            {
                int value;
                if (int.TryParse(context.Request.QueryString["index"], NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    _player.SetSubtitleStreamIndex(value);
                }
                else
                {
                    _logger.Error("Unrecognized setSubtitleStreamIndex value {0}", context.Request.QueryString["index"]);
                }
            }

            SendResponse(context, positionTicks);
        }