Answered
0
0

Hi,

I tried pls files found on shoutcast.com with fmod player, like
http://www.shoutcast.com/sbin/shoutcast … lename.pls

It says “buffering” but the music doesn’t start.

With local *.pls files there’s no problem. Is there a solution to play
remote *.pls files ?

Thanks.

  • You must to post comments
Best Answer
0
0

Thanks Brett, greatly Fmod 4 ๐Ÿ˜‰

Just for Windows users, a compilation of Fmod sources and MSDN :

Parsing a remote *.pls file and playing it with Fmod :
(needs to be linked with Wininet.lib)

[code:2l4r4vqd]

typedef struct
{
int count;
void **name;
void **displayname;
} Playlist;

Playlist* my_playlist; // SHOUTCAST PLAYLIST

define BOX(text) MessageBox(NULL,text,"Info",MB_OK | MB_TOPMOST);

char *stristr(char *string2, char *string1) // from /samples/fmod/Main.c
{
char *s1 = strdup(string1);
char *s2 = strdup(string2);
char *ret = 0;
int i, j;
int len1 = (int)strlen(string1);
int len2 = (int)strlen(string2);

for (i=0;s1[i];i++) s1[i] = tolower(s1[i]);
for (i=0;s2[i];i++) s2[i] = tolower(s2[i]);

for (j=0;j < (len2 - len1);j++)
{
    char *a = s1;
    char *b = &s2[j];

    for (i=0;(i < len1) && *a && *b;a++, b++, i++)
    {
        if (*a != *b)
        {
            break;
        }
    }

    if (i == len1)
    {
        ret = &string2[j];
        break;
    }
}

free(s1);
free(s2);
return ret;

}

Playlist *ParsePlaylist(char *name) // from /samples/fmod/Main.c and MSDN
{
char *filebuf, *p;
Playlist *playlist = 0;
int count, i;

// Check if URL is null
if (!name)
{
    BOX("Streaming URL is empty");
    return 0;
}

// Check if URL is a *.pls file
if (_stricmp((const char *)".pls", (const char *)(&name[strlen(name) - 4])))
{
    return 0;
}

// Create a WinInet session
HINTERNET hSession = InternetOpen(_T(""), INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);

// Prepare a request
HINTERNET hRequest = InternetOpenUrl(hSession, name, 0, 0, 0, 0);

// Send the HTTP request.
HttpSendRequest(hRequest, 0, 0, 0, 0);

// Read the response data.
DWORD dwNumberOfBytesAvailable = 0;

do
{
    // Retrieve size of remote file
    InternetQueryDataAvailable(hRequest, &dwNumberOfBytesAvailable, 0, 0);

    if (0 < dwNumberOfBytesAvailable)
    {
        // Allocate buffer memory
        filebuf = new char[dwNumberOfBytesAvailable + 1];
        filebuf[dwNumberOfBytesAvailable] = 0;

        DWORD dwBytesRead = 0;

        // Read remote file and put in buffer
        InternetReadFile(hRequest,
                           filebuf,
                           dwNumberOfBytesAvailable,
                           &dwBytesRead);

        //BOX(filebuf);
    }
}
while (0 < dwNumberOfBytesAvailable);

// Close the request handle.
InternetCloseHandle(hRequest);

// Close the WinInet session.
InternetCloseHandle(hSession);

// Parse the pls file (from Fmod sample)
p = stristr(filebuf, "NumberOfEntries=");
if (!p)
{
    BOX("Streaming : NumberOfEntries in pls file not found");
    return 0;
}

p += 16;
count = atoi(p);

if (!count)
{
    BOX("Streaming : numeric value for NumberOfEntries not found");
    return 0;
}

playlist = (Playlist *)calloc(sizeof(Playlist), 1);
if (!playlist)
{
    BOX("Streaming : can't allocate memory for pls file (playlist)");
    return 0;
}

playlist->count = count;

playlist->name = (void **)calloc(sizeof(char *) * count, 1);
if (!playlist->name)
{
    BOX("Streaming : can't allocate memory for pls file (playlist->name)");
    return 0;
}

playlist->displayname = (void **)calloc(sizeof(char *) * count, 1);
if (!playlist->displayname)
{
    BOX("Streaming : can't allocate memory for pls file (playlist->displayname)");
    return 0;
}

for (i=0;i < count;i++)
{
    char tmp[32];
    char *filename, *displayname, *t;

    filename = displayname = 0;

    sprintf(tmp, "File%d=", i + 1);
    p = strstr(filebuf, tmp);
    if (p)
    {
        p += strlen(tmp);
        t = p;
        for (;*t && (*t != 0xa) && (*t != 0xd);t++);
        if (*t)
        {
            char tmpc = *t;
            *t = 0;
            filename = _strdup(p);
            *t = tmpc;
        }
    }

    if (strncmp(filename, "http://", 7) && strncmp(filename, "http:\\\\", 7))
    {
        char *tmpname = _strdup(filename);
        p = &tmpname[strlen(tmpname) - 1];
        for (;(p > tmpname) && (*p != '\\') && (*p != '/');p--);
        if ((*p == '\\') || (*p == '/'))
        {
            p++;
        }
        displayname = _strdup(p);
        free(tmpname);
    }

    playlist->name[i] = filename;
    playlist->displayname[i] = displayname;
}

free(filebuf);
return playlist;

}

[main code]

char string_music[256] = "http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=6042&file=filename.pls"; // For example

// Parse the remote file (in case it’s a Shoutcast playlist (*.pls))
my_playlist = ParsePlaylist(string_music);

if (my_playlist)
strcpy(string_music, (char*) my_playlist->name[0]); // for the first song in the playlist

FSOUND_STREAM * my_stream = FSOUND_Stream_Open(string_music, FSOUND_NORMAL | FSOUND_NONBLOCKING, 0, 0);
int int_sound_mp3 = FSOUND_Stream_Play(FSOUND_FREE, my_stream);

[/code:2l4r4vqd][code]

  • You must to post comments
0
0

ok, it’s what i thought. Thanks for your response.

In fact i must say “remote shoutcast playlist”, sorry for that.

Thanks for your great product ๐Ÿ˜‰

  • You must to post comments
0
0

This is an old post, but I was curious if anybody had a C# variation of the same type of parser for .PLS files.

I’d rather not have to reinvent the wheel when I know somebody has taken time to do it.

If not, then I suppose porting this one over won’t be too bad

  • dexter
    I'm trying to find a way to play .pls files (streaming audio from a site) by a simple application i got the windows forms all setup just need to do the code and having trouble finding a to play the .pls and stream audio
  • You must to post comments
0
0

I’m trying to find a way to play .pls files (streaming audio from a site) by a simple application i got the windows forms all setup just need to do the code and having trouble finding a to play the .pls and stream audio, Any insight will be appreciated.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.