Supplying an icon/image to the ShowMessage function call

14 views
Skip to first unread message

George

unread,
Nov 10, 2009, 1:33:07 AM11/10/09
to Snarl Discussion
I am in the process of writing a plugin for Winamp to interface with
Snarl. I know one exists already, but it doesn't work with non-Latin
characters which I really don't like. Also, it doesn't do a good job
with album art, so I decided to write my own. It already works with
non-Latin characters which is awesome, but I am having trouble with
album art.

I'm not sure if I get the API correctly, but it seems the icon needs
to exist as a file somewhere, instead of an in-memory buffer. I guess
passing the whole image through SendMessage() would be really heavy?
Is my only option to save the album art to a thumbnail somewhere in a
temp file and sending the path to that to Snarl?

Cheers,
George

Sven Walther

unread,
Nov 10, 2009, 2:34:06 AM11/10/09
to snarl-...@googlegroups.com
Hi George,

you are absolutly right - images are provided only using a file path or
(since 2.21) as an URL. So if you donn't have access to an already
existing caching place where the album is stored (I assume it's within
the MP3, is it?) you need to store it somewhere temporarily.

Looking forward for your plugin :)

Cheers

Sven

miguel.mateo

unread,
Nov 10, 2009, 9:07:21 AM11/10/09
to Snarl Discussion
George,

Do you mind posting a slice of the changes you did to accept non Latin
characters? A simple portion of the code will do.

Thanks,
Miguel

George

unread,
Nov 10, 2009, 10:21:12 AM11/10/09
to Snarl Discussion
Hi Miguel,

I plan to release all the code eventually, don't worry. =)

I'm not sure what 'changes' you're talking about. All it takes for non-
Latin to work is to handle strings in wchar_t* at all times instead of
char*. On the Winamp side, I make sure to use the message
IPC_GET_EXTENDED_FILE_INFOW. Notice that it ends in 'W'. That ensures
that Winamp will return a wchar_t based string. There is a
IPC_GET_EXTENDED_FILE_INFO message as well, which doesn't support
Unicode. Next, I have to send it on to Snarl with the
SnarlInterface::ShowMessage method which is defined for both char and
wchar_t, so it just works when I pass it the string I receive from
Winamp.

Here's some code.

//do_once = false;
wchar_t *filename = (wchar_t*)SendMessage
(plugin.hwndParent,WM_WA_IPC,0,IPC_GET_PLAYING_FILENAME);

extendedFileInfoStructW song_data;
// sigh, it has to be a hard coded length...
// this means that things longer than that
// will just get truncated which I guess is
// fine.
const int buffer_length = 256;

wchar_t title[buffer_length] = L""; bool success_title =
false;
wchar_t artist[buffer_length] = L""; bool success_artist =
false;
wchar_t album[buffer_length] = L""; bool success_album =
false;

wchar_t snarl_notification_title[buffer_length] = L"";
wchar_t snarl_notification_text[buffer_length] = L"";

wchar_t buffer[buffer_length];
song_data.filename = filename;
song_data.metadata = L"title";
song_data.ret = buffer;
song_data.retlen = buffer_length;

// ask for the infoz
// returns 1 if the decoder supports a getExtendedFileInfo
method
static const int WINAMP_SUCCESS = 1;
if (SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)
&song_data,IPC_GET_EXTENDED_FILE_INFOW) == WINAMP_SUCCESS) {
success_title = true;
wcscpy_s(title, buffer);
}

song_data.metadata = L"artist";
// ask for the infoz
if (SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)
&song_data,IPC_GET_EXTENDED_FILE_INFOW) == WINAMP_SUCCESS) {
success_artist = true;
wcscpy_s(artist, buffer);
}

song_data.metadata = L"album";
// ask for the infoz
if (SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)
&song_data,IPC_GET_EXTENDED_FILE_INFOW) == WINAMP_SUCCESS) {
success_album = true;
wcscpy_s(album, buffer);
}

snarl->ShowMessage(artist, title, 3, L"C:\\Program Files\
\Winamp\\Plugins\\notfound.png");

This runs when a new song has just come up.

Cheers,
George

Chris Peel

unread,
Nov 17, 2009, 3:28:22 AM11/17/09
to snarl-...@googlegroups.com

For images, at the moment it must physically exist on a filesystem
somewhere (URLs are now supported however). I have experimented with
in-memory images but the variety of formats (GDI DIB, GDI DDB, GDI+
Image, etc.) would mean a fair amount of coding/decoding would need to
take place (and, you're right, passing even a few hundred KB via
WM_COPYDATA is not recommended). You can always download the icon to
the user's %TEMP% folder with a static filename so it overwrites the
previous one there, or simply record the names of the icons you've
used and tidy them up when your app/plugin quits.

George

unread,
Nov 18, 2009, 10:00:42 AM11/18/09
to Snarl Discussion
That's exactly what I ended up doing - use the temp folder. Works
great.
Reply all
Reply to author
Forward
0 new messages