Instant Music Player for IE

You must have met such a situation: you've got a hyper-link of some music and you want to have a taste of it, but it may be large enough that you don't want to download.Or - you just want to listen to the music online. -- In a word, Baidu MP3 doesn't work everywhere. So you may need an INSTANT web music player to play the music links without downloading them first.

 

I wrote a small tool as the extension of Internet Explorer to faciliate the function mentioned above - when you found a song's link, righ click on the link and choose the option we've added by this tool, and then you can start a player to enjoy.

 

Here're the main steps:

 

1. Config the registry

 

Write a .reg file like this:

 

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/MenuExt]
[HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/MenuExt/Listen Now!]
@="C:/Program Files/MyListener/start.html"

 

The blue ones are what IE uses as its right button extension, and the red parts are what we are about to config. "Listen Now!" is the name you want to see from the context menu; the html address is the page for handling the click event, as step 2.

 

2. Setup the event logic

 

Following step 1,we need to implement the html page we indicated because this page will be executed(or, interpreted) after your right click. In this page, you need to grabs the music URL and its name :

 

<script language="javascript">

function OnContextMenu()
{
    var srcEvent = external.menuArguments.event;
    var EventElement;
 
  if(typeof(srcEvent.clientX) == "undefined")
    {
        EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.pointerX, srcEvent.pointerY );
    }
    else
    {
        EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.clientX, srcEvent.clientY );
    }
     
    // These parameters don't work for IE7/IE8
  window.open ("listen.html?url="+EventElement.href+"&txt="+EventElement.innerText, "MUSICBOX", "height=100,width=100,status=yes,toolbar=yes, menubar=no, location=no");
}

OnContextMenu();

</script>

 

OnContextMenu() is the call-back function for your right clicking event, and you should retrieve the parameters through external.menuArguments.document.elementFromPoint and open the player windows(listern.html which we'll complete in step 3) with the parameters, using window.open().

 

3. Setup the player page

 

The player page is a common html file.

 

Now we are proceeding to the final step - the player page, in which there are two things you need to finish:


a) Get the parameters


//  Get Parameters

function getParam(paramName)
{
  var ret='';
  var url=window.location.search;
  if(url.indexOf("?")!=-1)
  {
    var str = url.substr(1)
    strs = str.split("&");
   
    for(i=0;i<strs.length;i++)
    {
      if([strs[i].split("=")[0]]==paramName)
        ret=unescape(strs[i].split("=")[1]);
    }
  }
 
  return ret;
}

//  Construct a endWith method
String.prototype.endWith=function(str){
  if(str==null||str==""||this.length==0||str.length>this.length)
    return false;
  if(this.substring(this.length-str.length)==str)
    return true;
  else
    return false;
  return true;
}

 

getParam() is to retrieve the request string to get the parameters back - the param name could be indicated by us. The second part is kinda an extension to JavaScript String objs, the endWith() method we added is to be used for judge the music format - remember windows media player cannot play .rm files. Now it's the final strike:

 

b) Start the player plugins


//  1. Get song URL
var music_url = getParam('url');
var text = getParam('txt');

//  2. Choose the right player
var player_str = '';
if(music_url.endWith("rm"))
  player_str = '<embed id="RealPlayer1" autogotourl=false type="audio/x-pn-realaudio-plugin" src="'+ music_url +'" controls="ControlPanel,StatusBar" ' +
               'width=350 height=68 border=0 autostart=true loop=true></embed> <noembed>please install RealPlayer!</noembed>'
;
else
  player_str =   '<object id="MediaPlayer1" width="350" height="64" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"' +
                 ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" ' +
                 'align="baseline" border="0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">' +
                 '<param name="URL" value="'+ music_url +'"><param name="autoStart" value="true"><param name="invokeURLs" value="false">' +
                 '<param name="playCount" value="100"><param name="defaultFrame" value="datawindow">' +
                 '<embed src="1.mp3" align="baseline" border="0" width="350" height="68" type="application/x-mplayer2"pluginspage="" ' +
                 'name="MediaPlayer1" showcontrols="1" showpositioncontrols="0" showaudiocontrols="1" showtracker="1" showdisplay="0" showstatusbar="1" ' +
                 'autosize="0" showgotobar="0" showcaptioning="0" autostart="1" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" ' +
                 'enablecontextmenu="1" clicktoplay="0" defaultframe="datawindow" invokeurls="0"></embed></object>'
;

 

If it is not a rm file, let's start Windows Media Player; or RealPlayer will be the right choice.

 

All is done. It is really easy isn't? You don't even have to open some IDE to compile something. But your life will be much easier now. I benefit from it a lot at least for there's a great religious music web site I love so much doesn't offer online playing...

 

P.S. At last, you can use SetupFactory to publish this tool. But please note that this only works for IE, so for the FireFox users we may need more work.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值