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

网站建设七大步骤百度搜索推广平台

网站建设七大步骤,百度搜索推广平台,申请网站,宝山网站建设推广介绍 在实际的开发过程中,需要在应用内部内嵌播放器进行视频的播放。官方默认的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.yidumall.com/news/97053.html

相关文章:

  • 小公司做网站多少钱外贸推广引流
  • 云虚拟主机做网站短链接购买
  • 北京 外贸型网站建设推广合作
  • 简约 时尚 高端 网站建设百度搜索优化怎么做
  • 东欣建设集团网站百度seo关键词排名
  • 电商网站开发图书seo搜索优化邵阳
  • 规划和设计一个网站百度网盘客服在线咨询
  • 企业网站招聘可以怎么做搜索引擎广告案例
  • 新疆建设兵团发改委网站官网百度网站名称和网址
  • 南宁高端网站建设公司杭州优化商务服务公司
  • 深圳贸易网站开发免费seo教程
  • 网站开发流程及顺序第三方网络营销平台有哪些
  • php网站开发实例教程书百度网站推广关键词怎么查
  • 怎样免费给自己的公司做网站水果网络营销策划方案
  • 做老电影网站侵权吗什么是搜索推广
  • 加盟类网站建设seo网络推广培训班
  • 有哪些学做衣服的网站有哪些竞价系统
  • 个人开发app需要多少钱seo推广软件排名
  • 个人网站需要多大空间营销推广软文案例
  • 怎么做移动端的网站电脑编程培训学校哪家好
  • 做网站图片的大小百度快照怎么没有了
  • 成都网站制作网站设计怎么在百度上发布信息
  • 云南高端建设网站seo管理
  • 专业团队怎样建设网站2022年最火文案
  • axure可以直接做网站卖链接的网站
  • 大庆公司做网站培训心得体会2000字
  • 成都网站建设公司排行seo推广优化服务
  • 国际 网站制作公司seo工资一般多少
  • 我想自己做网站seo什么意思
  • 绵阳网站建设优化seo服务公司上海