Skip to content

Commit

Permalink
Merge pull request #21 from Blazored/KellsoHP-main
Browse files Browse the repository at this point in the history
PR #16 from @KellsoHP rebased onto main
  • Loading branch information
SQL-MisterMagoo authored Jan 3, 2023
2 parents 4975de9 + 9c2fdee commit c3be28f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions src/Blazored.Video/Support/MediaErrorState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Blazored.Video.Support
{
/// <summary>
/// Presents media error object.
/// </summary>
public class MediaErrorState
{
public MediaErrorType Code { get; set; }

public string Message { get; set; }

public override string ToString()
{
return this.Code.ToString();
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
8 changes: 4 additions & 4 deletions src/Blazored.Video/Support/VideoState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class VideoState
/// <summary>
/// Returns a List&lt;<see cref="AudioTrack"/>&gt; object representing available audio tracks
/// </summary>
[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<AudioTrack> AudioTracks { get; set; }
/// <summary>
/// Returns whether the audio/video should start playing as soon as it is loaded
Expand Down Expand Up @@ -56,9 +56,9 @@ public class VideoState
/// </summary>
public bool Ended { get; set; }
/// <summary>
/// Returns a <see cref="MediaError"/> object representing the error state of the audio/video
/// Returns a <see cref="MediaErrorState"/> object representing the error state of the audio/video
/// </summary>
public MediaError Error { get; set; }
public MediaErrorState Error { get; set; }
/// <summary>
/// Returns whether the audio/video should start over again when finished
/// </summary>
Expand Down Expand Up @@ -134,4 +134,4 @@ public class VideoState
/// </summary>
public BlazoredVideo Video { get; set; }
}
}
}
31 changes: 22 additions & 9 deletions src/Blazored.Video/wwwroot/blazoredVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
)
}
}
}
6 changes: 4 additions & 2 deletions tests/Blazored.Video.Tests/VideoDataInflateDeflateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

}
Expand Down

0 comments on commit c3be28f

Please sign in to comment.