分享
 
 
 

关于WEB使用media player的一些说明

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Simple Example of Scripting in a Web Page

You can easily embed the Windows Media Player control in an HTML file using any scripting language your browser recognizes. The following simple example uses Microsoft JScript to create a page that will play a file when you click on a button, and stop playing the file when you click on another button.

You can embed the Windows Media Player ActiveX control in a Web page using the following four steps:

Create the Web page.

Add the OBJECT tag.

Add a user interface. In this case, two buttons.

Add a few lines of code to respond when the user clicks on one of the buttons you have created.

Creating the Web Page

The first step is to create a valid HTML Web page. The following code is the minimum needed to create a blank but valid HTML page:

<HTML>

<HEAD>

</HEAD>

<BODY>

</BODY>

</HTML>

Adding the OBJECT Tag

Once you have created a Web page, you need to add an OBJECT tag. This identifies the ActiveX control to the browser and sets up any initial definitions. You must place the OBJECT tag in the BODY of the code. If you place it in the BODY, the default user interface of Windows Media Player will be visible. If you want to create your own user interface, set the height and width attributes to 0 (zero). You can also set the Player.uiMode property to "invisible" when you want to hide the control, but still reserve space for it on the page. The following code is recommended when you provide a custom user interface:

<OBJECT ID="Player" height="0" width="0"

CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">

</OBJECT>

The following OBJECT tag attributes are required:

ID

The name that will be used by other parts of the code to identify and use the ActiveX control. You can choose any name you want, as long as it is a name that is not already used by HTML, HTML extensions, or the scripting language you are using. In this example, the name Player is used, but you could also call it MyPlayer or something else. Just pick a name that is unique to that Web page.

CLASSID

A very large hexadecimal number that is unique to the control. Only one control has this number and it is the Windows Media Player ActiveX control. To prevent typographical errors, you can copy and paste this number from the documentation. Versions of the Windows Media Player control prior to version 7.0 had a different CLASSID.

Adding a User Interface

HTML allows a vast wealth of user interface elements, allowing the user to interact with your Web page by clicking, pressing keys, and other user actions. Adding a few INPUT buttons is the easiest way to provide a quick user interface. The following code creates two buttons that can respond to the user. Clicking one button starts the media stream playing and the other button stops it:

<INPUT TYPE="BUTTON" NAME="BtnPlay" VALUE="Play" OnClick="StartMeUp()">

<INPUT TYPE="BUTTON" NAME="BtnStop" VALUE="Stop" OnClick="ShutMeDown()">

The name of the button is used to identify the button to your code; the value is the label that will appear on the button, and the OnClick attribute identifies which part of your scripting code will be called when the button is clicked.

Adding Scripting Code

Scripting code adds interactivity to your page. Scripting code can respond to events, call methods, and change run-time properties. Extended scripts are enclosed in a SCRIPT tag set. The SCRIPT tag tells the browser where your scripting code is and identifies the scripting language. If you do not identify a language, the default language will be Microsoft JScript.

It is good authoring practice to enclose your script in HTML comment tags so browsers that do not support scripting do not render your code as text. Put the SCRIPT tag anywhere within the BODY of your HTML file and embed the comment-surrounded code within the opening and closing SCRIPT tags.

The following Microsoft JScript code example calls the Windows Media Player control and performs an appropriate action in response to the corresponding button click.

<SCRIPT>

<!--

function StartMeUp ()

{

Player.URL = "laure.wma";

}

function ShutMeDown ()

{

Player.controls.stop();

}

-->

</SCRIPT>

The example function, StartMeUp, is called when the button marked Play is clicked, and the ShutMeDown function is called when the Stop button is clicked.

The code inside StartMeUp uses the URL property to define a path to the media. The media will start playing immediately.

The ShutMeDown code calls the stop method of the Controls object. Note that the Controls object is called through the controls property of the Player object, which has the ID value of "Player".

The following code shows a complete example.

<HTML>

<HEAD>

</HEAD>

<BODY>

<OBJECT ID="Player" height="0" width="0"

CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">

</OBJECT>

<INPUT TYPE="BUTTON" NAME="BtnPlay" VALUE="Play" OnClick="StartMeUp()">

<INPUT TYPE="BUTTON" NAME="BtnStop" VALUE="Stop" OnClick="ShutMeDown()">

<SCRIPT>

<!--

function StartMeUp ()

{

Player.URL = "laure.wma";

}

function ShutMeDown ()

{

Player.controls.stop();

}

-->

</SCRIPT>

</BODY>

</HTML>

Note that you must provide a valid URL to a valid file name in the URL property. In this case the assumption is that the file laure.wma is in the same directory as the HTML file.

这个是从MSDN的SDK中copy的一段,不过说明了一些问题,比如说play和stop的问题,这个在WEB的ASP版常常看到的MEDIA PLAYER 的问题,这个很容易说明的用mediaid.controls.play()和media.control.stop();加以控制

Controls.currentItem

The currentItem property specifies or retrieves the current media item.

Syntax

player.controls.currentItem

Possible Values

This property is a read/write Media object.

Remarks

This method works only with items in Player.currentPlaylist. Calling currentItem with a reference to a saved media item is not supported.

Example Code

The following JScript example uses currentItem to set the player control current media item to the selected value in an HTML SELECT element. The current playlist was first specified by using PlaylistCollection.getByName. The Player object was created with ID = "Player".

<SELECT ID = playItem NAME = "playItem" LANGUAGE = "JScript"

/* Specify the current item when the selected list value changes. */

onChange = "Player.controls.currentItem = Player.currentPlaylist.item(playItem.value);">

/* Fill the SELECT element list with three items that match

the songs in the playlist. */

<OPTION VALUE = 0 >Laure

<OPTION VALUE = 1 >Jeanne

<OPTION VALUE = 2 >House

</SELECT>

Controls.currentItemThe currentItem property specifies or retrieves the current media item.

Syntax

player.controls.currentItem

Possible Values

This property is a read/write Media object.

Remarks

This method works only with items in Player.currentPlaylist. Calling currentItem with a reference to a saved media item is not supported.

Example Code

The following JScript example uses currentItem to set the player control current media item to the selected value in an HTML SELECT element. The current playlist was first specified by using PlaylistCollection.getByName. The Player object was created with ID = "Player".

<SELECT ID = playItem NAME = "playItem" LANGUAGE = "JScript"

/* Specify the current item when the selected list value changes. */

onChange = "Player.controls.currentItem = Player.currentPlaylist.item(playItem.value);">

/* Fill the SELECT element list with three items that match

the songs in the playlist. */

<OPTION VALUE = 0 >Laure

<OPTION VALUE = 1 >Jeanne

<OPTION VALUE = 2 >House

</SELECT>

显然controls有很多东西,我们可以控制的也很多

Controls.nextThe next method sets the current item to the next item in the playlist.

Syntax

player.controls.next()

Parameters

This method takes no parameters.

Return Values

This method does not return a value.

Remarks

If the playlist is on the last entry when next is invoked, the first entry in the playlist will become the current one.

For server-side playlists, this method skips to the next item in the server-side playlist, not the client playlist.

When playing a DVD, this method skips to the next logical chapter in the playback sequence, which may not be the next chapter in the playlist. When playing DVD stills, this method skips to the next still.

Example Code

The following example creates an HTML BUTTON element that uses next to move to the next item in the current playlist. The Player object was created with ID = "Player".

<INPUT TYPE = "BUTTON" ID = "NEXT" NAME = "NEXT" VALUE = ">>|"

onClick = "

/* Check first to be sure the operation is valid. */

if (Player.controls.isAvailable('Next'))

/* Move to the next item in the playlist. */

Player.controls.next();

">

所有这些在微软的sdk中都有的,大小为10M,可以下载很方便的

这里仅仅写了WEB的script中的一些用法,用VB VC一样可以控制的,controls显然是很方便的

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有