Click here to Skip to main content
6,290,721 members and growing! (2,901 online)
Email Password   helpLost your password?
Multimedia » Audio and Video » General     Beginner License: The Code Project Open License (CPOL)

Windows Media Player meets Shoutcast

By Ladislav Nevery

How to play *.pls internet radios / files in Windows Media Player
C++
Posted:6 Jul 2008
Views:10,624
Bookmarked:6 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
6 votes for this article.
Popularity: 1.95 Rating: 2.50 out of 5
3 votes, 50.0%
1

2
2 votes, 33.3%
3

4
1 vote, 16.7%
5
Get it from CNET Download.com!

Introduction

Let's face it Windows Media Player looks sexy but what is more important it sounds a lot better than any other overskinned overpluggined monster out there. At least for me ;) Now it can't open pls files but can play any stream addresses contained in them due to some weird marketing decission. So the sollution is to get url from pls file and pass it to the player as commandline parameter

So here is simple utility to open and play internet streams or files contained in popular *.pls playlist format in Windows Media Player by simply clicking on interned radios in web browser.

How to Use

When you click on any radio on internet radio sites like www.shoutcast.com web browser usually asks in which program to open *.pls files. Just browse to pls2wmp.exe utility downloaded from this page (or compile it from provided source code) and mark Allways use check box. But if browser doesn't ask it usually means that pls file is associated with different program. In that case Hold Shift and right click on any downloaded pls file. -> Open with -> Choose Program -> browse for and select pls2wmp.exe -> check Always use selected .... checkbox. And voila all internet radios now open Windows Media Player.

The Source Code

Well the code si very simple. It opens pls file and passes first found url/file path to launched windows media player as parameter.

To make it little bit less boring it demonstrates how to read and process files without usual check file size -> allocate -> copy memory mantra. Windows does all for us. How it works? Everytime we first time touch the page sized memory (4096 bytes) via pointer returned from MapViewOfFile windows internaly generates exception that allocates page -> copies data from file. But this is all transparent to us so we just read this pointer and let the windows do the dirty job. Another advantage of this approach is that only parts of file that are accessed are allocated/transfered. So offset based operations on multi gigabyte files are extremly fast. I used PAGE_WRITECOPY which means that if we try to modify data windows allocates another temporary memory where he holds just changes without writing changes back to file.

But main purpose of this article is to share new way of listening to internet radios on sites like www.sky.fm or www.shoutcast.com or www.live365.com also in Windows Media Player.

That's it format it the way you like it and enjoy the better sounding music. ;)
#include <windows.h>
#include <stdio.h>

CALLBACK WinMain( HINSTANCE inst, HINSTANCE prev, char* cmd, int show ) {   
    int len = strlen(cmd);
    if(!len) return -1; cmd++;
    if(cmd[len-2]=='"') cmd[len-2]=0;

    HANDLE file = CreateFile(cmd,GENERIC_READ,1,0,OPEN_EXISTING,0,0); if(file==INVALID_HANDLE_VALUE) return -1;
    HANDLE map  = CreateFileMapping(file,0,PAGE_WRITECOPY,0,10,0);    if(!map) return -1;
    char*  url  = (char*)MapViewOfFile(map,1,0,0,0);                  if(!url) return -1;
           url  = strstr(url,"ile");                                  if(!url) return -1;
           url  = strchr(url,'='  );                                  if(!url) return -1;
    char*  end  = strchr(url,'\n' );                                  if( end) *end = 0;

    ShellExecute(0,"open","wmplayer",url+1,0,SW_SHOW);
    UnmapViewOfFile(url);

    CloseHandle(file);
    CloseHandle(map);
    return 0;
}
     

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ladislav Nevery


Member
Past Projects:
[Siemens.sk]Mobile network software: HLR-Inovation for telering.at (Corba)
Medical software: CorRea module for CT scanner
[cauldron.sk]Computer Games:XboxLive/net code for Conan, Knights of the temple II, GeneTroopers, CivilWar, Soldier of fortune II
[www.elveon.com]Computer Games:XboxLive/net code for Elveon [new game based on Unreal Engine 3]
Occupation: Software Developer (Senior)
Location: Slovakia Slovakia

Other popular Audio and Video articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
GeneralCan You Allow it to Also Pull ID3 Tag Info from Shoutcast Stream Pinmembereist119:19 30 Jul '08  
GeneralGreat Tool PinmemberMember 370984617:08 16 Jul '08  
GeneralYou realy annoy me PinmemberMrGoodly10:48 6 Jul '08  
GeneralRe: You realy annoy me [modified] PinmemberLadislav Nevery13:31 6 Jul '08  
GeneralRe: You realy annoy me PinmemberJim Crafton4:50 7 Jul '08  
GeneralRe: You realy annoy me PinmemberJim Crafton5:24 7 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 6 Jul 2008
Editor:
Copyright 2008 by Ladislav Nevery
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project