I am using the following code to track the playback postion in sound files. It seems to work fine with wma files but the time are off with MP3 Files. The songs hit the end before the current postion says they are at the end. Any suggestions would be apperciated. Also does anyone know how to force the clock to a specfic sound card in a filter graph. when I add more then one audio render to my graph I do not see a default clock being set.
Dim l_Pos, l_Dur, l_Rem As Double
If Not (c_aud10 Is Nothing) Then 'AndAlso (c_aud10.CurrentState = zktAudioPlayer.PlayState.Running Or c_aud10.CurrentState = zktAudioPlayer.PlayState.Paused) Then
Dim l_AudioMin As Integer
Dim l_AudioSec As Integer
Dim l_AudioHour As Integer
l_Pos = c_aud10.CurrentPosition
l_Dur = c_aud10.Duration
l_Rem = l_Dur - l_Pos
l_AudioMin = CType(Int(l_Pos / 60), Integer)
l_AudioSec = CType(l_Pos Mod 60, Integer)
If l_AudioMin > 59 Then
l_AudioHour = CType(Int(l_AudioMin / 60), Integer)
l_AudioMin = l_AudioMin Mod 60
End If
lbl_TimeCode1.Text = "P " & l_AudioHour.ToString.PadLeft(2, "0"c) & ":" & l_AudioMin.ToString.PadLeft(2, "0"c) & ":" & l_AudioSec.ToString.PadLeft(2, "0"c)
scAud_1.Value = CType(l_Pos, Integer)
l_AudioMin = CType(Int(l_Dur / 60), Integer)
l_AudioSec = CType(l_Dur Mod 60, Integer)
If l_AudioMin > 59 Then
l_AudioHour = CType(Int(l_AudioMin / 60), Integer)
l_AudioMin = l_AudioMin Mod 60
End If
lbl_Duration1.Text = "D " & l_AudioHour.ToString.PadLeft(2, "0"c) & ":" & l_AudioMin.ToString.PadLeft(2, "0"c) & ":" & l_AudioSec.ToString.PadLeft(2, "0"c)
l_AudioMin = CType(Int(l_Rem / 60), Integer)
l_AudioSec = CType(l_Rem Mod 60, Integer)
If l_AudioMin > 59 Then
l_AudioHour = CType(Int(l_AudioMin / 60), Integer)
l_AudioMin = l_AudioMin Mod 60
End If
lbl_Remaining1.Text = "R " & l_AudioHour.ToString.PadLeft(2, "0"c) & ":" & l_AudioMin.ToString.PadLeft(2, "0"c) & ":" & l_AudioSec.ToString.PadLeft(2, "0"c)
Else
'lbl_TimeCode1.Text = "P 0.0"
'lbl_Duration1.Text = "D 0.0"
End If
Here is the coder for the calls to CurrentPostion and Duration
Private c_mediaPosition As IMediaPosition = Nothing
Public ReadOnly Property Duration() As Double
Get
Dim l_Duration As Double
If Not (c_mediaPosition Is Nothing) And c_FileIsLoaded = True Then
c_mediaPosition.get_Duration(l_Duration)
Return l_Duration
End If
Return -1
End Get
End Property
Public Property CurrentPosition() As Double
Get
Dim l_Pos As Double
If Not (c_mediaPosition Is Nothing) And c_FileIsLoaded = True Then
c_mediaPosition.get_CurrentPosition(l_Pos)
Return l_Pos
End If
End Get
Set(ByVal Value As Double)
If c_FileIsLoaded Then c_mediaPosition.put_CurrentPosition(Value)
End Set
End Property
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am still beating on this issue. I am reading the duration from the MP3 headers now and trying to make things work using the duration from the header. I have the stream working now with that using the MeadiaSeeking interface. My file scrubber bar is still acting really funny though I am trying to convert it to MediaSeeking as well but am having issues getting the code right to allow for scrolling (seeking) back and forth through the file. Does one of the samples show how to impliment a scrubber bar using the MediaSeeking interface? I was using the Position interface but that is not tracking my time correctly I am hoping this different approach will help. Any feed back is apperciated.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I belive I have now forced the primary sound card to be the clock. It did not change anthing with the file dirations being incorrect. It appears that the issue is with VBR mp3 files. for instance I have a copy of Beat It.mp3 and winamp and mediaplayer say it is 4:18 in lenght and the duration from Directshow shows it at 4:34 in length. This messes up positon tracking as well as my end song triggering. Any ideas on how I can get the correct durrations? I have a whole host of other mp3 files that this is an issu on as well.
Thanks
zktech
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I added some code to get the file lenght from the header of the MP3 file this gives me the supposed correct time (duration) This now matches winamp and WM. If I play the file based on that duration everthing seems to work find. However here is the rub now.
I have a scroll bar set to allow for moving of the postion in the file (ie.. a playback scrubber). If I scrub back and forth and then let the file play to the end it plays longer then the duration of the file in the header. I think this has to do with some kind of calculation that Direct Show is doing as it decompressed the VBR MP3 file.
When I start my test file and let the file play from beginning to end. The end postion is at position point 259.3 when I scrub arround the ending point is at 273.664. almost 15 seconds different.
Any ideas on how I can offset for the differnce in these VBR files?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the following code to track the playback postion in sound files. It seems to work fine with wma files but the time are off with MP3 Files. The songs hit the end before the current postion says they are at the end. Any suggestions would be apperciated. Also does anyone know how to force the clock to a specfic sound card in a filter graph. when I add more then one audio render to my graph I do not see a default clock being set.
Dim l_Pos, l_Dur, l_Rem As Double
If Not (c_aud10 Is Nothing) Then 'AndAlso (c_aud10.CurrentState = zktAudioPlayer.PlayState.Running Or c_aud10.CurrentState = zktAudioPlayer.PlayState.Paused) Then
Dim l_AudioMin As Integer
Dim l_AudioSec As Integer
Dim l_AudioHour As Integer
l_Pos = c_aud10.CurrentPosition
l_Dur = c_aud10.Duration
l_Rem = l_Dur - l_Pos
l_AudioMin = CType(Int(l_Pos / 60), Integer)
l_AudioSec = CType(l_Pos Mod 60, Integer)
If l_AudioMin > 59 Then
l_AudioHour = CType(Int(l_AudioMin / 60), Integer)
l_AudioMin = l_AudioMin Mod 60
End If
lbl_TimeCode1.Text = "P " & l_AudioHour.ToString.PadLeft(2, "0"c) & ":" & l_AudioMin.ToString.PadLeft(2, "0"c) & ":" & l_AudioSec.ToString.PadLeft(2, "0"c)
scAud_1.Value = CType(l_Pos, Integer)
l_AudioMin = CType(Int(l_Dur / 60), Integer)
l_AudioSec = CType(l_Dur Mod 60, Integer)
If l_AudioMin > 59 Then
l_AudioHour = CType(Int(l_AudioMin / 60), Integer)
l_AudioMin = l_AudioMin Mod 60
End If
lbl_Duration1.Text = "D " & l_AudioHour.ToString.PadLeft(2, "0"c) & ":" & l_AudioMin.ToString.PadLeft(2, "0"c) & ":" & l_AudioSec.ToString.PadLeft(2, "0"c)
Here is the coder for the calls to CurrentPostion and Duration
Private c_mediaPosition As IMediaPosition = Nothing
Public ReadOnly Property Duration() As Double
Get
Dim l_Duration As Double
If Not (c_mediaPosition Is Nothing) And c_FileIsLoaded = True Then
c_mediaPosition.get_Duration(l_Duration)
Return l_Duration
End If
Return -1
End Get
End Property
Public Property CurrentPosition() As Double
Get
Dim l_Pos As Double
If Not (c_mediaPosition Is Nothing) And c_FileIsLoaded = True Then
c_mediaPosition.get_CurrentPosition(l_Pos)
Return l_Pos
End If
End Get
Set(ByVal Value As Double)
If c_FileIsLoaded Then c_mediaPosition.put_CurrentPosition(Value)
End Set
End Property
I am still beating on this issue. I am reading the duration from the MP3 headers now and trying to make things work using the duration from the header. I have the stream working now with that using the MeadiaSeeking interface. My file scrubber bar is still acting really funny though I am trying to convert it to MediaSeeking as well but am having issues getting the code right to allow for scrolling (seeking) back and forth through the file. Does one of the samples show how to impliment a scrubber bar using the MediaSeeking interface? I was using the Position interface but that is not tracking my time correctly I am hoping this different approach will help. Any feed back is apperciated.
Thanks
http://msdn.microsoft.com/en-us/library/dd377588%28VS.85%29.aspx
snarfle
I belive I have now forced the primary sound card to be the clock. It did not change anthing with the file dirations being incorrect. It appears that the issue is with VBR mp3 files. for instance I have a copy of Beat It.mp3 and winamp and mediaplayer say it is 4:18 in lenght and the duration from Directshow shows it at 4:34 in length. This messes up positon tracking as well as my end song triggering. Any ideas on how I can get the correct durrations? I have a whole host of other mp3 files that this is an issu on as well.
Thanks
zktech
Here is where I am at any ideas?
I added some code to get the file lenght from the header of the MP3 file this gives me the supposed correct time (duration) This now matches winamp and WM. If I play the file based on that duration everthing seems to work find. However here is the rub now.
I have a scroll bar set to allow for moving of the postion in the file (ie.. a playback scrubber). If I scrub back and forth and then let the file play to the end it plays longer then the duration of the file in the header. I think this has to do with some kind of calculation that Direct Show is doing as it decompressed the VBR MP3 file.
When I start my test file and let the file play from beginning to end. The end postion is at position point 259.3 when I scrub arround the ending point is at 273.664. almost 15 seconds different.
Any ideas on how I can offset for the differnce in these VBR files?
Thanks