Embedding LIb.VLC in winform Application - c#

This Question is In reference with my previous question Embedding VLC player in WInform Application in .Net Core. Core.Intialize() Giving Exception
I want to run the player for certain time and during that time video should be on repeat. Currently code looks like this ...
Core.Initialize();
var libvlc = new LibVLC();
// Make VideoView control
VideoView vv = new VideoView();
vv.MediaPlayer = new MediaPlayer(libvlc);
vv.Dock = DockStyle.Fill;
// Add it to the form
Controls.Add(vv);
var uri = new Uri(#"C:\vid.3gp");
// Use command line options as Options for media playback (https://wiki.videolan.org/VLC_command-line_help/)
var media = new Media(libvlc, uri, ":input-repeat=65535");
vv.MediaPlayer.Play(media);
//Set fullscreen
this.FormBorderStyle = FormBorderStyle.None;
this.Size = Screen.PrimaryScreen.Bounds.Size;
this.Location = Screen.PrimaryScreen.Bounds.Location;
How I can close the player after certain time. currently even if I close the form with the player video keeps playing in background till I close the whole application.
Just to inform the this winform application is created in .netcore3.1.
Regards.

Create MediaPlayer as class field and call it to start/pause/stop it in you WinForm application.
private LibVLC _libVlc;
private MediaPlayer _mediaPlayer;
...
// Call this method in your constructor/initializer
private void StartMediaPlayer(string videoUrl)
{
using var media = new Media(_libVlc, new Uri(videoUrl), ":input-repeat=65535");
_mediaPlayer = new MediaPlayer(_libVlc)
{
Media = media
};
_mediaPlayer.Play();
}
// Method to stop media player
private void button1_Click(object sender, EventArgs e)
{
_mediaPlayer.Stop();
}

Related

How would I go on making re sizable and moveable windows modules in a winform app?

I am currently developing a program where I can view and send data to an Arduino however I am unsure how to create a window Application that I can move the tabe inside it.
This Tab should be scaleable, pinnable, closeable, and can snap into corners or between other modules. Will I have to create this system From scratch or are there already packages out there that do this ?.
Example of what i try to do
all the telemetry data are in single tab, which can be moved or closed. I am trying to build a win form to do that Task
First of all I am trying to make a moveable Tabe , then scale it up with many modules at once. I am having trouble finding information about moveable Tabe in a winform so if you know of any information to help me out please let me know!
In Winforms, maybe you can try MDI. The link: Multiple-Document Interface (MDI) Applications is the document to create MDI Parent&Child you can refer to.
First, we need to set the "Main Form" as an MDIContainer.
public MainForm()
{
InitializeComponent();
this.IsMdiContainer = true;
}
Then, set the "Child Form"s' MdiParent to the "Main Form".
private void MainForm_Load(object sender, EventArgs e)
{
// Form1
MdiChildForm newMDIChild = new MdiChildForm();
newMDIChild.Size = new Size(200, 200);
newMDIChild.MdiParent = this;
newMDIChild.Show();
newMDIChild.Location = new Point(0, 0);
// Form2
MdiChildForm2 newMDIChild2 = new MdiChildForm2();
newMDIChild2.Size = new Size(500, 200);
newMDIChild2.MdiParent = this;
newMDIChild2.Show();
newMDIChild2.Location = new Point(210, 0);
}
The test result,

cefsharp change audio source name

I have a little c# winforms app, that plays some youtube videos. To play them, i'm using cefsharp because the winforms browser (IE9) doesn't support it.
everything is working fine, but i'd like to change the audio source name displayed in the volume mixer to the name of the app. (Currently it is "CefSharp.BrowserSubProcess")
here's the code i'm using to initialize the browser object
public ChromiumWebBrowser Browser;
public void InitializeChromium(string url, string cachepath)
{
CefSettings settings = new CefSettings();
// Initialize cef with the provided settings
settings.CachePath = cachepath;
//Handle cookies, such as yt login
if (!Directory.Exists(Path.Combine(cachepath, "Extensions")))
{
Directory.CreateDirectory(Path.Combine(cachepath, "Extensions"));
}
Cef.Initialize(settings);
// Create a browser component
Browser = new ChromiumWebBrowser(url);
// Add it to the form and fill it to the form window.
this.Controls.Add(Browser);
Browser.Dock = DockStyle.Fill;
Browser.AddressChanged += Browser_AddressChanged;
Browser.TitleChanged += Browser_TitleChanged;
KeyDown += Browser_KeyDown;
}
It is possible?
if yes, do i need to use some special arguments?
thanks in advice.

Video is not rendered in accord videoSourcePlayer control

I have an accord videoSourcePlayer control in my form.Why is it that it is not rendering the video that I select? Please see my code below:
// Open video file using DirectShow
private void openVideoFileusingDirectShowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// create video source
FileVideoSource = new FileVideoSource(openFileDialog.FileName);
// open it
sourceInitialiization = true;
OpenVideoSource(FileVideoSource);
}
}
// Open video source
private void OpenVideoSource(IVideoSource source)
{
// set busy cursor
this.Cursor = Cursors.WaitCursor;
// close previous video source
CloseVideoSource();
// start new video source
videoSourcePlayer.VideoSource = new AsyncVideoSource(source);
videoSourcePlayer.Start();
// reset statistics
statIndex = statReady = 0;
// start timers
timer.Start();
alarmTimer.Start();
//alarmTimer1.Start();
videoSource = source;
this.Cursor = Cursors.Default;
}
In my laptop where I initially coded this program, this works perfectly, but if I transfer it to another machine, say a desktop or another laptop, the code doesn't work anymore. It runs but it doesn't render the video and there is not error detected in the debugger too.
I tried downloading a sample video project from accord framework but I still couldn't get it to play a video on the desktop except on my laptop. What am I missing? Thank you.
Have you subscribed to the NewFrameReceived event?

Windows 8 xaudio2 playing wav file in multitouch app

I am learning how to work with xAudio2. Made a simple application Windows 8 in Visual Studio 2012 Express For Windows 8.
Simple xAudio2 player class:
public class SoundEffect
{
readonly XAudio2 _xaudio;
readonly WaveFormat _waveFormat;
readonly AudioBuffer _buffer;
readonly SoundStream _soundstream;
SourceVoice sourceVoice;
public SoundEffect(string soundFxPath)
{
_xaudio = new XAudio2();
var masteringsound = new MasteringVoice(_xaudio);
var nativefilestream = new NativeFileStream(
soundFxPath,
NativeFileMode.Open,
NativeFileAccess.Read,
NativeFileShare.Read);
_soundstream = new SoundStream(nativefilestream);
_waveFormat = _soundstream.Format;
_buffer = new AudioBuffer
{
Stream = _soundstream.ToDataStream(),
AudioBytes = (int)_soundstream.Length,
Flags = BufferFlags.EndOfStream
};
//sourceVoice = null;
}
public void Play()
{
sourceVoice = new SourceVoice(_xaudio, _waveFormat, true);
if (sourceVoice != null)
{
sourceVoice.FlushSourceBuffers();
sourceVoice.SubmitSourceBuffer(_buffer, _soundstream.DecodedPacketsInfo);
sourceVoice.Start();
}
}
public void Stop()
{
sourceVoice.Stop();
}
}
And Xaml:
<Border Background="Gray" MinHeight="150" MinWidth="150" Margin="10,10,0,0" x:Name="A" PointerPressed="btnAPointerPressed" PointerReleased="btnAPointerReleased" />
and:
private SoundEffect shotEffect = new SoundEffect(#"sounds\mywav.wav");
private void btnAPointerPressed(object sender, PointerRoutedEventArgs e)
{
bool _hasCapture = ((Border)sender).CapturePointer(e.Pointer);
shotEffect.Play();
}
private void btnAPointerReleased(object sender, PointerRoutedEventArgs e)
{
((Border)sender).ReleasePointerCapture(e.Pointer);
shotEffect.Stop();
}
Tested in Windows 8 Simulator.
If I press one finger, then everything is fine.
When I click on the button - the sound plays when I let go of your finger - the sound stops.
If I click with two fingers and let go of both fingers, the sound continues to play. And the result is aliasing.
Called two events: btnAPointerPressed and two events: btnAPointerReleased but the sound continues to play. As if the audio stream freezes and continues to play. As if the audio stream freezes and continues to play.
I want to understand the problem haudio2? or I do not properly done something?
When you call Play() again - the previous SourceVoice gets replaced with a new one in your SoundEffect, but you never stop the old one. You should create a new SourceVoice with each touch, but keep them all associated with the pointer IDs so that we can stop each of them when the associated pointers are released.

How can I create a shelltoast?

In my application I want to notify the user with the ShellToast.
Just by running...
var toast = new ShellToast
{
Title = "Nom nom nom!",
Content = "More! More! Keep feeding me!",
};
toast.Show();
...makes nothing happen, and as I understand it needs to be run from a ScheduledTaskAgent. But how do I run this on command, and make sure it only run once?
You can't use a ShellToast while the app is the foreground app. It's meant to be invoked from a background service while the app isn't the foreground app.
If you want to have a UX similar to that of ShellToast use the Coding4fun toolkit ToastPrompt control. Here's a code snippet showing how to use it:
private void ToastWrapWithImgAndTitleClick(object sender, RoutedEventArgs e)
{
var toast = GetToastWithImgAndTitle();
toast.TextWrapping = TextWrapping.Wrap;
toast.Show();
}
private static ToastPrompt GetToastWithImgAndTitle()
{
return new ToastPrompt
{
Title = "With Image",
TextOrientation = System.Windows.Controls.Orientation.Vertical,
Message = LongText,
ImageSource = new BitmapImage(new Uri("../../ApplicationIcon.png", UriKind.RelativeOrAbsolute))
};
}
Running this code snippet shows the following:
Just a small update: using ShellToast when the app is in foreground, is now possible, when using Windows Phone 8 Update 3. Though, they are obscured by other activity such as a phone call or the lock screen. Source

Categories

Resources