Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cast MediaError to C# object #16

Merged
merged 4 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions src/Blazored.Video/Blazored.Video.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageReleaseNotes>Initial Release</PackageReleaseNotes>
<Version>1.0.1</Version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version control is added by CI pipeline

</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 11 additions & 2 deletions src/Blazored.Video/BlazoredVideo.razor
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,17 @@
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
}
}
}

Expand Down
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ToString here really necessary?

{
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 @@ -126,4 +126,4 @@ public class VideoState
/// </summary>
public double Volume { get; set; }
}
}
}
26 changes: 14 additions & 12 deletions tests/Blazored.Video.Tests/VideoDataInflateDeflateTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Blazored.Video.Support;
using Blazored.Video.Support;
using System;
using System.Text.Json;
using Xunit;
Expand Down Expand Up @@ -26,12 +26,12 @@ public void CanBeInflatedFromEmptyData()
var result = JsonSerializer.Deserialize<VideoEventData>(data, options);

Assert.NotNull(result);
Assert.Equal("Pause",result.Name);
Assert.Equal("Pause", result.Name);
}
[Fact]
public void CanBeInflatedFromAllData()
{
var data = @"{""name"":""Pause"",""state"":{""Autoplay"":false,""Controls"":true,
var data = @"{""name"":""Pause"",""state"":{""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,""Played"":{},
Expand All @@ -40,27 +40,29 @@ public void CanBeInflatedFromAllData()
var result = JsonSerializer.Deserialize<VideoEventData>(data, options);

Assert.NotNull(result);
Assert.Equal("Pause",result.Name);
Assert.Equal("Pause", result.Name);
Assert.False(result.State.Autoplay);
Assert.True(result.State.Controls);
Assert.Equal(new Uri("https://res.cloudinary.com/blazoredgitter/video/upload/v1557015491/samples/elephants.mp4"),result.State.CurrentSrc);
Assert.Equal(5.25375,result.State.CurrentTime);
Assert.Equal(new Uri("https://res.cloudinary.com/blazoredgitter/video/upload/v1557015491/samples/elephants.mp4"), result.State.CurrentSrc);
Assert.Equal(5.25375, result.State.CurrentTime);
Assert.False(result.State.DefaultMuted);
Assert.Equal(1, result.State.DefaultPlaybackRate);
Assert.Equal(48.516, result.State.Duration);
Assert.False(result.State.Ended);
Assert.False(result.State.Loop);
Assert.False(result.State.Muted);
Assert.Equal(NetworkState.NETWORK_IDLE,result.State.NetworkState);
Assert.Equal(NetworkState.NETWORK_IDLE, result.State.NetworkState);
Assert.True(result.State.Paused);
Assert.Equal(1, result.State.PlaybackRate);
Assert.Equal(0,result.State.Played.Length);
Assert.Equal("metadata",result.State.Preload);
Assert.Equal(ReadyState.HAVE_ENOUGH_DATA,result.State.ReadyState);
Assert.Equal(0,result.State.Seekable.Length);
Assert.Equal(0, result.State.Played.Length);
Assert.Equal("metadata", result.State.Preload);
Assert.Equal(ReadyState.HAVE_ENOUGH_DATA, result.State.ReadyState);
Assert.Equal(0, result.State.Seekable.Length);
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