Code: Select all
Video
Code: Select all
int videoProgress = 0;
List videos = default!;
FileInfo? video;
string? videoUrl;
private async Task OnVideoCompletedAsync(IEnumerable _videos) {
videos = _videos.ToList();
Console.WriteLine($"[EVENT] Video Dropped : {videos.Count()}");
videos.ForEach(x => Console.WriteLine($"Name: {x.Name}, Size: {x.Size/1000000f} mb"));
video = videos[0].LocalFile;
videoUrl = await embedFiles(video, "video/mp4");
videoProgress = 0;
StateHasChanged();
}
private async Task embedFiles(FileInfo? fileInfo, string format) {
if(fileInfo == null) {
return null;
}
byte[] bytes = new byte[fileInfo.Length];
using(FileStream fileStream = fileInfo.OpenRead()) {
await fileStream.ReadAsync(bytes);
}
string url = await JSRuntime.InvokeAsync("bytesToDataURL", bytes, format);
Console.WriteLine($"[INFO] File URLs : {url}");
return url;
}
Code: Select all
async function bytesToDataURL(bytes, format) {
const blob = new Blob([new Uint8Array(bytes)], format);
let url = URL.createObjectURL(blob);
console.log(url);
return url;
}