我想知道如何在Xamarin(所有平台)中显示来自jpegs的视频。
我的jpeg正在从流行的视频监控管理软件发送的http客户端流中流式传输。
我的jpeg采用 byte [] 的形式,我得到 10 jpegs / second 。这种格式是强加的。
我尝试在图片上快速更改来源,但这会导致Android上出现严重的叛逆。这似乎适用于Windows手机,但效果不佳。
如何为每个人创建一个视频播放器?除非我讨厌,否则现有组件无法做到这一点。
最佳,
答案 0 :(得分:1)
只需将带有NuGet的SkiaSharp.Views.Forms添加到项目中即可!
以下是代码(共享项目)中的内容:
// Content page initialization
private void InitUI() {
Title = "Xamavideo";
var button = new Button
{
Text = "Connect!"
};
Label label = new Label
{
Text = ""
};
var scroll = new ScrollView();
scroll.BackgroundColor = Color.Black;
Content = scroll;
var stack = new StackLayout
{
Padding = 40,
Spacing = 10
};
//Add a SKCanvasView item to the stack
var videoCanvas = new SKCanvasView
{
HeightRequest = 400,
WidthRequest = 600,
};
videoCanvas.PaintSurface += OnCanvasViewPaintSurface;
stack.Children.Add(videoCanvas);
}
//Create the event handler
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
// using (var stream = new SKManagedStream(fileStream))
if (lastFrame == null) return;
using (var canvas = surface.Canvas)
// use KBitmap.Decode to decode the byte[] in jpeg format
using (var bitmap = SKBitmap.Decode(lastFrame))
using (var paint = new SKPaint())
{
// clear the canvas / fill with black
canvas.DrawColor(SKColors.Black);
canvas.DrawBitmap(bitmap, SKRect.Create(640, 480), paint);
}
}
void UpdateFrame(VideoClient client){
//Use this to update the canvas:
byte[] lastFrame = client.imageBytes;
videoCanvas.InvalidateSurface();
}