C # WMP Video playback

Source: Internet
Author: User
Tags shuffle

1. Common methods for C # Player controls Introduction

Right-click Toolbox, select items (I) ... display "Select toolbox items", COM components, Windows Media Player wmp.dll add

[Basic Properties] url:string; Specify the media location, native or network address uimode:string; Player interface mode, available for full, Mini, None, Invisible (no case) Playstate:integer; Playback status. This property changes when both the Playstatechange event and the StateChange event are raised.   The value range is enumerated: Wmplib.wmpplaystate, its members are as follows: wmppsundefined = 0;    Unknown state wmppsstopped = 1;     Playback stop wmppspaused = 2;     Play Pause wmppsplaying = 3;   Playing wmppsscanforward = 4;   Search forward wmppsscanreverse = 5;     Search Backwards wmppsbuffering = 6;      Buffering wmppswaiting = 7;    Waiting for stream to start wmppsmediaended = 8;    Playback stream has ended wmppstransitioning = 9;      Prepare a new media file Wmppsready = 10;   Ready to play wmppsreconnecting = 11;       Attempt to reconnect streaming media data Wmppslast = 12;  The last state, the state has not changed the write code in Playstatechange can prevent the issue of non-default types such as playing rmvb (with Wmppsready).    Enablecontextmenu:boolean;         Enable/Disable right-click menu Fullscreen:boolean; Whether full screen display//Player basic Control ctlcontrols.play; Play Ctlcontrols.pause; Suspension of Ctlcontrols.stop; Stop Ctlcontrols.currentPosition:double; Current Progress Ctlcontrols.currentPositionString:string; Current progress, string format. such as "00:23" Ctlcontrols.fastforward; Fast forward ctlcontrols.fastreverse; FastRetreat Ctlcontrols.next; Next song Ctlcontrols.previous; Previous [Settings] Wmp.settings//player basic Settings Settings.volume:integer; volume, 0-100 settings.autoStart:Boolean; Whether to play Settings.mute:Boolean automatically; Whether Mute settings.playCount:integer; Played//Sequential play Wmp.settings.setMode ("Shuffle", False)//Random play Wmp.settings.setMode ("Shuffle", True)//Loop play wmp.settings. SetMode ("Loop", True) [Currentmedia] Wmp.currentmedia//Current media properties currentMedia.duration:double; Total media length currentMedia.durationString:string; Media total length, string format. such as "03:24" Currentmedia.getiteminfo (const string); Get current media information "title" = Media title, "Author" = artist, "copyright" = Copyright Information, "Description" = Media content description, "Duration" = Duration (seconds), "FileSize" = File size, " FileType "= File type," sourceURL "= Original address Currentmedia.setiteminfo (const string); Set media information currentMedia.name:string by property name; With Currentmedia.getiteminfo ("Title")

Basic Setup Examples:

Axwindowsmediaplayer1.windowlessvideo = false;   When set to False, double-click the screen to full screen Axwindowsmediaplayer1.fullscreen = true; Set player Full screen playback Axwindowsmediaplayer1.url = @ "mms://192.168.0.102/vod/jingwei.wma";// Play Resource AxWindowsMediaPlayer1.Ctlcontrols.play ();        Play AxWindowsMediaPlayer1.Ctlcontrols.stop ();        Stop AxWindowsMediaPlayer1.Ctlcontrols.pause ();       Pause AxWindowsMediaPlayer1.settings.autoStart = true;     AutoPlay AxWindowsMediaPlayer1.settings.mute = false;         Mute axWindowsMediaPlayer1.settings.volume = +;      Volume int 0 ~   100 is the maximum volume axWindowsMediaPlayer1.currentMedia.duration.ToString ();// Film length axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 30; Current playback position doubleaxWindowsMediaPlayer1.currentMedia.getItemInfo ("Title");// Title AxWindowsMediaPlayer1.currentMedia.getItemInfo ("Author");//author

Full Screen control Instance code:

Using system.io;using wmplib;            Public Videoplay () {InitializeComponent (); Full screen settings and hide mouse this.            WindowState = formwindowstate.maximized; This.            FormBorderStyle = Formborderstyle.none;            Cursor.hide (); Player Full Screen Rectangle screensize = system.windows.forms.systeminformation.virtualscreen;//Gets the width and height of the screen. Panel1.            Location = new System.Drawing.Point (0, 0);            This.panel1.Size = new System.Drawing.Size (screensize.width,screensize.height);            This.axWindowsMediaPlayer1.Location = new System.Drawing.Point (0, 0);            This.axWindowsMediaPlayer1.Size = new System.Drawing.Size (screensize.width, screensize.height); Player Settings Axwindowsmediaplayer1.uimode = "None";//Player Style Axwindowsmediaplayer1.stretchtofit = true;//non-full When the screen state is stretched to the optimal size Axwindowsmediaplayer1.enablecontextmenu = false;//Disable the player right-click menu} private IWMPP Laylist videolist;//Creating playlists       private bool IfLoop = true;//Video Looping//setting whether to loop the public bool IfLoop {get {return if Loop;        } set {IfLoop = value;}            }//The private void Axwindowsmediaplayer1_statuschange (object sender, EventArgs e) Occurs when the playback state is changed {                  Determine if the video has stopped playing if ((int) axwindowsmediaplayer1.playstate = = 1) {//Pause for 2 seconds and replay again                System.Threading.Thread.Sleep (2000);            Re-play//axwindowsmediaplayer1.ctlcontrols.play ();        }}//Play public void Videostart () {axWindowsMediaPlayer1.Ctlcontrols.play (); }//List play public void Videoliststart () {videoplaylist ();//Retrieve playlist Axwindows        MediaPlayer1.Ctlcontrols.play ();        }//Pause public void Videopause () {axWindowsMediaPlayer1.Ctlcontrols.pause (); }//Replay public void VideorePlay () {videostop ();        Videostart (); }//List replay public void Videolistreplay () {axwindowsmediaplayer1.currentplaylist = Videolist        ;//Reload playlist videostart (); }//Stop playing public void Videostop () {//axwindowsmediaplayer1.currentplaylist.cl        Ear ();//Clear List axWindowsMediaPlayer1.Ctlcontrols.stop ();        }//Video mute public void Videomute (bool t) {AxWindowsMediaPlayer1.settings.mute = t; }//Play the next video public void Videonext () {///determine if the currently played video is the last if of the list (Axwindowsmedia Player1.currentMedia.name = = axwindowsmediaplayer1.currentplaylist.item[                Axwindowsmediaplayer1.currentplaylist.count-1].name) {} else { AxWindowsMediaPlayer1.Ctlcontrols.next ();//Play Next}}//Play previous media public void Videopreviou     S ()   {//Determines whether the currently played video is the first if of the list (AxWindowsMediaPlayer1.currentMedia.name = = Axwindowsmediaplayer1.currentplaylis T.item[0].name) {} else {AXWINDOWSMEDIAPLAYER1.CTLCONTROLS.PR Evious ();//Play Last}}//Get playback Class table and initialize public void Videoplaylist () {Videoli            st = AxWindowsMediaPlayer1.playlistCollection.newPlaylist ("one");//Create playlist string path = @ ". \data\video";//media path            DirectoryInfo dir = new DirectoryInfo (path); foreach (FileSystemInfo fsi in dir. Getfilesysteminfos ()) {if (FSI is FileInfo) {FileInfo fi = (                    FileInfo) FSI; Videolist.appenditem (Axwindowsmediaplayer1.newmedia (FI.                FullName)); }} axwindowsmediaplayer1.currentplaylist = videolist;//Find the video, play the class table AxWindowsMediaPlayer1.        Settings.setmode ("Loop", ifloop);//Set class table loop playback} 

2. C # calling WMP to play a folder file

Playlist Wmplib.iwmpplaylist playlist = Null;playlist = MediaPlayer.playlistCollection.newPlaylist ("palylist");// Playlist Add item, and start playing Playlist.appenditem (Mediaplayer.newitem (file_address)) from the item you just added; Mediaplayer.currentplaylist = Playlist;//oldcount is the quantity before adding, playlist after adding. Item[oldcount] is the first item added MediaPlayer.Ctlcontrols.currentItem = Playlist. Item[oldcount]; Playmusic ()
The current playback property//title: Title, is the information embedded in the MP3 file sourceURL: File address MediaPlayer.currentMedia.getItemInfo ("title"); The total time of the current item: MediaPlayer.currentMedia.duration  //double type MediaPlayer.currentMedia.durationString  //string type, It's a few seconds of formatting. Current progress: MediaPlayer.Ctlcontrol.currentPosition//double type MediaPlayer.Ctlcontrol.currentPositionString// String type, which is formatted well for a few seconds//mediaplayer control playback, all in the Ctlcontrol inside

3. C # WinForm from the lower right corner of the pop-up window

<summary>///Form animation function Note: to refer to System.Runtime.InteropServices; </summary>//<param Name= "hwnd" > Specifies the handle of the window that produces the animation </param>//<param name= "Dwtime" > Specifying the duration of the animation </param>//<param name= "DwFlags" > Specifies the type of animation, which can be a combination of one or more flags. </param>//<returns></returns> [DllImport ("user32")] private static extern bool Animatewi        Ndow (IntPtr hwnd, int dwtime, int dwFlags); The following constants are available, declaring the private const int aw_hor_positive = 0x0001;//from left to right, based on different animation effects, which can be used in scrolling and sliding animations. This flag is ignored when using the AW_CENTER flag Private Const int aw_hor_negative = 0x0002;//from right to left display window, this flag can be used in scrolling animation and sliding animation. This flag is ignored when using the AW_CENTER flag Private Const int aw_ver_positive = 0x0004;//top-down display window, which can be used in scrolling animations and slide animations. This flag is ignored when using the AW_CENTER flag Private Const int aw_ver_negative = 0x0008;//from the bottom up Display window, which can be used in scrolling animations and slide animations. The flag is ignored when the Aw_center flag is used when the flag is private const int aw_center = 0x0010;//If the aw_hide flag is used, the window overlaps; otherwise the private const in T aw_hide = 0x10000;//hidden window private const int aw_active = 0x20000;//activation window, do not use this flag after using the AW_HIDE flag Private Const int aw_slide = 0x40000;//Use sliding type animation effect The default is the scrolling animation type, when using the Aw_center flag, this flag is ignored by the private const int aw_blend = 0x80000;//using the fade effect private void frmmsg _load (object sender, EventArgs e) {int x = Screen.primaryscreen.workingarea.right-this.            Width; int y = screen.primaryscreen.workingarea.bottom-this.            Height; This. Location = new Point (x, y);//setup form displays AnimateWindow (this) in the lower-right corner of the screen. Handle, Aw_slide | aw_active |        aw_ver_negative); private void Frmmsg_formclosing (object sender, FormClosingEventArgs e) {AnimateWindow (this. Handle, Aw_blend |        Aw_hide); }

  

C # WMP Video playback

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.