Skip to content

Commit a01c9c6

Browse files
committed
doc: 增加下载示例
1 parent b2d17e9 commit a01c9c6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private IVideoDevice? VideoDeviceService { get; set; }</Pre>
1818
<Button Text="@Localizer["VideoDeviceOpenText"]" Icon="fa-solid fa-play" OnClick="OnOpenVideo" IsDisabled="_isOpen || string.IsNullOrEmpty(_deviceId)"></Button>
1919
<Button Text="@Localizer["VideoDeviceCloseText"]" Icon="fa-solid fa-stop" OnClick="OnCloseVideo" IsDisabled="!_isOpen"></Button>
2020
<Button Text="@Localizer["VideoDeviceCaptureText"]" Icon="fa-solid fa-camera" OnClick="OnCapture" IsDisabled="!_isOpen"></Button>
21+
<Button Text="@Localizer["VideoDeviceDownloadText"]" Icon="fa-solid fa-download" OnClick="OnDownload" IsDisabled="!_isOpen"></Button>
2122
<Button Text="QVGA" IsDisabled="!_isOpen" OnClickWithoutRender="() => OnApply(320, 240)"></Button>
2223
<Button Text="VGA" IsDisabled="!_isOpen" OnClickWithoutRender="() => OnApply(640, 480)"></Button>
2324
<Button Text="HD" IsDisabled="!_isOpen" OnClickWithoutRender="() => OnApply(1280, 960)"></Button>

src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public partial class VideoDevices : IAsyncDisposable
1313
[Inject, NotNull]
1414
private IVideoDevice? VideoDeviceService { get; set; }
1515

16+
[Inject, NotNull]
17+
private DownloadService? DownloadService { get; set; }
18+
1619
private readonly List<IMediaDeviceInfo> _devices = [];
1720

1821
private List<SelectedItem> _items = [];
@@ -61,6 +64,15 @@ private async Task OnCapture()
6164
_previewUrl = await VideoDeviceService.GetPreviewUrl();
6265
}
6366

67+
private async Task OnDownload()
68+
{
69+
var stream = await VideoDeviceService.GetPreviewData();
70+
if (stream != null)
71+
{
72+
await DownloadService.DownloadFromStreamAsync("preview.png", stream);
73+
}
74+
}
75+
6476
private async Task OnApply(int width, int height) => await VideoDeviceService.Apply(new MediaTrackConstraints() { Width = width, Height = height });
6577

6678
private async Task DisposeAsync(bool disposing)

0 commit comments

Comments
 (0)