Skip to content

Commit 23ebe64

Browse files
committed
feat: 增加 GetPreviewData 方法
1 parent fbc8446 commit 23ebe64

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ public async Task Capture()
4545
return await module.InvokeAsync<string?>("getPreviewUrl");
4646
}
4747

48+
public async Task<Stream?> GetPreviewData()
49+
{
50+
Stream? ret = null;
51+
var module = await LoadModule();
52+
var stream = await module.InvokeAsync<IJSStreamReference?>("getPreviewData");
53+
if (stream != null)
54+
{
55+
ret = await stream.OpenReadStreamAsync(stream.Length);
56+
}
57+
return ret;
58+
}
59+
4860
public async Task<bool> Apply(MediaTrackConstraints constraints)
4961
{
5062
var module = await LoadModule();

src/BootstrapBlazor/Services/MediaDevices/DefaultVideoDevice.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public Task Capture()
3737
return deviceService.Capture();
3838
}
3939

40+
public Task<Stream?> GetPreviewData()
41+
{
42+
return deviceService.GetPreviewData();
43+
}
44+
4045
public Task<string?> GetPreviewUrl()
4146
{
4247
return deviceService.GetPreviewUrl();

src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public interface IMediaDevices
4343
/// <returns></returns>
4444
Task<string?> GetPreviewUrl();
4545

46+
/// <summary>
47+
/// Gets the stream of the captured image.
48+
/// </summary>
49+
/// <returns></returns>
50+
Task<Stream?> GetPreviewData();
51+
4652
/// <summary>
4753
/// Apply the media track constraints.
4854
/// </summary>

src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,18 @@ public interface IVideoDevice
3636
/// <returns></returns>
3737
Task Capture();
3838

39-
///// <summary>
40-
///// Preview a still image from the video stream.
41-
///// </summary>
42-
///// <returns></returns>
43-
//Task Preview();
44-
45-
///// <summary>
46-
///// Gets the stream of the captured image.
47-
///// </summary>
48-
///// <returns></returns>
49-
//Task<Stream?> GetPreviewImage();
50-
5139
/// <summary>
5240
/// Gets the preview URL of the captured image.
5341
/// </summary>
5442
/// <returns></returns>
5543
Task<string?> GetPreviewUrl();
5644

45+
/// <summary>
46+
/// Gets the stream of the captured image.
47+
/// </summary>
48+
/// <returns></returns>
49+
Task<Stream?> GetPreviewData();
50+
5751
/// <summary>
5852
/// Apply the media track constraints.
5953
/// </summary>

0 commit comments

Comments
 (0)