当前位置: 首页 > news >正文

网站开发用的工具铜排制作 东莞

网站开发用的工具,铜排制作 东莞,宝安自适应网站建设,重庆seo快速优化软件介绍 在实际的开发过程中,需要在应用内部内嵌播放器进行视频的播放。官方默认的MediaElement控件只能播放有限的视频格式,也不能播放网络流。比较流行的解决方式是vlc的库,但是在实际使用过程中发现有很多问题。这里给大家推荐另一个比较好的…

介绍

在实际的开发过程中,需要在应用内部内嵌播放器进行视频的播放。官方默认的MediaElement控件只能播放有限的视频格式,也不能播放网络流。比较流行的解决方式是vlc的库,但是在实际使用过程中发现有很多问题。这里给大家推荐另一个比较好的库。

使用

官网地址

安装库

Nuget下安装FFME.Windows

PM> Install-Package FFME.Windows

下载ffmpeg依赖

注:官网给的地址我在实际使用中发现,使用官方的代码没问题,使用给定的步骤使用就会抱错,如果你们跟我一样给大家推荐另一个ffmpeg包的地址
ffmpeg依赖下载地址

代码

  1. 指定ffmpeg库的地址
Unosquare.FFME.Library.FFmpegDirectory = @"C:\ffmpeg\ffmpeg-4.4-windows-desktop-vs2022-gpl-lite\bin";
  1. xaml中插入控件
<Window x:Class="WpfApp1.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp1" xmlns:ffme="clr-namespace:Unosquare.FFME;assembly=ffme.win"mc:Ignorable="d"Loaded="Window_Loaded"Closed="Window_Closed"Title="MainWindow" Height="300" Width="600"><Grid><ffme:MediaElement x:Name="Media" Background="Gray" LoadedBehavior="Play" UnloadedBehavior="Manual" /><Button Content="Play" Click="PlayButton_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="10"/><Button Content="Stop" Click="StopButton_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="100,10,0,0"/></Grid>
</Window>
  1. 监听失败的事件
Media.MediaFailed += OnMediaFailed;
  1. 创建一个处理流地址的类FileInputStream
namespace Unosquare.FFME.Windows.Sample.Foundation;using Common;
using FFmpeg.AutoGen;
using System;
using System.IO;
using System.Runtime.InteropServices;/// <inheritdoc />
/// <summary>
/// Provides an example of a very simple custom input stream.
/// </summary>
/// <seealso cref="IMediaInputStream" />
public sealed unsafe class FileInputStream : IMediaInputStream
{private readonly FileStream BackingStream;private readonly object ReadLock = new();private readonly byte[] ReadBuffer;/// <summary>/// Initializes a new instance of the <see cref="FileInputStream"/> class./// </summary>/// <param name="path">The path.</param>public FileInputStream(string path){var fullPath = Path.GetFullPath(path);BackingStream = File.OpenRead(fullPath);var uri = new Uri(fullPath);StreamUri = new Uri(uri.ToString().ReplaceOrdinal("file://", Scheme));CanSeek = true;ReadBuffer = new byte[ReadBufferLength];}/// <summary>/// The custom file scheme (URL prefix) including the :// sequence./// </summary>public static string Scheme => "customfile://";/// <inheritdoc />public Uri StreamUri { get; }/// <inheritdoc />public bool CanSeek { get; }/// <inheritdoc />public int ReadBufferLength => 1024 * 16;/// <inheritdoc />public InputStreamInitializing OnInitializing { get; }/// <inheritdoc />public InputStreamInitialized OnInitialized { get; }/// <inheritdoc />public void Dispose(){BackingStream?.Dispose();}/// <summary>/// Reads from the underlying stream and writes up to <paramref name="targetBufferLength" /> bytes/// to the <paramref name="targetBuffer" />. Returns the number of bytes that were written./// </summary>/// <param name="opaque">The opaque.</param>/// <param name="targetBuffer">The target buffer.</param>/// <param name="targetBufferLength">Length of the target buffer.</param>/// <returns>/// The number of bytes that have been read./// </returns>public int Read(void* opaque, byte* targetBuffer, int targetBufferLength){lock (ReadLock){try{var readCount = BackingStream.Read(ReadBuffer, 0, ReadBuffer.Length);if (readCount > 0)Marshal.Copy(ReadBuffer, 0, (IntPtr)targetBuffer, readCount);else if (readCount == 0)return ffmpeg.AVERROR_EOF;return readCount;}catch (Exception){return ffmpeg.AVERROR_EOF;}}}/// <inheritdoc />public long Seek(void* opaque, long offset, int whence){lock (ReadLock){try{return whence == ffmpeg.AVSEEK_SIZE ?BackingStream.Length : BackingStream.Seek(offset, SeekOrigin.Begin);}catch{return ffmpeg.AVERROR_EOF;}}}
}
  1. 播放视频
//var target = new Uri(@"rtmp://127.0.0.1/live/test1231233");
var target = new Uri(@"D:\视频\泥坑.mp4");
if (target.ToString().StartsWith(FileInputStream.Scheme, StringComparison.OrdinalIgnoreCase))await Media.Open(new FileInputStream(target.LocalPath));
elseawait Media.Open(target);
http://www.yayakq.cn/news/635763/

相关文章:

  • 做网站原型图是用什么软件数字博物馆网站建设
  • 域名备案后怎样做网站响应式的学校网站
  • 企业网站的在线推广方法有哪几种海口网约车最新政策
  • 做视频采集网站犯法wordpress红包
  • 国外免费psd网站wordpress 调用特征图片
  • 商城网站程序湖南必去十大景点排名
  • 个人中心网页设计温州网站建设优化
  • 建筑设计网站制作网站视频接口 怎么做
  • 石家庄市建设厅网站缘魁上海网站建设
  • 珠海仿站定制模板建站天津市做网站的公司
  • 学做淘宝客网站如何修改wordpress后台绑定的域名
  • 亚马逊做品牌备案自有网站做系统和做网站哪个简单一些
  • 推广网站购物网站哪个是正品
  • 手机360网站seo优化服务专业的网页制作服务
  • 可以做调查的网站个人网站如何赚钱
  • 网络推广商城网站如何提高网站流量
  • 网站策划与维护做网站公司
  • 浙江网站建设哪里有专业网站建设 公司哪家好
  • 金色世纪做网站的是哪个岗位自己电脑做网站服务器广域网访问
  • 没有营业执照 怎么做网站学全屋定制设计怎么入手
  • wordpress移动端顶部导航栏移动端网站怎么做seo
  • 室内设计网课推荐网站站内优化方案
  • 新吴区网站建设wordpress一直加载
  • 网站注册查询邢台555信息港
  • 如何把网站转换成wap站点手表大全网站
  • 南宁最新消息今天哈尔滨网站建设网络优化
  • 模板做网站影响seo好的 做网站的软件公司
  • 动态电子商务网站 制作怎么让百度收录
  • 免费建站网站群加强网站建设的制度
  • 在什么网站做引流装修公司装饰