/// <summary> /// Parse value as specified type. /// </summary> /// <param name="value">The raw value to parse.</param> /// <returns>The typed parsed value.</returns> protected override T?ParseValue(string?value) { if (value == null) { return(null); } if (string.Compare((string)value, "true", StringComparison.InvariantCultureIgnoreCase) == 0) { value = "yes"; } if (string.Compare((string)value, "false", StringComparison.InvariantCultureIgnoreCase) == 0) { value = "no"; } // Remove parenthesis. if (value.Length >= 2 && value[0] == '"' && value[value.Length - 1] == '"') { value = value.Substring(1, (int)(value.Length - 2)); } return(FlagExtensions.ParseMpvFlag <T>((string)value)); }
/// <summary> /// Occurs when an event is received from MPV. /// </summary> private void Mpv_EventReceived(object sender, MpvMessageEventArgs e) { if (e.EventName == "start-file") { StartFile?.Invoke(this, new EventArgs()); } else if (e.EventName == "end-file" && EndFile != null) { var args = new EndFileEventArgs(); if (Enum.TryParse(e.Data["reason"], true, out EndReason reason)) { args.Reason = reason; } else { args.Reason = EndReason.Unknown; } EndFile?.Invoke(this, args); } else if (e.EventName == "file-loaded") { FileLoaded?.Invoke(this, new EventArgs()); } else if (e.EventName == "seek") { Seek?.Invoke(this, new EventArgs()); } else if (e.EventName == "playback-restart") { PlaybackRestart?.Invoke(this, new EventArgs()); } else if (e.EventName == "idle") { Idle?.Invoke(this, new EventArgs()); } else if (e.EventName == "tick") { Tick?.Invoke(this, new EventArgs()); } else if (e.EventName == "shutdown") { Shutdown?.Invoke(this, new EventArgs()); } else if (e.EventName == "log-message" && LogMessage != null) { var args = new LogMessageEventArgs { Prefix = e.Data["prefix"] ?? string.Empty, Level = FlagExtensions.ParseMpvFlag <LogLevel>(e.Data["level"]) ?? LogLevel.No, Text = e.Data["text"] ?? string.Empty }; LogMessage?.Invoke(this, args); } else if (e.EventName == "video-reconfig") { VideoReconfig?.Invoke(this, new EventArgs()); } else if (e.EventName == "audio-reconfig") { AudioReconfig?.Invoke(this, new EventArgs()); } else if (e.EventName == "property-change" && PropertyChanged != null) { var args = new PropertyChangedEventArgs() { Id = e.Data["id"].Parse <int>() ?? 0, Data = e.Data["data"] ?? string.Empty, Name = e.Data["name"] ?? string.Empty }; PropertyChanged?.Invoke(this, args); } }