locked
I Need Help Trying to Play (.pls) files in a simple windows forms Application RRS feed

  • Question

  •  So I'm try to build application that when I click on the icon it opens a little window and play the url .pls. I already got the graphics of the app i just to get the code and I've been looking around for but all i got was this code

    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);

    and i got to link it to Wininet.lib

    and I'm a noob so i got problems as soon as i tried to put everything together

    so any help greatly appreciated 

    BTW if you know any other ways, that I'll be able to stream the audio that will be great to.

    heres the link for the audio stream (.pls)

    http://panel3.serverhostingcenter.com:2199/tunein/nrlsxglp.pls

    • Moved by Barry Wang Monday, December 22, 2014 6:30 AM Not winform forum specific, the pls file api may third party
    Sunday, December 7, 2014 8:25 PM

Answers

  • Hello 0cooldex0,

    What library do you used in this scenario? I haven't saw this FSOUND_STREAM from MSDN library.

    By the way, winform general is used for talking about Windows Form library, is is using C# or VB.NET but not C or C++. You are not posting in the right forum.

    In my point of view, you may choose the forum depending on the library you choosed and post on specific forum.

    Regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Barry Wang Monday, December 22, 2014 6:29 AM
    Tuesday, December 9, 2014 2:05 AM