Results 1 to 14 of 14

Thread: Current Position and Duration

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Current Position and Duration

    Hey guys,
    Imagine that I have a timer checking the current position, and always checking if it is equal to the duration of the sound.

    I have a Media Player control.

    But, what are the variables of that? I tried with a Duration, and another, the curPosition, something like that, but couldn't get it to work. Any help?

    Thanks

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Guys, please..

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Current Position and Duration

    You are asking what variables you need to look at to get values of the current position of a playing item as well as the total duration of that item?

    Try

    Code:
    MP.Ctlcontrols.currentPositionString 'string obviously
    MP.currentMedia.durationString 'string obviously
    'or
    MP.Ctlcontrols.currentPosition 'double datatype
    MP.currentMedia.duration 'double datatype

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Well, and imagine that I want to make some action when I know that the file playing in AxWindowsMediaPlayer has stopped. How can I detect that without using a timer?

    (Why I don't want to use a timer? Because my application runs a lot from memory, and I don't want to overcharge it)

    I was trying this:
    vb Code:
    1. Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    2.         If AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = AxWindowsMediaPlayer1.currentMedia.duration Then
    3.             frmPainel.index += 1
    4.             AxWindowsMediaPlayer1.URL = frmPainel.lst_videos.Items.Item(frmPainel.index).ToString
    5.             MsgBox(frmPainel.lst_videos.Items.Item(frmPainel.index).ToString)
    6.             AxWindowsMediaPlayer1.Ctlcontrols.play()
    7.             ' frmPainel.lst_videos.Items.
    8.         End If

    No results.

    Btw, tried it now in a timer, didn't work though.

    vb Code:
    1. Private Sub verificaMusica_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles verificaMusica.Tick
    2.         If AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString = AxWindowsMediaPlayer1.currentMedia.durationString Then
    3.             MsgBox("Current Position: " & AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString & vbNewLine)
    4.             MsgBox("Duration: " & AxWindowsMediaPlayer1.currentMedia.durationString)
    5.         End If
    6.     End Sub

    Tried with interval to 100 and 1000. And of course it is enabled.
    Last edited by SirPereira; Apr 26th, 2010 at 03:33 PM.

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Current Position and Duration

    Code the media player's PlayStateChange event. For example:
    vb.net Code:
    1. Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    2.         If e.newState = 1 Then
    3.             MessageBox.Show("Player stopped")
    4.         End If
    5.     End Sub
    The value 1 stands for Stopped. You can find other possible values for e.newState in msdn.

    BB

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Well, even tried with else, but it didn't got there... and I'm sure the movie has finished lol.

    vb.net Code:
    1. Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    2.         If e.newState = 8 Then
    3.             MessageBox.Show("Player stopped")
    4.         Else
    5.             MsgBox("something else happened")
    6.         End If
    7.     End Sub

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Current Position and Duration

    It works fine for me.

    Create a new project, and add the media player to the form. Also add a listbox and a button. Then add this code:

    Code:
    Public Class Form1
    
        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            ListBox1.Items.Add([Enum].Parse(GetType(WMPLib.WMPPlayState), e.newState.ToString))
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            AxWindowsMediaPlayer1.URL = "C:\somevideo.wmv"
        End Sub
    
    End Class
    Change the video to a real one on your system.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Well, the states that I've invoked:
    wmppsTransitioning, wmppsPlaying and wmppsStopped.

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Current Position and Duration

    Well there you go. Isn't that what you were after?

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Even trying with this:

    vb.net Code:
    1. Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    2.         If e.newState.ToString = "wmppsStopped" Then
    3.             MessageBox.Show("Player stopped")
    4.         Else
    5.             MsgBox("something else happened")
    6.         End If
    7.     End Sub

    Couldn't get anything..

    EDIT:
    Well, I tried it on a new project, and It worked. What event could be blocking it from occur?
    Last edited by SirPereira; Apr 27th, 2010 at 11:27 AM.

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Current Position and Duration

    Hard to say. If you dont want to scratch your original project, you could just try to remove the media player component from it, then add it back in.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Good dammit. Tried to remove and add again, but a new problem has come:
    http://www.google.pt/search?q=visual...ient=firefox-a

    Already tried solving it, but none of the first solutions worked... grrr. Fortunatly I can back to where I had the WMP control.

    I've changed some of the WMP control' confs, but it is supposed to work with them, right?

    EDIT:
    I've found this, and I think I'm gonna take the same steps, as the events are not raising up...

    http://windows-tech.info/7/927dae71a3ccbb43.php

    EDIT2:

    OMG, bad luck today. I can't find it on MS website
    Last edited by SirPereira; Apr 27th, 2010 at 12:08 PM.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Finally, I got it to work!

    Now it recognizes the evets, but I'm having the problem of changing the source to another URL, I've already few things.

    The last one was this:
    vb.net Code:
    1. Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    2.  
    3.         If e.newState = 8 Then
    4.             frmPainel.lst_videos.SelectedIndex += 1
    5.  
    6. 'check if variable is well defined
    7.             MsgBox("URL: " & frmPainel.lst_videos.Items.Item(frmPainel.lst_videos.SelectedIndex).ToString)
    8.  
    9.             AxWindowsMediaPlayer1.URL = frmPainel.lst_videos.Items.Item(frmPainel.lst_videos.SelectedIndex).ToString
    10.  
    11.             AxWindowsMediaPlayer1.Ctlcontrols.play()
    12.             ' frmPainel.lst_videos.Items.
    13.         Else
    14.             MsgBox([Enum].Parse(GetType(WMPLib.WMPPlayState), e.newState.ToString))
    15.         End If
    16.  
    17.     End Sub

    What this basically supposed to do, was having a kind of playlist function, when the last movie stopped, it adds one value to a listbox, and will play the next movie there.

    But I'm getting the error that it cannot convert String to Media... Any suggestions?

    And yes, the var is retrieving the list index content (file path).

    Thanks

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Current Position and Duration

    Anyone? I'm really needing this, and I'm achieving the method to do it

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