How to play multiple files embedded in Windows Media Player

Source: Internet
Author: User

Embedded media player on the webpage is simple. You can complete a simple player with the following code:

 <! Doctype  HTML public  "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  > <Html  Xmlns  =  Http://www.w3.org/1999/xhtml"  > <Head> <Meta  Content  =  "Text/html; charset = UTF-8"  HTTP-equiv  =  "Content-Type" /> <Title>  Audio Player  </Title>   Height  =  "200"  Type  =  "Video/X-MS-WMV"  Width  =  "200"  > <Param  Name  =  "FILENAME"  Value =  "C: \ Users \ skyd \ music \ Groove Coverage \ far away from home. MP3"  /> <Param  Name  =  "Autostart"  Value  =  "True"  /> <Param  Name  =  "Loop"  Value  =  "True" /> </Object> </body>  

Running effect:

 

How can I enable the player to play multiple audio/video files?

You cannot directly add multiple filename parameters to HTML for multi-file playback. You can create a playback list and point the filename parameter to the position of the playback list.

The following C #CodeCreates a playlist file supported by Windows Media Player:

 Public static void  Generate an ASX music playlist file (  String  Storage path,  Params string  [] File path list ){  Stringbuilder  S  = New  Stringbuilder  ();  Foreach  (  VaR  F  In  File Path list) {s  .  Appendline (  String  .  Format (  @ "<Entry> <ref href =" "{0}"/> </entry>"  , F ));} Streamwriter  SW  =  New  Streamwriter  (Storage path,  False  ,  Encoding  .  Default); SW  .  Write (  String  .  Format (  @ "<ASX version =" "3.0" "> {0} </ASX>" , S); SW  .  Close ();} 

Note that:

Encoding should be default (in simplified Chinese system default is equivalent to gb2312), UTF-8, Unicode and so on are not good, ASCII can, but does not support Chinese path.

The music file name can be a local path or URL, either absolute or relative path. If it is a local path, URL encoding is not required.

The file name of the saved playlist is preferably set to. ASX. Otherwise, the player may not recognize it.

 

How to play a song in random (out of order?

You cannot specify out-of-order playback behaviors in HTML by using parameters. You can use a work und to clone N parts of the playback list, disrupt the order, and combine them into a new large playback list, randomizes playback.

Here we provide a simple extension method to disrupt the set:

 
StaticRandomR=NewRandom();
/// <Summary> ///  Returns the random sorted set.  /// </Summary>  Public static  Ienumerable  <  T  >  Random  <  T  >  (  This  Ienumerable  <  T >  O ){  VaR  C  =  O  .  Count ();  VaR  L  =  New  List  <  Int  >  ();  For (  Int  I  =  0  ; I  <  C; I  ++  ) {L  .  Add (I );}  While  (L  .  Count  >  0 ){  VaR  I  =  L [R  .  Next (L  .  Count)]; L  .  Remove (I );  Yield return  O  .  Elementat (I );}} 

You only need to combine n original Playlists that have been disrupted by this method into a new playlist output.

 

On the DesktopProgramThis method is used to play background music.

This should be the easiest way to play music in a desktop program, although it has a strong shanzhai style.

You only need to create a webbrowser control and assign its documenttext attribute to the HTML code of the player.

The following C # code can be used to play background music:

 VaR  Path  =  @ "C: \ 123.asx"  ;  VaR  B  =  New  Webbrowser  (); B  .  Documenttext =  String  .  Format (  @ "<! Doctype HTML public ""-// W3C // dtd xhtml 1.0 transitional // en "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "" http://www.w3.org/1999/xhtml ">   , PATH ); 

 

Download

XPS version: http://www.uushare.com/user/icesee/file/3169359

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.