Hi there,
I'm trying to build a mediaplayer, which should be able to play video's on a beamer (presentation) with vb 2010.
For that I made 2 forms, first form is the main form with all the regular function (play, pause, stop, volume, open, etc) and the second form is the "presentation" screen and has a windows media player object on it (with modus set to none).
On the first form I also have a windows mediaplayer object (small preview screen).
The media is being loaded from an openfiledialog into a listbox and the url of both the mediaplayers are set to the listbox1.selecteditem.
This works and both of the players play the media selected, but there are not sync.
How to solve this?
Here is the code I use:
I'm trying to build a mediaplayer, which should be able to play video's on a beamer (presentation) with vb 2010.
For that I made 2 forms, first form is the main form with all the regular function (play, pause, stop, volume, open, etc) and the second form is the "presentation" screen and has a windows media player object on it (with modus set to none).
On the first form I also have a windows mediaplayer object (small preview screen).
The media is being loaded from an openfiledialog into a listbox and the url of both the mediaplayers are set to the listbox1.selecteditem.
This works and both of the players play the media selected, but there are not sync.
How to solve this?
Here is the code I use:
VB.NET:
Public Class MainForm
Dim tinseconden As Integer
Private Sub Play_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Play.Click
SecondForm.AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.play()
AxWindowsMediaPlayer1.Ctlcontrols.play()
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.mute
CheckBox1.Enabled = True
Me.Select()
Timer1.Start()
ProgressBarX1.Value = SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
End Sub
Private Sub Pause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pause.Click
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.pause()
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub
Private Sub Stopbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stopbutton.Click
Try
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.stop()
AxWindowsMediaPlayer1.Ctlcontrols.stop()
Catch ex As Exception
End Try
End Sub
Private Sub Slider1_DecreaseButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Slider1.DecreaseButtonClick
SecondForm.AxWindowsMediaPlayer1.settings.volume = SecondForm.AxWindowsMediaPlayer1.settings.volume - 10
End Sub
Private Sub Slider1_IncreaseButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Slider1.IncreaseButtonClick
SecondForm.AxWindowsMediaPlayer1.settings.volume = SecondForm.AxWindowsMediaPlayer1.settings.volume + 10
End Sub
Private Sub Slider1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Slider1.MouseMove
SecondForm.AxWindowsMediaPlayer1.settings.volume = Slider1.Value
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBarX1.Value = SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
tinseconden = SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
End Sub
Private Sub ButtonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem1.Click
OpenFileDialog1.ShowDialog()
For Each filename As String In OpenFileDialog1.FileNames
ListBox1.Items.Add(filename)
If ListBox1.Items.Count > 0 And ButtonItem2.Checked = True Then
Play.Enabled = True
Pause.Enabled = True
Stopbutton.Enabled = True
End If
Next
End Sub
Private Sub ButtonItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem2.Click
If ButtonItem2.Checked = True Then
ButtonItem2.Checked = False
Else
ButtonItem2.Checked = True
End If
End Sub
Private Sub ButtonItem2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem2.CheckedChanged
If ButtonItem2.Checked = True Then
Dim screen As Screen
'Show second form on second screen
screen = screen.AllScreens(1)
SecondForm.StartPosition = FormStartPosition.Manual
SecondForm.Location = screen.Bounds.Location + New Point(100, 100)
SecondForm.Show()
Me.Select()
If ListBox1.Items.Count > 0 And ButtonItem2.Checked = True Then
Play.Enabled = True
Pause.Enabled = True
Stopbutton.Enabled = True
End If
Else
SecondForm.Close()
ButtonItem2.Checked = False
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.stop()
AxWindowsMediaPlayer1.Ctlcontrols.stop()
Play.Enabled = False
Pause.Enabled = False
Stopbutton.Enabled = False
If CheckBox1.Checked = True Then
CheckBox1.Checked = False
CheckBox1.Enabled = False
End If
End If
End Sub
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If ListBox1.Items.Count = 0 And ButtonItem2.Checked = False Then
Play.Enabled = False
Pause.Enabled = False
Stopbutton.Enabled = False
End If
CheckBox1.Enabled = False
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
SecondForm.AxWindowsMediaPlayer1.fullScreen = True
Fullscreen.Checked = True
Else
SecondForm.AxWindowsMediaPlayer1.fullScreen = False
Fullscreen.Checked = False
End If
End Sub
Private Sub Playmenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Playmenu.Click
Try
SecondForm.AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.play()
AxWindowsMediaPlayer1.Ctlcontrols.play()
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.mute
CheckBox1.Enabled = True
Me.Select()
Timer1.Start()
ProgressBarX1.Value = SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
Catch ex As Exception
End Try
End Sub
Private Sub Pausemenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pausemenu.Click
Try
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.pause()
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Catch ex As Exception
End Try
End Sub
Private Sub Stopmenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stopmenu.Click
Try
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.stop()
AxWindowsMediaPlayer1.Ctlcontrols.stop()
Catch ex As Exception
End Try
End Sub
Private Sub ButtonItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem6.Click
AboutBox1.ShowDialog()
End Sub
Private Sub Fullscreen_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fullscreen.CheckedChanged
If Fullscreen.Checked Then
SecondForm.AxWindowsMediaPlayer1.fullScreen = True
CheckBox1.Checked = True
Else
SecondForm.AxWindowsMediaPlayer1.fullScreen = False
CheckBox1.Checked = False
End If
End Sub
Private Sub ProgressBarX1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ProgressBarX1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
ProgressBarX1.Value = e.X
SecondForm.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = ProgressBarX1.Value
End If
End Sub
End Class