Componente Windows Media Player C#

componente windows media player c#

I am working with the Windows Media Player component but I m How to get Windows Media Player starts with Windows 7, and Windows Media Player.

componente windows media player c#

In this article we will see how we can use Windows Media Player s COM and its ActiveX Control in Using Windows Media Player COM in WPF. media 2016 C Corner.

Embedding the Windows Media Player Control in a C# Solution

How to add Windows Media Player component to c. net vidual studio to play Video file. Asked March 14, 2014 by Jtn Rthd in Information Technology. Hello.

Embedding the Windows Media Player Control in a C Solution Developer To use the functionality of Windows Media Player in a C application.

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

The following sections describe how to create an application that plays video and uses custom play and stop buttons.

Add the Video Window

Add the Windows Media Player ActiveX control to a form. Resize the control, and then place it where you want the video window to appear.

Select the Windows Media Player control, then change the uiMode property to none. This setting hides the UI controls. When the user plays a video, it will appear in the window. For audio-only content, a visualization will appear.

Add Two Buttons and Adjust the Form

Now, add two buttons to the form. Select the first button and change the Text property to Play. Select the second button and change its Text property to Stop.

Add the Play Code

Double-click the Play button to reveal the Code window. In C, the following code will be displayed:

private void button1_Click object sender, System.EventArgs e

Add this line between the two curly braces:

axWindowsMediaPlayer1.URL c: mediafile.wmv ;

In 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. Any valid file path can be used. The symbol instructs the compiler to not interpret backslashes as escape characters.

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 axWindowsMediaPlayer1.mediaCollection.getByName mediafile ;

Because the autoStart property is true by default, Windows Media Player will start playing when you set the currentPlaylist or URL property.

Add the Stop Code

Double-click the Stop button to reveal the Code window. In C, the following code will be displayed:

private void button2_Click object sender, System.EventArgs e

axWindowsMediaPlayer1.Ctlcontrols.stop ;

Note  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 System.Windows.Forms.Control.

Add Error-handling

The Windows Media Player control does not raise an exception when it encounters an error such as an invalid URL. Instead, it signals an event. Your application should handle error events sent by the Player.

To create an event handler, first open the Properties window for the Windows Media Player control. In the list of events, double-click MediaError. The following code is displayed:

private void Player_MediaError object sender, _WMPOCXEvents_MediaErrorEvent e

The following code could be inserted in the method to provide minimal error-handling capability. Note that information about the error can be retrieved from the _WMPOCXEvents_MediaErrorEvent argument.

try

// If the Player encounters a corrupt or missing file,

// show the hexadecimal error code and URL.

IWMPMedia2 errSource e.pMediaObject as IWMPMedia2;

IWMPErrorItem errorItem errSource.Error;

MessageBox.Show Error errorItem.errorCode.ToString X

in errSource.sourceURL ;

catch InvalidCastException

// In case pMediaObject is not an IWMPMedia item.

MessageBox.Show Error. ;

Related topics

Embedding the Windows Media Player Control in a. NET Framework Solution.

Windows Media Player Component. Help - Media Player Based On Windows Media Player Controls; C ; ASP.NET.NET Framework; VB6; PHP;.

Mar 22, 2014  Click on the Windows Media Player control and press F4 to get the now here s a tutorial for creating your own Media Player in C.

componente windows media player c#

Playlist with component windows media player c. c485-4cc1-a858-2571d49d2d61/playlist-with-component-windows-media-player-c.forum winforms.

Using the Windows Media Player the Windows Media Player Control in a C Solution: Provides instructions for creating a simple C application that uses the Windows.

componente windows media player c#