Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Media Player forward function not working

$
0
0
Hello,

I have a form with a Media Player object embedded. In the bin folder I have a folder named Movies where are a couple of movie files. I want to read all the files in that folder and make media player run them. For that I created a forward() function that works fine when I press the right arrow key. The problem is that it doesn't work with PlayStateChange event. It simply stops and doesn't read the following file. But if I press the play button it plays the next file. The problem is that I want it to play automatically. Here is the script:

Imports AxWMPLib.AxWindowsMediaPlayer

Public Class Form1
Dim fileNames As New List(Of String)
Dim index As Integer = 0

Private Sub frmPrincipal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim files = My.Computer.FileSystem.GetFiles("Movies")

fileNames.Clear()
index = 0
For i = 0 To files.Count - 1
fileNames.Add(files(i))
Next

play(index)
End Sub

Private Sub play(ByVal index As Integer)
AxWindowsMediaPlayer1.URL = fileNames(index)
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub

Private Sub forward()
index += 1
If index > fileNames.Count - 1 Then
index = 0
End If
play(index)
End Sub

Private Sub backward()
index -= 1
If index < 0 Then
index = fileNames.Count - 1
End If
play(index)
End Sub

Private Sub AxWindowsMediaPlayer1_KeyUpEvent(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_KeyUpEvent) Handles AxWindowsMediaPlayer1.KeyUpEvent
Select Case e.nKeyCode
Case Keys.Right
forward()
Case Keys.Left
backward()
End Select
End Sub

Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If e.newState = WMPLib.WMPPlayState.wmppsMediaEnded Then
forward()
End If
End Sub

End Class

ANOTHER PROBLEM is that when in fullscreen mode the KeyUp event doesn't work anymore so I can't advance through the files.

Any help?
Thx

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>