Latest restricted WACUP beta release is build #18798 (April 7th 2024) (x86 & x64 changelogs) | Latest WACUP public preview is build #17040 (September 30th 2023) (x86 only)


NOTE: Beta testers are added in a limited & subjective manner as I can only support so many people as part of the beta test program to keep it useful for my needs.

Unless I think you're going to be helpful, not all requests will be accepted but might still be later on. Remember that beta testing is to help me & the limitations currently works for my needs for this project.

Author Topic: How to load a playlist programmatically  (Read 1537 times)

daniel_kukiela

  • Beta Tester
  • Full Member
  • ***
  • Posts: 14
    • View Profile
How to load a playlist programmatically
« on: October 26, 2021, 08:59:56 AM »
Hi everyone.

I'm making integration with Stream Deck. I'm not creating a Stream Deck plugin, at least for now, so I won't be able to show statuses in the Deck and rather start simple.
I'm a Python programmer and that's also my language of choice.
So I successfully wrote some code to play/pause/stop/prev/next using
Code: [Select]
win32api.SendMessage(hWinamp, win32con.WM_COMMAND, id, 0), where id is a given button.

I'd also like to be able to change playlists, but despite different attempts, nothing happens.
My sample code:
Code: [Select]
import win32api
import win32gui
import win32con
import sys
import ctypes
from ctypes import wintypes


# enumerates windows and returns possible matches
def window_enum_callback(hwnd, hwnds):
    #hwnds = []
    if 'Winamp' in win32gui.GetWindowText(hwnd) or 'WACUP' in win32gui.GetWindowText(hwnd):
        hwnds.append(hwnd)
hwnds = []
win32gui.EnumWindows(window_enum_callback, hwnds)

    return

# queries for a version to check if whatever has "winamp" in it's title is actually winamp
for hwnd in hwnds:
    result = usercommand(hwnd, 0)
    if result:
        break

# data structore for a playlist path
class COPYDATASTRUCT(ctypes.Structure):
    _fields_ = [
        ('dwData', wintypes.LPARAM),
        ('lpData', ctypes.c_void_p),
        ('cbData', wintypes.DWORD),
    ]

file = b'd:\\test.m3u8'
playlist = COPYDATASTRUCT(100, ctypes.cast(ctypes.c_char_p(file), ctypes.c_void_p), len(file)+1)
win32api.SendMessage(hWinamp, win32con.WM_COPYDATA, 0, playlist)
I'm also clearing up the playlist with code (which I did not include in at the above example, and this works).

I also tried:
Code: [Select]
win32api.SendMessage(hwnd, win32con.WM_USER, file, 100)
but this crashes Wacup.

Anyone have an idea what am I doing wrong?


Thanks,
Daniel

dro

  • Admin / WACUP Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 4488
    • View Profile
    • WACUP (Winamp Community Update Project)
Re: How to load a playlist programmatically
« Reply #1 on: October 26, 2021, 01:55:20 PM »
Doing "win32api.SendMessage(hwnd, win32con.WM_USER, file, 100)" won't work as you're not within the WACUP process so when the message is received it's effectively a junk "string" & it's then luck of the draw as to how well that'll work. The applies to a lot of the Winamp apis which unless you're sending an integer value they're not going to work nicely from an externally run application.

From an external tool, WM_COPYDATA is going to be the preferred way to do it as the OS will marshal the handling of the string between the processes. However using the command-line (when it's support is fully working) is often the easier way to do things e.g. wacup.exe /FIND can be used to get the correct HWND to use instead of having to try to figure it out assuming that you've got a known WACUP location to work with.

-dro

daniel_kukiela

  • Beta Tester
  • Full Member
  • ***
  • Posts: 14
    • View Profile
Re: How to load a playlist programmatically
« Reply #2 on: October 26, 2021, 10:12:44 PM »
Thank you for this explanation. It totally makes sense.

I actually implemented it using command line, not without issues too.

1. does not work:
winamp playlist.m3u8
2. does not work:
winamp /ADD playlist.m3u8
3. does not work:
winamp playlist.pls
4. kind of works:
winamp /ADD playlist.pls

Only pls playlist and only while we /ADD it, so the final solution is:
winamp /CLEAR
winamp /ADD playlist.pls
winamp /PLAY

I'm not sure if it's me doing something wrong, it's a bug or it works like this by design.

Attaching a photo of what I have so far (the botto line of buttons are different playlists)


dro

  • Admin / WACUP Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 4488
    • View Profile
    • WACUP (Winamp Community Update Project)
Re: How to load a playlist programmatically
« Reply #3 on: October 26, 2021, 10:29:31 PM »
Command-line support with WACUP is incomplete at the moment whilst I'm transitioning things over to working without the need for the Winamp core. That's the main reason for most of the actions not working correctly / at all.

-dro

daniel_kukiela

  • Beta Tester
  • Full Member
  • ***
  • Posts: 14
    • View Profile
Re: How to load a playlist programmatically
« Reply #4 on: October 26, 2021, 11:31:45 PM »
Makes sense.
I managed to make what I wanted to anyway.


Thanks!