Click here to Skip to main content
11,639,861 members (60,006 online)
Click here to Skip to main content

Embedded Media Player with hot key controls and adding play list capability (ASX file)

, 25 Nov 2006 CPOL 119.2K 1.3K 19
Rate this:
Please Sign up or sign in to vote.
How to add Windows Media Player in your web site. Adding play list capability and activation of Hot Key controls.

Sample Image - myrshewmp.jpg

Introduction

This is a simple example that will elaborate how to embed the Windows Media Player in your web pages. And I will explain how to make a play list (ASX file) that you can use to play in the Embedded Windows Media Player. I have also implemented the functionality of Hot Keys that you can use from your keyboard.

Making a Playlist (ASX File)

What is an ASX file? It is a Windows Media container file. ASX is a metafile that provides information about media files, including descriptions of multimedia content, and contains the URLs for the streams. This will enable you to add more than one song on your Embedded Media player. You can use it to create a play list for both your audio and video files.

  • Open MS Notepad
  • Copy and paste the code below in Notepad [Ctrl+c - Ctrl+v]
  • <ASX  Version="3.0">
       <title>NAME  OF MUSIC LIST</title>
       <entry>
       <title>NAME  OF SONG</title>
       <author>NAME OF ARTIST</author>
       <Ref href="THE URL OF THE MUSIC/VIDEO FILE"/>
       </entry> 
    </asx>
  • Replace NAME OF MUSIC LIST with the name of the music list. [E.g., My Playlist or My Songs].
  • Replace NAME OF SONG and NAME OF ARTIST with what they say. [E.g., aab k humbichre, Mehdi Hasan].
  • Now replace THE URL OF THE MUSIC/CIDEO FILE with the URL of the song/video. You can host your songs on many hosting services and get the URL or the www address.
  • Also, you can Google for videos or audio files already on the internet and get the URL.
  • To add more songs to the play list, copy the code from <entry> to </entry> and make the necessary changes in the URL and names of songs.
  • Save the file [on Notepad] as “sample.asx”.
  • Upload this file "sample.asx" to a hosting service.
  • You are done!!
  • It is necessary that you carry out each step carefully. It worked for me, and it should do for you too. Any easier than this and it will lose its essence.

Using the Code

After making your ASX play list, the next step is to place the following code in your web page by using any of the editors.

Place the following code in your head section of the HTML page:

<SCRIPT>
<!--
        var WMState = new Array();
        WMState[0]  = "Undefined"; 
        WMState[1]  = "Stopped"; 
        WMState[2]  = "Paused"; 
        WMState[3]  = "Playing"; 
        WMState[4]  = "Scan Forward"; 
        WMState[5]  = "Scan Reverse"; 
        WMState[6]  = "Buffering"; 
        WMState[7]  = "Waiting"; 
        WMState[8]  = "Media Ended"; 
        WMState[9]  = "Transitioning"; 
        WMState[10] = "Ready"; 
        WMState[11] = "Reconnecting";

        function Status () {
            x = Player.playState; 
            alert("Windows Media Player is " + WMState[x] + "\r\r" + 
                  "Player Version:" + Player.versionInfo);
        } 
        function Play () {
            x = Player.playState;
            if (x == 2) {
                Player.controls.play();
            } else {
                Player.URL = "sample1.asx";
            }          
        }
        function Pause () {
            Player.controls.pause();          
        } 
        function Stop () {
            Player.controls.stop();
        }
        function MuteMe () {
            x = Player.settings.mute;
            if (x == 0) {
                Player.settings.mute = "1";
            } else {  
                Player.settings.mute = "0"; 
            } 
        } 
        function UnMuteMe () { 
            Player.settings.mute = "0"; 
        } 
        function VolumeUp () { 
            X = Player.settings.volume; 
            Player.settings.volume = X + 10;      
        }
        function VolumeDown () {
            X = Player.settings.volume; 
            Player.settings.volume = X - 10; 
        }
-->
</SCRIPT>

And then place the following code in the body tag of the HTML page:

<OBJECT  ID="Player" width="320" height="300" 
         CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
  <PARAM name = "Volume"  value="50">
  <PARAM name = "AutoStart"  value="True">
</OBJECT>
<BR><BR> 
<INPUT TYPE="BUTTON" NAME="BtnPlay"    VALUE="Play"     accesskey=p  OnClick="Play()"> 
<INPUT TYPE="BUTTON" NAME="BtnPause"   VALUE="Pause"    accesskey=p  OnClick="Pause()"> 
<INPUT TYPE="BUTTON" NAME="BtnStop"    VALUE="Stop"     accesskey=s  OnClick="Stop()"> 
<INPUT TYPE="BUTTON" NAME="BtnMute"    VALUE="Mute"     accesskey=m  OnClick="MuteMe()"> 
<INPUT TYPE="BUTTON" NAME="BtnUnMute"  VALUE="UnMute"   accesskey=m  OnClick="UnMuteMe()"> 
<INPUT TYPE="BUTTON" NAME="BtnVolUp"   VALUE="VolUp"    accesskey=u  OnClick="VolumeUp()"> 
<INPUT TYPE="BUTTON" NAME="BtnVolDown" VALUE="VolDown"  accesskey=z  OnClick="VolumeDown()">

And that’s it. You are done!

Note: CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" is the ID for the version of the media player that will be embedded. You can change it according to the version you are using.

Hot Keys for this Embedded Media Player

  • Alt+P --> Play
  • Alt+P --> Pause
  • Alt+M --> Mute
  • Alt+M --> Unmute
  • Alt+U --> Volume up
  • Alt+Z --> Volume down

History

I will try to keep a running update of any changes or improvements. Thanks.

License

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

Share

About the Author

Sabah u Din Irfan
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionEmbedded Media Player with hot key Controls & Adding Play List capability(ASX FILE) Pin
SMARTDeveloper78611-Nov-09 15:41
memberSMARTDeveloper78611-Nov-09 15:41 
QuestionZoom option is not working Pin
Surya Prakash23-Sep-08 2:02
memberSurya Prakash23-Sep-08 2:02 
GeneralThanks Pin
ygrao25-Jul-08 19:44
memberygrao25-Jul-08 19:44 
QuestionRe: Thanks Pin
Member 56468677-Nov-08 17:55
memberMember 56468677-Nov-08 17:55 
GeneralFeedback on this article Pin
ygrao25-Jul-08 19:40
memberygrao25-Jul-08 19:40 
GeneralPlaylist Not Showing Pin
azeo12-Oct-07 13:41
memberazeo12-Oct-07 13:41 
GeneralHelp; Embeded WMV & MP3 Players not working for Firefox! Pin
CanaanMedia.com3-Oct-07 9:20
memberCanaanMedia.com3-Oct-07 9:20 
Generalthank you Pin
topequa227-Jun-07 9:09
membertopequa227-Jun-07 9:09 
GeneralRe: thank you Pin
Sabah u Din Irfan29-Jun-07 8:26
memberSabah u Din Irfan29-Jun-07 8:26 
QuestionVideo Appears Small in IE7 Pin
kaanuki24-Jun-07 11:33
memberkaanuki24-Jun-07 11:33 
AnswerRe: Video Appears Small in IE7 Pin
Sabah u Din Irfan29-Jun-07 8:21
memberSabah u Din Irfan29-Jun-07 8:21 
GeneralAccess denied on asx file Pin
LMoody11-May-07 12:26
memberLMoody11-May-07 12:26 
QuestionMore control? Pin
aluatrill4-May-07 12:10
memberaluatrill4-May-07 12:10 
GeneralIt keeps connecting but then saying "ready" Pin
Esstay4-May-07 1:26
memberEsstay4-May-07 1:26 
GeneralRe: It keeps connecting but then saying "ready" Pin
Sabah u Din Irfan29-Jun-07 8:25
memberSabah u Din Irfan29-Jun-07 8:25 
GeneralRe: It keeps connecting but then saying "ready" Pin
CanaanMedia.com3-Oct-07 10:33
memberCanaanMedia.com3-Oct-07 10:33 
GeneralRe: It keeps connecting but then saying "ready" Pin
joyjjjz3-Sep-08 1:06
memberjoyjjjz3-Sep-08 1:06 
GeneralRe: It keeps connecting but then saying "ready" Pin
ramgarhia23-Jan-09 4:08
memberramgarhia23-Jan-09 4:08 
QuestionHow to embed video? Pin
passatgt29-Apr-07 3:16
memberpassatgt29-Apr-07 3:16 
Generalevent detecting Pin
marcello3d12-Apr-07 23:38
membermarcello3d12-Apr-07 23:38 
GeneralRe: event detecting Pin
Sabah u Din Irfan18-Apr-07 8:02
memberSabah u Din Irfan18-Apr-07 8:02 
QuestionProblem in Mozilla Firebox???? Pin
sri baski3-Apr-07 2:28
membersri baski3-Apr-07 2:28 
AnswerRe: Problem in Mozilla Firebox???? Pin
Sabah u Din Irfan3-Apr-07 7:50
memberSabah u Din Irfan3-Apr-07 7:50 
GeneralRe: Problem in Mozilla Firebox???? Pin
sri baski6-Apr-07 0:34
membersri baski6-Apr-07 0:34 
QuestionOne question regarding embedded video Pin
Esstay26-Mar-07 0:50
memberEsstay26-Mar-07 0:50 
AnswerRe: One question regarding embedded video Pin
Sabah u Din Irfan27-Mar-07 9:31
memberSabah u Din Irfan27-Mar-07 9:31 
GeneralRe: One question regarding embedded video Pin
Sabah u Din Irfan27-Mar-07 9:46
memberSabah u Din Irfan27-Mar-07 9:46 
GeneralRe: One question regarding embedded video Pin
Esstay29-Mar-07 22:43
memberEsstay29-Mar-07 22:43 
QuestionI am a 'Dummy' Pin
BigKevSter25-Mar-07 0:56
memberBigKevSter25-Mar-07 0:56 
QuestionLink to any point within the Embedded Player Pin
Topsey Krits12-Mar-07 5:52
memberTopsey Krits12-Mar-07 5:52 
Generalbrilliant script just a quick question... Pin
bigbobed21-Feb-07 5:49
memberbigbobed21-Feb-07 5:49 
Generalproblems.... Pin
DaTaddd9-Feb-07 13:28
memberDaTaddd9-Feb-07 13:28 
GeneralRe: problems.... Pin
Sabah u Din Irfan12-Feb-07 9:50
memberSabah u Din Irfan12-Feb-07 9:50 
QuestionNot working in IE7? Pin
robertwertheim26-Jan-07 5:29
memberrobertwertheim26-Jan-07 5:29 
AnswerRe: Not working in IE7? Pin
Sabah u Din Irfan26-Jan-07 9:39
memberSabah u Din Irfan26-Jan-07 9:39 
GeneralAnother Embeded player in Web Browser Pin
Sabah u Din Irfan25-Jan-07 5:22
memberSabah u Din Irfan25-Jan-07 5:22 
GeneralASX list and player Pin
gary711-Dec-06 5:16
membergary711-Dec-06 5:16 
GeneralRe: ASX list and player Pin
Sabah u Din Irfan11-Dec-06 10:34
memberSabah u Din Irfan11-Dec-06 10:34 
GeneralRe: ASX list and player Pin
Sabah u Din Irfan11-Dec-06 10:40
memberSabah u Din Irfan11-Dec-06 10:40 
GeneralRe: ASX list and player Pin
gary711-Dec-06 17:02
membergary711-Dec-06 17:02 
GeneralRe: ASX list and player Pin
Sabah u Din Irfan12-Dec-06 9:26
memberSabah u Din Irfan12-Dec-06 9:26 
GeneralRe: ASX list and player Pin
gary713-Dec-06 4:07
membergary713-Dec-06 4:07 
GeneralRe: ASX list and player Pin
Sabah u Din Irfan20-Dec-06 12:15
memberSabah u Din Irfan20-Dec-06 12:15 
GeneralRe: ASX list and player Pin
donsepeda1-Feb-07 15:49
memberdonsepeda1-Feb-07 15:49 
GeneralRe: ASX list and player Pin
Sabah u Din Irfan12-Feb-07 9:51
memberSabah u Din Irfan12-Feb-07 9:51 
QuestionDifferent Windows Media Player Pin
Meghan085417-Apr-08 4:47
memberMeghan085417-Apr-08 4:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150731.1 | Last Updated 25 Nov 2006
Article Copyright 2006 by Sabah u Din Irfan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid