Bitrate from Encoded Media Player file.

Tome`

Member
Joined
Jun 7, 2004
Messages
9
I am trying to get the Bitrate of an encoded audio file, but I run into a little problem with a returned data type. The code example I have been given is:
VB.NET:
 Dim AC As Integer 

Dim MyRate As Long

AC = Player1.currentMedia.getAttributeCountByType("Bitrate", "") - 1

MyRate = Player1.currentMedia.getItemInfoByType("Bitrate", "", AC)

bitRate.Text = "Bit rate = " & CStr(MyRate) & " bits/second"

But this throws an error: “Additional information: Cast from type 'UInt32' to type 'Long' is not valid.” It would seem that the return value of getItemInfoByType is a UInt32 value. The example cast it as a long which is then cast as a string "CStr(MyRate);the documentation for getItemInfoByType says it returns a string, but regardless I can't do anything with the returned value. Can someone Please shed some light on how I would go about getting and displaying this value. Thanks in advance.
 
according to the Media 9 SDK Library, Media.getItemInfoByType returns a string (as long as the specified attribute isn't WM/Lyrics_Synchronised, WM/Picture, or WM/UserWebURL). Define the variable MyRate as a string and remove the CStr in the concatenation and it should work.
 
Thanks Paszt,

When doing a search in the Object Browser for getitmeinfoByType it returns the following information. Public Overridable Function getItemInfoByType(ByVal bstrType As String, ByVal bstrLanguage As String, ByVal lIndex As Integer) As Object

Member of: WMPLib.WindowsMediaPlayerClass

Which I take as meaning it returns an Object and not a String.



This code works for Visual Basic 6.0

VB.NET:
			Dim AC As Integer

			Dim MyRate As Long

  

			AC = Player.currentMedia.getAttributeCountByType("Bitrate", "") - 1

			MyRate = Player.currentMedia.getItemInfoByType("Bitrate", "", AC)

			Bitrate.Caption = "Bit rate = " & CStr(MyRate) & " bits/second"



And this code works for Visual Basic .net

VB.NET:
	  Dim AC As Integer

	  Dim MyRate As Object

  

	  AC = Player1.currentMedia.getAttributeCountByType("Bitrate", "") - 1

	  MyRate = Player1.currentMedia.getItemInfoByType("Bitrate", "", AC)

	  bitRate.Text = "Bit rate = " & MyRate.ToString & " bits/second"



Now when searching for documentation on getinfobytype it leads one to believe it returns a String or a Long. But within the Object browser of .NET it says it returns an object; which it appears to do. Am I to believe that when trying to migrate to dot.NET this will be a problem I will need to deal with on a continuing basis? I am new at this so I am led to believe I should stick with something tried and true such as Visual Basic 6 until .NET is better documented. Any comments?
 
I'm not sure if the link above is correct, so I'll give again: Media.getItemInfoByType. On this page you'll see that the method getItemInfoByType returns a string as long as the specified attribute isn't WM/Lyrics_Synchronised, WM/Picture, or WM/UserWebURL. The link shows the return type for those attributes. It's defined as an object because of the possiblility of returning different types (a string is an object).
 
Back
Top