我想知道如何在Xamarin (所有平台)中显示来自jpegs的视频。
我的jpegs是从一个流行的视频监控管理软件发送的http客户端流中传输的。
我的jpeg以byte[]的形式出现,我了解10 jpegs/second。这种格式是强加的。
我试着在图像上快速改变Source,但它在安卓上造成了严重的变化。这似乎适用于Windows,但性能不太好。
如何为每个视频播放器创建一个视频播放器?除非我错了,否则现有的组件无法做到这一点。
最好的
发布于 2017-03-23 10:13:30
谢谢杰森!工程伟大,非常流畅的渲染!
只需将SkiaSharp.Views.Forms和NuGet添加到项目和瞧!
下面是代码(共享项目)中的内容:
// 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();
}https://stackoverflow.com/questions/42930776
复制相似问题