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
Re: Current Position and Duration
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
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:
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = AxWindowsMediaPlayer1.currentMedia.duration Then
frmPainel.index += 1
AxWindowsMediaPlayer1.URL = frmPainel.lst_videos.Items.Item(frmPainel.index).ToString
MsgBox(frmPainel.lst_videos.Items.Item(frmPainel.index).ToString)
AxWindowsMediaPlayer1.Ctlcontrols.play()
' frmPainel.lst_videos.Items.
End If
No results.
Btw, tried it now in a timer, didn't work though.
vb Code:
Private Sub verificaMusica_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles verificaMusica.Tick
If AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString = AxWindowsMediaPlayer1.currentMedia.durationString Then
MsgBox("Current Position: " & AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString & vbNewLine)
MsgBox("Duration: " & AxWindowsMediaPlayer1.currentMedia.durationString)
End If
End Sub
Tried with interval to 100 and 1000. And of course it is enabled.
Re: Current Position and Duration
Code the media player's PlayStateChange event. For example:
vb.net Code:
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If e.newState = 1 Then
MessageBox.Show("Player stopped")
End If
End Sub
The value 1 stands for Stopped. You can find other possible values for e.newState in msdn.
BB
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:
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If e.newState = 8 Then
MessageBox.Show("Player stopped")
Else
MsgBox("something else happened")
End If
End Sub
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.
Re: Current Position and Duration
Well, the states that I've invoked:
wmppsTransitioning, wmppsPlaying and wmppsStopped.
Re: Current Position and Duration
Well there you go. Isn't that what you were after?
Re: Current Position and Duration
Even trying with this:
vb.net Code:
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If e.newState.ToString = "wmppsStopped" Then
MessageBox.Show("Player stopped")
Else
MsgBox("something else happened")
End If
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?
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.
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 :(
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:
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If e.newState = 8 Then
frmPainel.lst_videos.SelectedIndex += 1
'check if variable is well defined
MsgBox("URL: " & frmPainel.lst_videos.Items.Item(frmPainel.lst_videos.SelectedIndex).ToString)
AxWindowsMediaPlayer1.URL = frmPainel.lst_videos.Items.Item(frmPainel.lst_videos.SelectedIndex).ToString
AxWindowsMediaPlayer1.Ctlcontrols.play()
' frmPainel.lst_videos.Items.
Else
MsgBox([Enum].Parse(GetType(WMPLib.WMPPlayState), e.newState.ToString))
End If
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 :)
Re: Current Position and Duration
Anyone? I'm really needing this, and I'm achieving the method to do it :(