Play a video (C #)

Source: Internet
Author: User

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

/// <Summary>
/// Summary description for playmedia
/// </Summary>
Public class playmedia
{
Public playmedia ()
{
//
// Todo: Add constructor logic here
//
}
Public String play (string URL, int width, int height)
{
String strtmp = URL. tolower ();
If (strtmp. endswith (". WMV ") | strtmp. endswith (". MP3 ") | strtmp. endswith (". WMA ") | strtmp. endswith (". avi ") | strtmp. endswith (". ASF ") | strtmp. endswith (". MPG "))
{
Return WMV (URL, width, height );
}
Else if (strtmp. endswith (". MP3 "))
{
Return MP3 (URL, width, height );
}
Else if (strtmp. endswith (". SWF "))
{
Return SWF (URL, width, height );
}
Else if (strtmp. endswith (". jpg") | strtmp. endswith (". GIF "))
{
Return IMG (URL, width, height );
}
Else if (strtmp. endswith (". rm "))
{
Return RM (URL, width, height );
}

Else
{
Return "data error ";
}
}

/// <Summary>
/// WMV format file playback
/// </Summary>
/// <Param name = "url"> </param>
/// <Returns> </returns>

Private string WMV (string URL, int width, int height)
{
System. Text. stringbuilder sb = new system. Text. stringbuilder ();

SB. append ("<Object ID = \" wmplay \ "style = \" width: "+ width +" PX; Height: "+ height +" PX \ "\ n ");
SB. append ("classid = \" CLSID: 6bf52a52-394a-11d3-b153-00c04f79faa6 \ "type = application/X-oleobject standby = \" loading Windows Media Player components ...\"");
SB. append ("codebase = \" downloads/mediaplayer9.0_cn.exe \ "viewastext> \ n ");
SB. append ("<Param name = \" url \ "value = '" + URL + "'> \ n ");
SB. append ("<Param name = \" controls \ "value = \" controlpanel, statusba \ "> ");
// <Param name = "controls" value = "controlpanel, statusbar">
SB. append ("<Param name = \" Hidden \ "value = \" 1 \ "> ");
SB. append ("<Param name = \" showcontrols \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" rate \ "value = \" 1 \ "> \ n ");
SB. append ("<Param name = \" balance \ "value = \" 0 \ "> \ n ");
SB. append ("<Param name = \" currentposition \ "value = \"-1 \ "> \ n ");
SB. append ("<Param name = \" defaultframe \ "value = \" \ "> \ n ");
SB. append ("<Param name = \" playcount \ "value = \" 100 \ "> \ n ");
SB. append ("<Param name = \" autostart \ "value = \"-1 \ "> \ n ");
SB. append ("<Param name = \" currentmarker \ "value = \" 0 \ "> \ n ");
SB. append ("<Param name = \" invokeurls \ "value = \"-1 \ "> \ n ");
SB. append ("<Param name = \" baseurl \ "value = \" \ "> \ n ");
SB. append ("<Param name = \" volume \ "value = \" 85 \ "> \ n ");
SB. append ("<Param name = \" mute \ "value = \" 0 \ "> \ n ");
SB. append ("<Param name = \" uimode \ "value = \" Mini \ "> \ n ");
SB. append ("<Param name = \" stretchtofit \ "value = \" 0 \ "> \ n ");
SB. append ("<Param name = \" windowlessvideo \ "value = \" 0 \ "> \ n ");
SB. append ("<Param name = \" enabled \ "value = \"-1 \ "> \ n ");
SB. append ("<Param name = \" enablecontextmenu \ "value = \" false \ "> \ n ");
SB. append ("<Param name = \" fullscreen \ "value = \" 0 \ "> \ n ");
SB. append ("<Param name = \" samistyle \ "value = \" \ "> \ n ");
SB. append ("<Param name = \" samilang \ "value = \" \ "> \ n ");
SB. append ("<Param name = \" samifilename \ "value = \" \ "> \ n ");
SB. append ("<Param name = \" captioningid \ "value = \" \ "> \ n ");
SB. append ("</Object> <br/> \ n ");

Return sb. tostring ();
}

Private string WMA (string URL, int width, int height)
{
System. Text. stringbuilder sb = new system. Text. stringbuilder ();

SB. append ("<Object ID = \" wmplay \ "classid = \" CLSID: 22d6f312-b0f6-11d0-94ab-0080c74c7e95 \ "style = \" Z-INDEX: 101; left: 40px; width: 240px; position: absolute; top: 32px; Height: 248px \ "> ");
SB. append ("<Param name = \" FILENAME \ "value = \" "+ URL +" \ "> ");
SB. append ("<Param name = \" playcount \ "value = \" 1 \ "> ");
SB. append ("<Param name = \" autostart \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" clicktoplay \ "value = \" 1 \ "> ");
// Sb. append ("<Param name = \" displaysize \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" enablefullscreen controls \ "value = \" 1 \ "> ");
SB. append ("<Param name = \" showaudio controls \ "value = \" 1 \ "> ");
SB. append ("<Param name = \" enablecontext Menu \ "value = \" 1 \ "> ");
SB. append ("<Param name = \" showdisplay \ "value = \" 1 \ "> ");

SB. append ("</Object> ");

Return sb. tostring ();

}
/// <Summary>
/// Playback of AVI Files
/// </Summary>
/// <Param name = "url"> </param>
/// <Returns> </returns>
Private string AVI (string URL, int width, int height)
{
System. Text. stringbuilder sb = new system. Text. stringbuilder ();

SB. append ("<Object ID = \" wmplay \ "width = \" 400 \ "Height = \" 200 \ "border = \" 0 \ "classid = \" CLSID: CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA \ "> ");
SB. append ("<Param name = \" showdisplay \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" showcontrols \ "value = \" 1 \ "> ");
SB. append ("<Param name = \" autostart \ "value = \" 1 \ "> ");
SB. append ("<Param name = \" autorewind \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" playcount \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" appearance value = \ "0 value = \"> ");
SB. append ("<Param name = \" borderstyle value = \ "0 value = \"> ");
SB. append ("<Param name = \" moviewindowheight \ "value = \" 240 \ "> ");
SB. append ("<Param name = \" movie1_wwidth \ "value = \" 320 \ "> ");
SB. append ("<Param name = \" FILENAME \ "value = \" "+ URL +" \ "> ");
SB. append ("</Object> ");

Return sb. tostring ();
}

Private string RM (string URL, int width, int height)
{
System. Text. stringbuilder sb = new system. Text. stringbuilder ();
SB. append ("<Object ID = \" wmplay \ "codebase = \" downloads/RealPlayer10-5GOLD_cn0302.exe \ "classid = \" CLSID: CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA \ "Height =" + height + "width =" + width + "> ");
SB. append ("<Param name = \" src \ "value = \" "+ URL +" \ "> ");
// Sb. append ("<Param name = \" _ extentx \ "value = \" 9313 \ "> ");
// Sb. append ("<Param name = \" _ extenty \ "value = \" 7620 \ "> ");
SB. append ("<Param name = \" autostart \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" Shuffle \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" prefetch \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" nolabels \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" controls \ "value = \" imagewindow, controlpanel, statusbar \ "> ");
SB. append ("<Param name = \" console \ "value = \" clip1 \ "> ");
SB. append ("<Param name = \" loop \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" numloop \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" center \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" maintainaspect \ "value = \" 0 \ "> ");
SB. append ("<Param name = \" backgroundcolor \ "value = \" #000000 \ "> ");
// Sb. append ("<embed SRC type = \" audio/X-PN-RealAudio-plugin \ "console = \" clip1 \ "controls = \" imagewindow \ "Height = \" 250 \ "width = \" 354 \ "autostart = \" false \ "> ");
SB. append ("</Object> ");

Return sb. tostring ();
}
}

The class found on the forum is easy to use.

Playmedia pcplay = new playmedia ();
Playmedialabel. Text = pcplay. Play ("XXX. wmv", 450,360 );

/* The program controls the media player to control the width and height.
Input parameters: media file, frame width, and frame height
Usage: label_mediaplayer.text = playmedia (mediafile, width, height)
*/

Public String playmedia (string mediafile, int framewidth, int frameheight)
{
String STR;
STR = "<Object ID = 'nsv' codebase = '";
STR + = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab ";
STR + = "# version = 5, 1, 52,701 'Type = 'application/X-oleobject '";
STR + = "Height = '";
STR + = frameheight;
STR + = "'standby = 'loading Microsoft Windows Media Player components ...'";
STR + = "width = '";
STR + = framewidth;
STR + = "'align = 'middle '";
STR + = "cssclassid = 'clsid: 22d6f312-b0f6-11d0-94ab-0080c74c7e95 '";
STR + = "viewastext> ";
STR + = "<Param name = 'audiostream' value = '-1'> ";
STR + = "<Param name = 'autosize' value = '1'> ";
STR + = "<Param name = 'autostart' value = '-1'> ";
STR + = "<Param name = 'animationatstart' value = '-1'> ";
STR + = "<Param name = 'allowscan' value = '-1'> ";
STR + = "<Param name = 'allowchangedisplaysize' value = '1'> ";
STR + = "<Param name = 'autorewind 'value = '0'> ";
STR + = "<Param name = 'balance 'value = '0'> ";
STR + = "<Param name = 'baseurl' value =''> ";
STR + = "<Param name = 'bufferingtime' value = '5'> ";
STR + = "<Param name = 'captioningid' value =''> ";
STR + = "<Param name = 'clicktoplay' value = '-1'> ";
STR + = "<Param name = 'cursortype' value = '0'> ";
STR + = "<Param name = 'currentposition' value = '-1'> ";
STR + = "<Param name = 'currentmarker 'value = '0'> ";
STR + = "<Param name = 'defaultframe 'value =''> ";
STR + = "<Param name = 'displaybackcolor' value = '0'> ";
STR + = "<Param name = 'displayforecolor' value = '000000'> ";
STR + = "<Param name = 'displaymode' value = '0'> ";
STR + = "<Param name = 'displaysize' value = '0'> ";
STR + = "<Param name = 'enabled' value = '-1'> ";
STR + = "<Param name = 'enablescontextmenu 'value = 'true'> ";
STR + = "<Param name = 'enablespositioncontrols 'value ='-1'> ";
STR + = "<Param name = 'enablefullscreencontrols 'value = '1'> ";
STR + = "<Param name = 'enablestracker' value = '-1'> ";
STR + = "<Param name = 'filename' value = '";
STR + = mediafile;
STR + = "'> ";
STR + = "<Param name = 'invokeurls 'value ='-1'> ";
STR + = "<Param name = 'language' value = '-1'> ";
STR + = "<Param name = 'mute' value = '0'> ";
STR + = "<Param name = 'playcount' value = '1'> ";
STR + = "<Param name = 'previewmode' value = '0'> ";
STR + = "<Param name = 'rate' value = '1'> ";
STR + = "<Param name = 'sample' value =''> ";
STR + = "<Param name = 'samples' value =''> ";
STR + = "<Param name = 'samifilename 'value =''> ";
STR + = "<Param name = 'selectionstart' value = '-1'> ";
STR + = "<Param name = 'selection} // 'value = '-1'> ";
STR + = "<Param name ='s} // openstatechangeevents 'value = '-1'> ";
STR + = "<Param name ='s} // warningevents 'value = '-1'> ";
STR + = "<Param name ='s} // errorevents 'value = '-1'> ";
STR + = "<Param name ='s} // keyboardevents 'value = '0'> ";
STR + = "<Param name ='s} // mouseclickevents 'value = '0'> ";
STR + = "<Param name ='s} // mousemoveevents 'value = '0'> ";
STR + = "<Param name ='s} // playstatechangeevents 'value = '-1'> ";
STR + = "<Param name = 'showcaptioning' value = '0'> ";
STR + = "<Param name = 'showcontrols' value = '-1'> ";
STR + = "<Param name = 'showaudiocontrols' value = '-1'> ";
STR + = "<Param name = 'showdisplay' value = '0'> ";
STR + = "<Param name = 'showgotobar' value = '0'> ";
STR + = "<Param name = 'showpositioncontrols' value = '-1'> ";
STR + = "<Param name = 'showstatusbar' value = '-1'> ";
STR + = "<Param name = 'showtracker' value = '-1'> ";
STR + = "<Param name = 'transparentatstart' value = '0'> ";
STR + = "<Param name = 'videoborderwidth' value = '0'> ";
STR + = "<Param name = 'videobordercolor' value = '0'> ";
STR + = "<Param name = 'videoborder3d 'value = '0'> ";
STR + = "<Param name = 'Volume 'value = '-600'> ";
STR + = "<Param name = 'windowlessvideo' value = '0'> ";
STR + = "</Object> ";
Return STR;
}

 

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.