Hi everyone! I am trying to Create a simple Winamp Player using WINAMP Controls! I have so far used the "Web Based" method using webbased commands for Winamp, but that seems to throw alot of exception errors, and plus I wanted the the code to show the Song Title, and because of the Errors, it will disapear and suddenly appear again!
Instead I tried to find another API class and I found a great API online but I can simply not understand why I am not able to make any of the Functions work! I tried it but I dont get any response from Any of the Functions..
I was later told that I have to use a "Sub New" or "Initialize" function or method to make it work, and true enough thats how the Web Based API Source code was working too. But I simply dont know how to add the SUB NEW or INITIALIZE function to this code! Please correct me If I am wrong....
This is the Complete Winamp Source API obviousely made for VB2005, but should work for VBNET2010:
I hope I can get some help to make this work, Thank you very much in advance!
Instead I tried to find another API class and I found a great API online but I can simply not understand why I am not able to make any of the Functions work! I tried it but I dont get any response from Any of the Functions..
I was later told that I have to use a "Sub New" or "Initialize" function or method to make it work, and true enough thats how the Web Based API Source code was working too. But I simply dont know how to add the SUB NEW or INITIALIZE function to this code! Please correct me If I am wrong....
This is the Complete Winamp Source API obviousely made for VB2005, but should work for VBNET2010:
Code:
Public Class wa
'======================================
' Winamp VB.NET class v1.0, Written with VS.NET 2005 Beta 1 (should work on any .NET version though)
' Written by Troy Jones
' 1-1-2005
' www.rtds.org, Radio That Doesn't Suck
'======================================
' This code may be used in any application you want, freeware, shareware, commercial.
' If you use this code or parts of it, please give credit and keep a link to www.rtds.org available.
'
' Credits
'
' Parts of this code came from various resources around the net, although it's basically all mine.
' It was converted from a VB6 module I had been using, I needed a .NET one and couldn't find anything
' that suited my needs. This class is not meant to be an end all class of winamp classes. It's designed to
' do what I need it to, which I think most people will find suits them well enough.
'
' Stuff
'
' I understand that this code could be shorted a lot, more use of constants, etc...
' I wrote it as I still have a lot to learn with .NET and this is what I wanted as a result. ;)
' However, if you feel you can improve the code, please do and share it with everyone.
'
' Updates
'
' I'll be updating this code as I need it myself, but that's pretty much about it.
' Windows API Decs
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer
' SendMessage Constants
Private Const WM_USER As Short = &H400
Private Const WM_COMMAND As Short = &H111
Private Const WM_COPYDATA As Integer = &H4A
'Commands
Private Const WA_ADDFile As Short = 100
Private Const WA_CLEARPLAYLIST As Short = 101
Private Const WA_GETSTATUS As Short = 104
Private Const WA_GETTRACKPOSITION As Short = 105
Private Const WA_GETTRACKLENGTH As Short = 105
Private Const WA_SEEKTOPOSITION As Short = 106
Private Const WA_SETVOLUME As Short = 122
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_CLOSE As Integer = &HF060&
Private Const WA_CLOSE As Integer = 40001
' Variables to keep track of this object
Private WAHandle As Integer ' Handle to use for this instance of the object
Private WAClassName As String ' Class name for this instance of the object
Private WAPath As String ' Path to Winamp for this instance of the object
Public Function SetVolume(Optional ByVal VolLevel As Short = 127) As Integer
If ((VolLevel < 0) Or (VolLevel > 255)) Then VolLevel = 127
Return SendMessage(WAHandle, WM_USER, VolLevel, WA_SETVOLUME)
End Function
Public Sub SetHandle(Optional ByVal WAClassName As String = "Winamp v1.x")
WAHandle = FindWindow(WAClassName, Nothing)
End Sub
Public ReadOnly Property GetHandle() As Integer
Get
Return WAHandle
End Get
End Property
Public ReadOnly Property GetClassName() As String
Get
Return WAClassName
End Get
End Property
Public ReadOnly Property GetWAPath() As String
Get
Return WAPath
End Get
End Property
Public Function OpenWinamp(ByVal PathToWA As String, Optional ByVal ClassName As String = "Winamp v1.x") As Boolean
Dim OpenStatus As Integer
If My.Computer.FileSystem.FileExists(PathToWA) = False Then Return False
Try
OpenStatus = Shell(PathToWA & " /class=" & Chr(34) & ClassName & Chr(34), AppWinStyle.MinimizedNoFocus)
If OpenStatus <> 0 Then
WAClassName = ClassName
WAPath = PathToWA
WAHandle = FindWindow(WAClassName, Nothing)
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
Public Function waPrev() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40044, 0&)
End Function
Public Function waNext() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40048, 0&)
End Function
Public Function waPlay() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40045, 0&)
End Function
Public Function waPause() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40046, 0&)
End Function
Public Function waStop() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40047, 0&)
End Function
Public Function waFadeout() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40147, 0&)
End Function
Public Function waFadeAfterStop() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40157, 0&)
End Function
Public Function waFForward() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40148, 0&)
End Function
Public Function waFRewind() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40144, 0&)
End Function
Public Function waOpenFile() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40029, 0&)
End Function
Public Function waOpenURL() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40155, 0&)
End Function
Public Function waInfo() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40188, 0&)
End Function
Public Function waFirstTrack() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40154, 0&)
End Function
Public Function waLastTrack() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40158, 0&)
End Function
Public Function VisDispElapsed() As Long
Dim WAHandle As Long
Return SendMessage(WAHandle, WM_COMMAND, 40037, 0&)
End Function
Public Function VisDispRemaining() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40038, 0&)
End Function
Public Function VisOptions() As Long
VisOptions = SendMessage(WAHandle, WM_COMMAND, 40190, 0&)
End Function
Public Function VisPlugInOptions() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40191, 0&)
End Function
Public Function VisPlugInExec() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40192, 0&)
End Function
Public Function TogScrPreferences() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40012, 0&)
End Function
Public Function TogScrAbout() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40041, 0&)
End Function
Public Function TogAutoscroll() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40189, 0&)
End Function
Public Function TogAlwaysOnTop() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40019, 0&)
End Function
Public Function TogWindowshadeMain() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40064, 0&)
End Function
Public Function TogWindowshadeList() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40266, 0&)
End Function
Public Function TogDoublesize() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40165, 0&)
End Function
Public Function TogEq() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40036, 0&)
End Function
Public Function TogList() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40040, 0&)
End Function
Public Function TogMain() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40258, 0&)
End Function
Public Function TogBrowser() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40298, 0&)
End Function
Public Function TogEasyMove() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40186, 0&)
End Function
Public Function TogRepeat() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40022, 0&)
End Function
Public Function TogShuffle() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40023, 0&)
End Function
Public Function VolRaise() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40058, 0&)
End Function
Public Function VolLower() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40059, 0&)
End Function
Public Function MiscJumpToTime() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40193, 0&)
End Function
Public Function MiscJumpToFile() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40194, 0&)
End Function
Public Function SkinSelector() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40219, 0&)
End Function
Public Function SkinReload() As Long
Return SendMessage(WAHandle, WM_COMMAND, 40291, 0&)
End Function
Public Function waClose() As Long
Return SendMessage(WAHandle, WM_SYSCOMMAND, SC_CLOSE, 0&)
End Function
Public Function waClose_old() As Long
' This function appears to have problems closing WA5 on Win2k3 Server...
Return SendMessage(WAHandle, WM_COMMAND, 40001, 0&)
End Function
Public Function GetWinampTitle() As String
Dim strTitle As String
Dim n As Long
strTitle = Space(2048)
GetWindowText(WAHandle, strTitle, 2048)
Do
n = n + 1
Loop Until Asc(Mid$(strTitle, n, 1)) = 0
strTitle = Left$(strTitle, n - 1)
Return strTitle
End Function
Public Function waStatus() As String
Dim Status As Short
Status = SendMessage(WAHandle, WM_USER, 0, WA_GETSTATUS)
Select Case Status
Case 1
Return "Playing"
Case 3
Return "Paused"
Case Else
Return "Stopped"
End Select
End Function
Public Function JumpToPosition(ByVal PositionInSeconds As Integer) As Short
Return SendMessage(WAHandle, WM_USER, CInt(PositionInSeconds * 1000), 106)
End Function
Public Function GetTrackLength() As String
Return Secs2Time(SendMessage(WAHandle, WM_USER, 1, WA_GETTRACKLENGTH))
End Function
Public Function GetTrackLengthSeconds() As Integer
Return SendMessage(WAHandle, WM_USER, 1, WA_GETTRACKLENGTH)
End Function
Public Function GetTrackPosition() As String
Return Secs2Time(SendMessage(WAHandle, WM_USER, 0, WA_GETTRACKLENGTH) / 1000)
End Function
Public Function GetTrackPositionSeconds() As String
Return (SendMessage(WAHandle, WM_USER, 0, WA_GETTRACKLENGTH) / 1000)
End Function
Public Function GetTrackName() As String
Dim TitleText As String, nBytes As Integer
Dim Idx As Long
TitleText = Space(255)
nBytes = 256
GetWindowText(WAHandle, TitleText, nBytes)
TitleText = TitleText.Substring(0, InStr(1, TitleText, Chr(0)) - 1)
If TitleText.Substring(1, 3) = "Win" Then
GetTrackName = "No Song Playing"
Else
Idx = TitleText.IndexOf(".", 0) + 2
GetTrackName = TitleText.Substring(Idx, (TitleText.Length - Idx))
End If
' Next two lines account for Playing shoutcast streams
If GetTrackName.IndexOf("[ICY 401", 0) > 0 Then Return ""
If GetTrackName.IndexOf("[Buffer:", 0) > 0 Then Return ""
Return GetTrackName.Replace(" - Winamp", "")
End Function
Private Function Secs2Time(ByVal secs As Integer) As String
Dim TempTime As String
TempTime = Trim$(Str$(secs \ 60))
Return TempTime & ":" & Trim$(Format(secs Mod 60, "0#"))
End Function
Public Function PLClear() As Integer
Return SendMessage(WAHandle, 1024, 0, 101)
End Function
Public Function PLLength() As Integer
Return SendMessage(WAHandle, WM_USER, 0, 124)
End Function
Public Function PLAddTrack(ByVal WAFile As String) As Boolean
' WAFile is the entire path and filename of the file to add
Dim OpenStatus As Integer
If My.Computer.FileSystem.FileExists(WAFile) = False Then Return False
Try
OpenStatus = Shell(WAPath & " /class=" & Chr(34) & WAClassName & Chr(34) & " /ADD " & Chr(34) & WAFile & Chr(34), AppWinStyle.MinimizedNoFocus)
If OpenStatus <> 0 Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
End Class