diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..e9fbbd7
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,9 @@
+# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
+###############################
+# Core EditorConfig Options #
+###############################
+root = true
+
+# Code files
+[*.{cs,csx,vb,vbx}]
+indent_style = tab
\ No newline at end of file
diff --git a/src/Blazored.Video/Support/MediaErrorState.cs b/src/Blazored.Video/Support/MediaErrorState.cs
new file mode 100644
index 0000000..b3aeed0
--- /dev/null
+++ b/src/Blazored.Video/Support/MediaErrorState.cs
@@ -0,0 +1,17 @@
+namespace Blazored.Video.Support
+{
+ ///
+ /// Presents media error object.
+ ///
+ public class MediaErrorState
+ {
+ public MediaErrorType Code { get; set; }
+
+ public string Message { get; set; }
+
+ public override string ToString()
+ {
+ return this.Code.ToString();
+ }
+ }
+}
diff --git a/src/Blazored.Video/Support/MediaError.cs b/src/Blazored.Video/Support/MediaErrorType.cs
similarity index 90%
rename from src/Blazored.Video/Support/MediaError.cs
rename to src/Blazored.Video/Support/MediaErrorType.cs
index ca43889..ace8721 100644
--- a/src/Blazored.Video/Support/MediaError.cs
+++ b/src/Blazored.Video/Support/MediaErrorType.cs
@@ -1,10 +1,10 @@
namespace Blazored.Video.Support
{
- public enum MediaError
+ public enum MediaErrorType
{
MEDIA_ERR_ABORTED = 1, // fetching process aborted by user
MEDIA_ERR_NETWORK = 2, // error occurred when downloading
MEDIA_ERR_DECODE = 3, // error occurred when decoding
MEDIA_ERR_SRC_NOT_SUPPORTED = 4, // audio/video not supported
}
-}
\ No newline at end of file
+}
diff --git a/src/Blazored.Video/Support/VideoState.cs b/src/Blazored.Video/Support/VideoState.cs
index 39b8706..f25d757 100644
--- a/src/Blazored.Video/Support/VideoState.cs
+++ b/src/Blazored.Video/Support/VideoState.cs
@@ -12,7 +12,7 @@ public class VideoState
///
/// Returns a List<> object representing available audio tracks
///
- [Obsolete("This is not exactly obsolete, but not yet implemented, sorry",false)]
+ [Obsolete("This is not exactly obsolete, but not yet implemented, sorry", false)]
public List AudioTracks { get; set; }
///
/// Returns whether the audio/video should start playing as soon as it is loaded
@@ -56,9 +56,9 @@ public class VideoState
///
public bool Ended { get; set; }
///
- /// Returns a object representing the error state of the audio/video
+ /// Returns a object representing the error state of the audio/video
///
- public MediaError Error { get; set; }
+ public MediaErrorState Error { get; set; }
///
/// Returns whether the audio/video should start over again when finished
///
@@ -134,4 +134,4 @@ public class VideoState
///
public BlazoredVideo Video { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/Blazored.Video/wwwroot/blazoredVideo.js b/src/Blazored.Video/wwwroot/blazoredVideo.js
index b763983..a46064e 100644
--- a/src/Blazored.Video/wwwroot/blazoredVideo.js
+++ b/src/Blazored.Video/wwwroot/blazoredVideo.js
@@ -85,22 +85,35 @@ export function registerCustomEventHandler(el, eventName, payload) {
// Craft a bespoke json string to serve as a payload for the event
function getJSON(el, eventName, payload) {
- let data = { id: el.id };
if (payload && payload.length > 0) {
// this syntax copies just the properties we request from the source element
// IE 11 compatible
+ let data = {};
for (var obj in payload) {
var item = payload[obj];
- if (el[item]) {
- data[item] = el[item];
+ var itemValue = el[item];
+ if (itemValue) {
+ if (typeof itemValue === 'object') {
+ data[item] = {}
+ for (var inhProp in itemValue) {
+ data[item][inhProp] = itemValue[inhProp]
+ }
+ }
+ else {
+ data[item] = itemValue
+ }
}
}
- }
- // this stringify overload eliminates undefined/null/empty values
- return JSON.stringify(
- { id: el.id, name: eventName, state: data },
- function (k, v) { return (v === undefined || v == null || v.length === 0) ? undefined : v }
- );
+ // this stringify overload eliminates undefined/null/empty values
+ return JSON.stringify(
+ { name: eventName, state: data }
+ , function (k, v) { return (v === undefined || v == null || v.length === 0) ? undefined : v }
+ )
+ } else {
+ return JSON.stringify(
+ { name: eventName }
+ )
+ }
}
}
diff --git a/tests/Blazored.Video.Tests/VideoDataInflateDeflateTests.cs b/tests/Blazored.Video.Tests/VideoDataInflateDeflateTests.cs
index 092f8cb..a59441f 100644
--- a/tests/Blazored.Video.Tests/VideoDataInflateDeflateTests.cs
+++ b/tests/Blazored.Video.Tests/VideoDataInflateDeflateTests.cs
@@ -33,7 +33,7 @@ public void CanBeInflatedFromEmptyData()
public void CanBeInflatedFromAllData()
{
- var data = @"{""id"":""video1"",""name"":""Pause"",""state"":{""id"":""video1"",""Autoplay"":false,""Controls"":true,
+ var data = @"{""id"":""video1"",""name"":""Pause"",""state"":{""id"":""video1"",""Autoplay"":false,""Controls"":true,""error"":{""code"":2,""message"":""some message""},
""CurrentSrc"":""https://res.cloudinary.com/blazoredgitter/video/upload/v1557015491/samples/elephants.mp4"",
""CurrentTime"":5.25375,""DefaultMuted"":false,""DefaultPlaybackRate"":1,""Duration"":48.516,""Ended"":false,
""Loop"":false,""Muted"":false,""NetworkState"":1,""Paused"":true,""PlaybackRate"":1,
@@ -64,7 +64,9 @@ public void CanBeInflatedFromAllData()
Assert.Null(result.State.Seekable);
Assert.False(result.State.Seeking);
Assert.Equal(1, result.State.Volume);
-
+ Assert.NotNull(result.State.Error);
+ Assert.Equal(MediaErrorType.MEDIA_ERR_NETWORK, result.State.Error.Code);
+ Assert.Equal("some message", result.State.Error.Message);
}
}