|
-
May 9th, 2013, 07:22 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Media Player forward function not working
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
-
May 9th, 2013, 09:54 AM
#2
Re: Media Player forward function not working
The problem is that it doesn't work with PlayStateChange event.
Have you checked to see that MediaEnded is the actual state at any point in proceedings? I think it unlikely. In any case this is completely the wrong way to go about creating a playlist and navigating through it. That's why they invented the Playlist!
vb.net Code:
Dim plist As IWMPPlaylist = Player.playlistCollection.newPlaylist("play") ' set up a new playlist called (unimaginatively) 'play'
For Each u In urls ' an array of filepaths
plist.appendItem(Player.newMedia(u)) ' fill the playlist
Next
Player.currentPlaylist = plist ' set the media player
Player.controls.play() ' play the list
' to go forward
Player.controls.next()
' to go back
Player.controls.previous()
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 10th, 2013, 02:31 AM
#3
Thread Starter
Addicted Member
Re: Media Player forward function not working
Helpful, as usual. Thank you. I had to change controls.play to Ctlcontrols.play() in order to make it work.
One last question remains for this subject. For the player "keyup" event I wrote this code:
Select Case e.nKeyCode
Case Keys.Right
player.Ctlcontrols.next()
Case Keys.Left
player.Ctlcontrols.previous()
End Select
This works only if I am not in full screen mode. Any ideea how to make it work also in full screen?
Thx.
-
May 10th, 2013, 02:33 PM
#4
Re: Media Player forward function not working
I suspect that you'd need to register a hotkey combination for that. In full screen mode I believe the control is overridden to the extent that it is no longer a recipient of key events.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 12th, 2013, 02:22 AM
#5
Thread Starter
Addicted Member
Re: Media Player forward function not working
I understand. Now I'll have to figure out how to do that. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|