-
Notifications
You must be signed in to change notification settings - Fork 118
Headless Examples
Ondrej Medek edited this page Oct 16, 2017
·
8 revisions
Examples of using WPF-MediaKit headless - without GUI, e.g. as a service.
Note, these examples demonstrates just basic functionality. E.g. you should hook on MediaOpened
, MediaFailed
events to catch the errors, etc.
static void Main(string[] args)
{
_player = new MediaUriPlayer();
_player.EnsureThread(ApartmentState.MTA);
_player.Dispatcher.BeginInvoke(new Action(() =>
{
_player.Source = new Uri("[MyUri]"); // mp3, wma, m3u, ...
_player.Play();
}));
Console.ReadKey();
}
static void Main(string[] args)
{
IntPtr backBuffer;
_player = new MediaUriPlayer();
_player.EnsureThread(ApartmentState.MTA);
_player.NewAllocatorFrame += () => GrabScreenShot(backBuffer);
_player.NewAllocatorSurface += (s, b) => backBuffer = b;
_player.Dispatcher.BeginInvoke(new Action(() =>
{
_player.AudioDecoder = null;
_player.AudioRenderer = null;
_player.Source = source;
_player.MediaPosition = second * MediaPlayerBase.DSHOW_ONE_SECOND_UNIT;
_player.Pause();
}));
Console.ReadKey();
}
private static void GrabScreenShot(IntPtr backBuffer)
{
// grab the screenshot, e.g.
D3DImage d3d = new D3DImage();
D3DImageUtils.SetBackBufferWithLock(d3d, backBuffer);
}
Also, see the Gist VideoScreenGrabber.cs for the more elaborate example.