Comments (1)
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)
- Dav Files Reproduction HOT 1
- When play rtmp steam or http stream, command stop(), the player will freeze 3-5 second
- close
- Upgrate to VLC 3.0.4 HOT 5
- Allow setting position / seeking to a keyframe HOT 1
- VLC回退重复缓冲 HOT 2
- demo solution does not build in VS2017 HOT 3
- get bitmap from "libvlc_media_player_get_hwnd" HOT 1
- Vlc elapsed time accuracy issue after I pause the video HOT 5
- 请更新 Meta.Vlc.Lib 版本
- 多平台支持 HOT 2
- need a simple way to stay in the 1st Frame HOT 2
- media plays the sound but there is no image after [restart window10+fisrt start programe] with low probability HOT 3
- 这个新版本缺少的的功能
- Where do I get libvlc 3.0 ?! HOT 1
- how can i play the video with Alpha channel HOT 1
- Vlc3.x用流的方式播放音视频时,最后半秒没有播放 HOT 1
- Create players with different options multiple times HOT 1
- How to know the online video was loaded failed? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meta.vlc.