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.
Related
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();
}
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,
I'm having problems with trying to save HTML source code into specific file. My goal is to save data that I get from "chromeBrowser.GetBrowser().MainFrame.ViewSource();" in "OnLoadingStateChanged" method into a file named "html.txt". Is it possible to do that?
public void InitializeChromiumWebBrowser()
{
CefSettings cefSettings = new CefSettings();
Cef.Initialize(cefSettings);
chromeBrowser = new ChromiumWebBrowser("https://google.com");
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
chromeBrowser.LoadingStateChanged += OnLoadingStateChanged;
}
private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs args)
{
if (!args.IsLoading)
chromeBrowser.GetBrowser().MainFrame.ViewSource();
}
I need exactly this method that is used in given code.
I've tried getting HTML Code through WebClient, HTTPWebRequest, GetSourceAsync, but none of those solutions work for my case.
I have embed CefSharp in my application using C# but looks like browser rendering is not proper (screenshot is attached below). I tried to find the issue without a success.
This is how I am initializing CEF :
public Form1() {
InitializeComponent();
InitializeChromium();
}
public void InitializeChromium() {
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
chromeBrowser = new ChromiumWebBrowser("http://www.google.com");
chromeBrowser.Dock = DockStyle.Fill;
this.Controls.Add(chromeBrowser);
}
Error picture 01
I want to know why this is happening?, thank you.
Scenario:
I'd like to use a WebBrowser Control to proxy website navigation on external websites for a research project. Therefore I tried to use the WebBrowser Control to load the site within a page request and forward the received HTML with some modifications (as changed src/href and javascript event handlers aso.). When a participant/user triggers an onclick event on the proxied website, I fetch this event on the server and would like to re-trigger it within my WebBrowser Control.
Problem:
I can't figure out how to handle the WebBrowser Control. Initially I thought it is just the matter of storing it as a session object, but the fact that it has to run in an STA thread makes this difficult. I need the same, active, browser object when the user invokes an onclick event to allow me to proxy this onclick on the control.
For now I use a Wrapper Class IEBrowser: System.Windows.Forms.ApplicationContext.
I copied the code from different sources, mainly from (http://www.codeproject.com/Articles/50544/Using-the-WebBrowser-Control-in-ASP-NET) but it does not consider using the same WebBrowser Control over many Requests.
Here is some of the code from the IEBrowser class:
public void Nav(string url)
{
this.url = url;
this.resultEvent = new AutoResetEvent(false);
htmlResult = null;
ths = new ThreadStart(delegate
{
// create a WebBrowser control
ieBrowser = new WebBrowser();
//Reset Session
InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);
// set WebBrowser event handls
ieBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(IEBrowser_DocumentCompleted);
//make request
ieBrowser.Navigate(url);
System.Windows.Forms.Application.Run(this);
//remove WebBrowser event handler
ieBrowser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(IEBrowser_DocumentIsCompleted);
//for now, we keep the webBrowser open
//ieBrowser.Dispose();
});
thrd = new Thread(ths);
thrd.Name = "Thread 2";
thrd.IsBackground = true;
// set thread to STA state before starting
thrd.SetApartmentState(ApartmentState.STA);
thrd.Start();
EventWaitHandle.WaitAll(new AutoResetEvent[] { resultEvent });
thrd.Join();
}
// DocumentCompleted event handle
void IEBrowser_DocumentIsCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (ieBrowser.ReadyState == WebBrowserReadyState.Complete && ieBrowser.IsBusy == false)
{
//Replace or Set IDs on every HTML Element [...]
//...
//
ieBrowser.Stop();
ExitThread();
//Dispose();
resultEvent.Set();
}
}
Limitations:
This is not about performance, I need to do this remote, but only 1-5 person will use the site simultaniously. I know that using WebBrowser Control is probably not a good solution in general, but in this case it is exactly what I need to capture all user navigation.