Giter Site home page Giter Site logo

缺少异常回调 about meta.vlc HOT 1 CLOSED

yangjieshao avatar yangjieshao commented on June 10, 2024
缺少异常回调

from meta.vlc.

Comments (1)

yangjieshao avatar yangjieshao commented on June 10, 2024

emm 断线重连的问题 解决了

VlcPlayer.Events.cs
/// <summary>
/// 确认是否正常播放
/// </summary>
private Thread _CheckAliveThread; // 记得在Dispose()里释放 - -
private bool _isCheckAliveThreadAlive = true;
private bool _isNeedCheckAlive = true;
private DateTime _lastVideoDisplayUpdateTime = DateTime.Now;
/// <summary>
/// 多久确认一次正常播放
/// </summary>
public int CheckAliveWaitMillisecond = 500;
/// <summary>
/// 播放过程出现错误
/// <para>播放不正常</para>
/// </summary>
public event EventHandler PlayingError;

private void MediaStateChanged(object sender, ObjectEventArgs<Interop.Core.Events.MediaStateChangedArgs> e)
{
if (_disposing || _isStopping) return;
if (State == MediaState.Playing)
{
if(_CheckAliveThread==null)
{
_CheckAliveThread = new Thread(() =>
{
while(_isCheckAliveThreadAlive)
{
if(_isNeedCheckAlive)
{
if ((DateTime.Now - _lastVideoDisplayUpdateTime).TotalMilliseconds > CheckAliveWaitMillisecond)
{
PlayingError?.Invoke(this, EventArgs.Empty);
}
Thread.Sleep(CheckAliveWaitMillisecond);
}
else
{
Thread.Sleep(20);
}
}
});
_CheckAliveThread.Start();
}
_isNeedCheckAlive = true;
}
else
{
_isNeedCheckAlive = false;
}
Debug.WriteLine(String.Format("StateChanged : {0}", e.Value.NewState));
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
if (StateChanged != null)
StateChanged(this, new ObjectEventArgs<MediaState>(e.Value.NewState));
}));
}

private void VideoDisplayCallback(IntPtr opaque, IntPtr picture)
{
_lastVideoDisplayUpdateTime = DateTime.Now;
if (_context == null || DisplayThreadDispatcher == null)
{
return;
}
_context.Display();
try
{
TakeSnapshot();
}
catch
{
// ignored
}
}

调用:
player.PlayingError += Player_PlayingError;
player.StateChanged += Player_StateChanged;

Uri rtsp1;
private void Player_StateChanged(object sender, Meta.Vlc.ObjectEventArgs<Meta.Vlc.Interop.Media.MediaState> e)
{
if (e.Value == Meta.Vlc.Interop.Media.MediaState.Error)
{
this.Dispatcher.Invoke(new Action(() =>
{
player.LoadMedia(rtsp1);
player.Play();
}));
}
}
private void Player_PlayingError(object sender, EventArgs e) { try { this.Dispatcher.Invoke(new Action(() => { player.LoadMedia(rtsp1); player.Play(); })); } catch (Exception) { } }`

from meta.vlc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.