Results 1 to 5 of 5

Thread: [RESOLVED] Media Player forward function not working

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    Resolved [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

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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:
    1. Dim plist As IWMPPlaylist = Player.playlistCollection.newPlaylist("play") ' set up a new playlist called (unimaginatively) 'play'
    2.  
    3.         For Each u In urls ' an array of filepaths
    4.             plist.appendItem(Player.newMedia(u)) ' fill the playlist
    5.         Next
    6.  
    7.         Player.currentPlaylist = plist ' set the media player
    8.         Player.controls.play()  ' play the list
    9.  
    10.         ' to go forward
    11.         Player.controls.next()
    12.  
    13.         ' to go back
    14.         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!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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
  •  



Click Here to Expand Forum to Full Width