Results 1 to 7 of 7

Thread: [VB6]: Extracting current WMP song

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    [VB6]: Extracting current WMP song

    This just basically tell you if WMP is loaded then if it is playing a song and if it is what song. This might not work with some WMP versions i haven't tested with 11.0 but it might.

    VB Code:
    1. Option Explicit
    2. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4. Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    5.  
    6.  
    7. Public Function strGetText(lngHwnd As Long) As String
    8. Dim ilngLength As Long
    9. Dim strBuffer  As String
    10.  
    11.     ilngLength = SendMessageLong(lngHwnd, &HE, 0, 0)
    12.     strBuffer = String$(ilngLength, 0)
    13.     SendMessageByString lngHwnd, &HD, ilngLength + 1, strBuffer
    14.     strGetText = strBuffer
    15. Exit Function
    16.  
    17.     Resume Next
    18. End Function
    19.  
    20.  
    21. Public Function getWMPT() As String
    22. Dim stringtxt As String
    23. Dim wmplng As Long
    24.  
    25.  wmplng = FindWindow("WMPlayerAPP", vbNullString)
    26.  
    27.  If wmplng = 0 Then
    28.  getWMPT = "WMP is not loaded currently"
    29.  Else
    30.  stringtxt = strGetText(wmplng)
    31.  
    32.  If stringtxt = "Windows Media Player" Then
    33.  getWMPT = "No Song is currently being played"
    34.  Else
    35.  stringtxt = wmplng
    36.  getWMPT = Trim$(Left$(stringtxt, InStr(1, stringtxt, " - Windows Media Player")))
    37.  
    38.  End If
    39.  End If
    40.  
    41.     Exit Function
    42.     Resume Next
    43.        
    44. End Function

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: [VB6]: Extracting current WMP song

    I guess it works, but not for 11.0 at least not the song info. It can detect activity for WMP, but not the song.

  3. #3

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [VB6]: Extracting current WMP song

    It should almost detect the window for any version of windows media player but yes extracting the song title is a problem

  4. #4
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: [VB6]: Extracting current WMP song

    Urgh, I have a problem with this code.
    I'm not really sure where to put it :\
    Anychance you've got an example project for me darling?
    Thanx
    Kankerflecken.

  5. #5

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [VB6]: Extracting current WMP song

    I wouldn't worry for about it to much it only calls the song in older versions But in any case that would do in a module

    But i am working on getting the song title in newer versions of WMP for my new project. Winamp support and itunes support is complete. But WMP is a little trickier though i got it working in C++ just need to convert it and tidy it up a little then i will release the source

  6. #6
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: [VB6]: Extracting current WMP song

    Hey!
    Sorry i haven't replied or anything.
    I haven't even touched VB in about 9 weeks, it isn't good
    I've decided to spend more time on it..get some more apps up and running and whatever ^^
    anyway
    Back to this, i wacked the code in a module created some txtboxes and told the tb's to read the variables.
    AND i get this:


    this is my code
    Module
    vb Code:
    1. Option Explicit
    2.       Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3.       Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4.       Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    5.       Public Function strGetText(lngHwnd As Long) As String
    6.       Dim ilngLength As Long
    7.       Dim strBuffer  As String
    8.           ilngLength = SendMessageLong(lngHwnd, &HE, 0, 0)
    9.           strBuffer = String$(ilngLength, 0)
    10.           SendMessageByString lngHwnd, &HD, ilngLength + 1, strBuffer
    11.           strGetText = strBuffer
    12.       Exit Function
    13.           Resume Next
    14.       End Function
    15.       Public Function getWMPT() As String
    16.       Dim stringtxt As String
    17.       Dim wmplng As Long
    18.        wmplng = FindWindow("WMPlayerAPP", vbNullString)
    19.        If wmplng = 0 Then
    20.        getWMPT = "WMP is not loaded currently"
    21.        Else
    22.        stringtxt = strGetText(wmplng)
    23.        If stringtxt = "Windows Media Player" Then
    24.        getWMPT = "No Song is currently being played"
    25.        Else
    26.        stringtxt = wmplng
    27.        getWMPT = Trim$(Left$(stringtxt, InStr(1, stringtxt, " - Windows Media Player")))
    28.        End If
    29.        End If
    30.           Exit Function
    31.           Resume Next
    32.       End Function

    and this in my Form1
    vb Code:
    1. Private Sub Command1_Click()
    2. Text1.Text = getWMPT
    3. Text2.Text = stringtxt
    4. End Sub

    Its probably all wrong, i haven't touched VB for ages..and i wasn't that good at it anyway..so
    Don't laugh
    ^^


    THANKS!
    Kankerflecken.

  7. #7
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: [VB6]: Extracting current WMP song

    there is no problem with your app, wmp just doesn't allow this anymore (from WMP11) without your app being a plug-in.

    i think i'm going to take a try at developing such a thing.
    Delete it. They just clutter threads anyway.

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