diff --git a/MK.IO/ConverterLE.cs b/MK.IO/ConverterLE.cs
index 71eb7f0..0d4c272 100644
--- a/MK.IO/ConverterLE.cs
+++ b/MK.IO/ConverterLE.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License.
using Newtonsoft.Json;
+using System.Xml;
namespace MK.IO
{
@@ -11,10 +12,11 @@ internal static class ConverterLE
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
- Formatting = Formatting.Indented,
+ Formatting = Newtonsoft.Json.Formatting.Indented,
Converters =
{
- new CustomDateTimeConverter()
+ new CustomDateTimeConverter(),
+ new CustomTimeSpanConverter()
},
};
}
@@ -28,7 +30,7 @@ public override bool CanConvert(Type objectType)
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
- if (objectType == typeof(DateTime?))
+ if (objectType == typeof(DateTime?))
{
if (reader.Value == null)
{
@@ -54,4 +56,38 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
}
}
}
+
+ internal class CustomTimeSpanConverter : JsonConverter
+ {
+ public override bool CanConvert(Type objectType)
+ {
+ return (objectType == typeof(TimeSpan)) || (objectType == typeof(TimeSpan?));
+ }
+
+ public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
+ {
+ if (objectType == typeof(TimeSpan?))
+ {
+ if (reader.Value == null)
+ {
+ return (TimeSpan?)null;
+ }
+ return XmlConvert.ToTimeSpan(reader.Value.ToString());
+ }
+ else if (objectType == typeof(TimeSpan))
+ {
+ return XmlConvert.ToTimeSpan(reader.Value.ToString());
+ }
+ return XmlConvert.ToTimeSpan(reader.Value.ToString());
+ }
+
+ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
+ {
+ if (value is not null and TimeSpan)
+ {
+ // convert TimeSpan to ISO 8601 format
+ writer.WriteValue(XmlConvert.ToString((TimeSpan)value));
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/MK.IO/CsharpDotNet2/Model/LiveEventEncoding.cs b/MK.IO/CsharpDotNet2/Model/LiveEventEncoding.cs
index 875f9b9..6934c8a 100644
--- a/MK.IO/CsharpDotNet2/Model/LiveEventEncoding.cs
+++ b/MK.IO/CsharpDotNet2/Model/LiveEventEncoding.cs
@@ -25,7 +25,7 @@ public class LiveEventEncoding
/// Use an ISO 8601 time value between 1 and 10 seconds to specify the output fragment length for the video and audio tracks of an encoding live event. For example, use PT2S to indicate 2 seconds. For the video track it also defines the key frame interval, or the length of a GoP (group of pictures). If this value is not set for an encoding live event, the fragment duration defaults to 2 seconds. The value cannot be set for pass-through live events.
[DataMember(Name = "keyFrameInterval", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "keyFrameInterval")]
- public string KeyFrameInterval { get; set; }
+ public TimeSpan KeyFrameInterval { get; set; }
///
/// Defaults to either Default720p or Default1080p depending on encoding type. May be used to specify alternative encoding templates - contact support for assistance if your needs are complex.
diff --git a/MK.IO/CsharpDotNet2/Model/LiveEventInput.cs b/MK.IO/CsharpDotNet2/Model/LiveEventInput.cs
index e05221b..0457d5c 100644
--- a/MK.IO/CsharpDotNet2/Model/LiveEventInput.cs
+++ b/MK.IO/CsharpDotNet2/Model/LiveEventInput.cs
@@ -40,7 +40,7 @@ public class LiveEventInput
/// ISO 8601 time duration of the key frame interval duration of the input. This value sets the EXT-X-TARGETDURATION property in the HLS output. For example, use PT2S to indicate 2 seconds. Leave the value empty for encoding live events.
[DataMember(Name = "keyFrameIntervalDuration", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "keyFrameIntervalDuration")]
- public string KeyFrameIntervalDuration { get; set; }
+ public TimeSpan KeyFrameIntervalDuration { get; set; }
///
/// The input protocol for the live event. This is specified at creation time and cannot be updated. Must be one of RTMP or SRT. fmp4 smooth input is not supported.
diff --git a/MK.IO/CsharpDotNet2/Model/LiveOutputProperties.cs b/MK.IO/CsharpDotNet2/Model/LiveOutputProperties.cs
index 00fd1cc..87f3c1e 100644
--- a/MK.IO/CsharpDotNet2/Model/LiveOutputProperties.cs
+++ b/MK.IO/CsharpDotNet2/Model/LiveOutputProperties.cs
@@ -17,7 +17,7 @@ public class LiveOutputProperties
/// ISO 8601 timespan duration of the archive window length. This is duration that customer want to retain the recorded content.
[DataMember(Name = "archiveWindowLength", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "archiveWindowLength")]
- public string ArchiveWindowLength { get; set; }
+ public TimeSpan ArchiveWindowLength { get; set; }
///
/// The name of the asset that the live output will write to.
@@ -98,7 +98,7 @@ public class LiveOutputProperties
/// Not supported. ISO 8601 timespan duration of the rewind window length during live playback. This is the amount of time that the live output will be able to rewind.
[DataMember(Name = "rewindWindowLength", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "rewindWindowLength")]
- public string RewindWindowLength { get; set; }
+ public TimeSpan RewindWindowLength { get; set; }
///
diff --git a/SampleLiveOperations.md b/SampleLiveOperations.md
index 1a6f786..26c3162 100644
--- a/SampleLiveOperations.md
+++ b/SampleLiveOperations.md
@@ -30,7 +30,7 @@ var liveOutputAsset = client.Assets.CreateOrUpdate(nameOutputAsset, "asset-" + n
var lo = client.LiveOutputs.Create(liveEvent.Name, MKIOClient.GenerateUniqueName("liveOutput"), new LiveOutputProperties
{
- ArchiveWindowLength = "PT5M",
+ ArchiveWindowLength = new TimeSpan(0,5,0),
AssetName = nameOutputAsset
});
diff --git a/SampleNet7.0/Program.cs b/SampleNet7.0/Program.cs
index 9c00df3..95d179b 100644
--- a/SampleNet7.0/Program.cs
+++ b/SampleNet7.0/Program.cs
@@ -448,7 +448,7 @@ static async Task MainAsync()
var lo = client.LiveOutputs.Create(le.Name, MKIOClient.GenerateUniqueName("liveOutput"), new LiveOutputProperties
{
- ArchiveWindowLength = "PT5M",
+ ArchiveWindowLength = new TimeSpan(0,5,0),
AssetName = nameasset
});