![]() Adding the Windows Media Player Controlīefore creating a new project, make sure that the latest version of Windows Media Player and the Windows Media Player SDK is installed on your computer. NET Framework application through the Toolbox in Visual Studio. You can add the Windows Media Player 9 Series or later ActiveX control to a. In case pMediaObject is not an IWMPMedia item.Įmbedding the Windows Media Player Control in a. ![]() ![]() IWMPErrorItem errorItem = errSource.Error IWMPMedia2 errSource = e.pMediaObject as IWMPMedia2 show the hexadecimal error code and URL. If the Player encounters a corrupt or missing file, Note that information about the error can be retrieved from the _WMPOCXEvents_MediaErrorEvent argument. The following code could be inserted in the method to provide minimal error-handling capability. The following code is displayed: private void Player_MediaError(object sender, _WMPOCXEvents_MediaErrorEvent e) In the list of events, double-click MediaError. To create an event handler, first open the Properties window for the Windows Media Player control. Your application should handle error events sent by the Player. The Windows Media Player control does not raise an exception when it encounters an error such as an invalid URL. The managed-code wrapper for the Windows Media Player control exposes the Controls object as Ctlcontrols to avoid collision with the Controls property inherited from. In C#, the following code will be displayed: private void button2_Click(object sender, System.EventArgs e)Īdd this line between the two curly braces: () Add the Stop Codeĭouble-click the Stop button to reveal the Code window. If you have added the digital media content from the Windows Media Player SDK to the library in Windows Media Player, you can use this code instead: axWindowsMediaPlayer1.currentPlaylist = ("mediafile") īecause the autoStart property is true by default, Windows Media Player will start playing when you set the currentPlaylist or URL property. The symbol instructs the compiler to not interpret backslashes as escape characters. In C#, the following code will be displayed: private void button1_Click(object sender, System.EventArgs e)Īdd this line between the two curly braces: axWindowsMediaPlayer1.URL = the preceding code example, "axWindowsMediaPlayer1" is the default name of the Windows Media Player control, and "c:\mediafile.wmv" is a placeholder for the name of the media item you want to play. Add the Play Codeĭouble-click the Play button to reveal the Code window. Select the second button and change its Text property to "Stop". Select the first button and change the Text property to "Play". ![]() For audio-only content, a visualization will appear. When the user plays a video, it will appear in the window. Select the Windows Media Player control, then change the uiMode property to "none". Resize the control, and then place it where you want the video window to appear. Add the Video WindowĪdd the Windows Media Player ActiveX control to a form. The following sections describe how to create an application that plays video and uses custom play and stop buttons. To use the functionality of Windows Media Player in a C# application, first add the component to a form as described in Using the Windows Media Player Control with Microsoft Visual Studio ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |