VB.NET .Net 6.0 Videoplayer - vb.net

Can someone tell me how to embedd a simple (video) mediaplayer in VB.NET?
.Net 6.0 (in vs2022) does not seem to support a mediaplayer.
Thanks

First u add VLC or media player object, here i post how to add media player in tool and how to play simple video files.
By default, 'Windows Media Player' control is not provided in the Toolbox, we have to add it into the toolbox if required.
Inorder to add 'Windows Media Player' control into toolbox
Right click on 'General' tab (or anyother tab) in toolbox ->select 'Choose Items...' ->select 'COM Components' tab ->select 'Windows Media Player' ->click on 'OK' button.
Once u add media player, control will appear in VS tool bar, and from that u drag to ur form design.
Below the code to play video and audio files.
Imports System
Imports System.Windows.Forms
Namespace mymediaplayer Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub btnBrowse_Click(ByVal sender As Object, ByVal e As EventArgs)
openFileDialog1.Filter = "(mp3,wav,mp4,mov,wmv,mpg)|*.mp3;*.wav;*.mp4;*.mov;*.wmv;*.mpg|all files|*.*"
If openFileDialog1.ShowDialog() = DialogResult.OK Then axWindowsMediaPlayer1.URL = openFileDialog1.FileName
End Sub
End Class
End Namespace
Thanks and Regards
Aravind

Related

VB.net: How to hide the Windows Media Player visualisation pane, leaving control bar visible, on a modal form?

Using VS2017 VB Forms, I've made a little program to play .mp3 files using the AxWindowsMediaPlayer, and I can't seem to reliably fix the size of the control at runtime.
In design, I've set the Size and MaximumSize properties of the control ("size=120,45") so it snuggles up to a PictureBox, and at run time it "misbehaves" when a modal form is displayed for the second time - the player expands in size to show the visualisation pane, which I'm attempting to hide, by setting the control's Height (and Maximum Height) property so only the control bar portion of the player is visible.
I've replicated this behavior with a little code below. Form1 has a button which shows Form2 modally. Form2 has a Picturebox and the AxWindowsMediaPlayer. Clicking the PictureBox plays the "test.mp3" file from the Application.StartupPath. All is well...the first time the audio is played, the player behaves nicely...no visible visualisation!
Closing Form2, clicking the "Load Form2" button on Form1, and then clicking the PictureBox on Form2 again results in the undesired behaviour... the player expands and shows a waveform pattern in the visualisation pane. Showing Form2 NON-modally ( by using Show in place of ShowDialog) does NOT exhibit this behaviour, presumably because the control is displayed using the initial Size set in design. However, I would like to display Form2 modally.
I would be very grateful on suggestions on how I might overcome this unexpected size change. I've researched a little of the extensive documentation of the player, but I've been unable to hide that visualisation pane. Thank you.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form2.ShowDialog()
End Sub
End Class
Public Class Form2
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Dim AudioFile As String
AudioFile = (Application.StartupPath & "\test.mp3")
AxWindowsMediaPlayer1.Visible = True
AxWindowsMediaPlayer1.URL = AudioFile
End Sub
End Class ```
Well, it's a workaround, really: I uses "Show()" in place of "ShowDialog()", and passed data to Form2 (as it initializes) to retain the state of several picture boxes.
Job done, but I'm wary of the media player.

Invoke Click Cefsharp VB

I would like to simulate a click or keypresses to a web browser element that is on my visual studio vb project.
I have found ways to do it for the webbrowser object built-in to visual studio, but I am using the cefsharp browser, so
weBrowser.Document.GetElementById('id').InvokeMember("Click") would not work, because cefsharp doesn't allow .Document. So my question, to reiterate, is, how would I use vb to simulate a click on my cefsharp webbrowser? Any help is appreciated, and have a nice day.
EDIT: I've been working on this code:
Dim elementID As String = "myBtn"
Dim click As String = "Click"
browser.ExecuteScriptAsync("Document.All(elementID).InvokeMember(click)")
but I am not sure if it will work or how to use the elementID part (I am not sure what kind of web elements can go here). Maybe this extra information will help.
Using ExecuteScriptAsync will execute JavaScript against the Chrome engine, so you would have to send valid JavaScript to this function. The following code shows how you could start a search using DuckDuckGo
Imports System.Threading
Imports CefSharp
Imports CefSharp.WinForms
Public Class Form1
Private _browser As New ChromiumWebBrowser()
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
_browser.Top = 10
_browser.Left = 10
_browser.Width = 600
_browser.Height = 400
Controls.Add(_browser)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
_browser.Load("https://duckduckgo.com/")
'for simplicity just wait until page is downloaded, should be handled by LoadingStateChanged
Thread.Sleep(3000)
Dim jsScript As String = <js><![CDATA[
document.all("q").value = "stack overflow";
document.all("search_button_homepage").click();
]]></js>.Value
_browser.ExecuteScriptAsync(jsScript)
End Sub
End Class

Remove FileDownload Dialog in WebBrowser VB.NET

I just need to remove/block this FileDownload Dialog:
(I don't have enough reputation to post images, so here is a link):
http://i60.tinypic.com/9bbwig.jpg
How can I do it?
Because I want to download file without this dialog, but when I use WebClient is starts up either. When I use My.Computer.Network.DownloadFile it freezes the WebBrowser (dialog doesn't show) and then if I use Background Worker (not to freeze the WebBrowser) the dialog shows...
I have no ideas what to do next :(
To download the logo of CNN you can use the following code
Imports System.Net
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Down_NewProp.DownloadFileAsync(New Uri("http://edition.cnn.com/.a/1.97.4/assets/" & "logo_cnn_badge_3up.png"), Application.StartupPath & "\" & "logo_cnn.png")
End Sub
End Class
It's a security device, to prevent the user download a file without realising. I doubt you would be able to remove it.

How do I invoke a click event with GeckoFx?

I can't seem to invoke a click event in GeckoFX in vb.net. Here is my code:
Imports Skybound.Gecko
Public Class Form1
Sub New()
InitializeComponent()
Xpcom.Initialize(Environment.CurrentDirectory + "/xulrunner")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GeckoWebBrowser1.Navigate("https://www.google.com")
Dim Button = New GeckoButtonElement(_webBrowser.Document.getElementById("Search").DomObject)
End Sub
End Class
The problem is that it says I do not have GeckoButtonElement class. I followed this tutorial.
Can someone help me get this button to click in another way? Or is there something else I have to do?
Side question: is there a package with the latest geckofx + xulrunner for download somewhere? I can't seem to find anything newer than what was offered in the tutorial above (which is from 2012).
Thanks.
Dim button As Gecko.DOM.GeckoButtonElement = TryCast(_webBrowser.Document.GetElementById("Search"), Gecko.DOM.GeckoButtonElement)
If button IsNot Nothing Then
button.Click()
End If
Newer versions of GeckoFx available on https://bitbucket.org/geckofx
Latest version is GeckoFx 29.0 (https://bitbucket.org/geckofx/geckofx-29.0/downloads).

How to Open console in VB

I currently have a console application by using the setting illustrated in the image bellow. However Now I wish to open multiple forms with the console so I'm wondering if I can somehow open multiple forms or open the console within a Windows Forms Application
#tinstaafl can you share this extra programming or a link to a
solution. Thanks
Here's a couple of links:
Console and WinForm together for easy debugging
Console Enhancements
Here's a conversion of the first one. You'll need a form with a checkbox name "CheckBox1":
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
Win32.AllocConsole()
Console.WriteLine("Done!")
Else
Win32.FreeConsole()
End If
End Sub
End Class
Public Class Win32
<DllImport("kernel32.dll")> Public Shared Function AllocConsole() As Boolean
End Function
<DllImport("kernel32.dll")> Public Shared Function FreeConsole() As Boolean
End Function
End Class
Everytime you click the checkbox you show or hide the console. You can write to and read from the same as any console app.
Forms and Console applications are very different. So much so that generally speaking a process either needs to be a form or console application. Forms applications are implemented with a message pump and console applications are command line drive. It is possible to a degree to run a form within a console, and vice versa, but generally not recommended. If you truly need both I would highly encourage you to use 2 processes.
If you could elaborate a bit more on your use case we may be better able to help you out.
So this is very cool. In the designer just add a checkbox using the Toolbox common controls.
Then double click on the new "CheckBox1" and that will automatically insert this sub routine:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
End Sub
Then all you have to do is add this code:
If CheckBox1.Checked Then
Win32.AllocConsole()
Console.WriteLine("Done!")
Else
Win32.FreeConsole()
End If
When you run your windows form program and check the box it will automatically open the window and KEEP it open until you uncheck the box.
Add this class to the bottom of your program:
Public Class Win32
<DllImport("kernel32.dll")> Public Shared Function AllocConsole() As Boolean
End Function
<DllImport("kernel32.dll")> Public Shared Function FreeConsole() As Boolean
End Function
End Class
And be sure to add the Imports statement at the top
Imports System.Runtime.InteropServices
If you want to open a console window to interact with and when you close the console, that action won't terminate your windows program then you can add these two lines of code:
Dim myProcess As Process
myProcess = Process.Start("cmd.exe")