Play using windows media player

Embedding the Windows Media Player Control in a C# Solution

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:

Add this line between the two curly braces:

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:

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:

Add this line between the two curly braces:

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.

Читайте также:  По поддержки windows сохранено

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:

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.

Как скачать проигрыватель Windows Media

Проигрыватель Windows Media доступен для устройств под управлением Windows. Воспользуйтесь этой таблицей, чтобы найти подходящую для вашей системы версию проигрывателя. (Если вы используете компьютер Mac, можно скачать компоненты Windows Media для QuickTime, чтобы воспроизвести файлы Windows Media.)

Операционная система или браузер

Проигрыватель Windows Media 12
Подробнее

Входит в состав Windows 10 (чистая установка и обновление с Windows 8.1 или Windows 7). В некоторых выпусках Windows 10 он входит в качестве дополнительной функции, которую можно включить. Для этого нажмите кнопку Пуск , а затем выберите Параметры > Приложения > Приложения и компоненты > Управление дополнительными компонентами > Добавить компонент > Проигрыватель Windows Media и выберите Установить.

Воспроизведение DVD не поддерживается. Перейдите на страницу Параметры воспроизведения DVD для Windows, чтобы узнать, как добавить функцию воспроизведения DVD в Windows 10.

Проигрыватель Windows Media 12
Подробнее

Входит в состав Windows 8.1 и Windows 8.1 Профессиональная, но воспроизведение DVD-дисков не поддерживается. Перейдите на страницу Параметры воспроизведения DVD для Windows, чтобы узнать, как добавить функцию воспроизведения DVD в Windows 8.1. Для проигрывателя Windows Media 12 для Windows 8,1 N и KN выпусков пакета дополнительных компонентов мультимедиа.

Проигрыватель Windows Media недоступен для Windows RT 8.1.

Проигрыватель Windows Media 12
Подробнее

Входит в состав выпусков Windows 7 Начальная, Домашняя расширенная, Профессиональная, Максимальная и Корпоративная. Для выпусков Windows 7 N и KN Загрузите пакет компонентов мультимедиа.

Компоненты Windows Media для QuickTime

Для переустановки проигрывателя Windows Media выполните следующие действия.

Нажмите кнопку «Пуск» , введите компоненты и выберите Включение или отключение компонентов Windows.

Прокрутите список вниз и разверните Компоненты для работы с мультимедиа, снимите флажок Проигрыватель Windows Media и нажмите кнопку ОК.

Перезапустите устройство. Проигрыватель Windows Media будет удален.

Повторите шаг 1.

Прокрутите список вниз и разверните Компоненты для работы с мультимедиа, установите флажок Проигрыватель Windows Media и нажмите кнопку ОК.

Перезапустите устройство. Проигрыватель Windows Media будет переустановлен.

Примечание: Сведения об устранении проблем с воспроизведением и кодеками см. в разделе «Техническая поддержка» в проигрывателе Windows Media.

Play a CD or DVD in Windows Media Player

In Windows Media Player, you can play audio CDs, data CDs, and data DVDs that contain music or video files (also known as media CDs). You can also play video CDs (VCDs), which are similar to DVDs, although the video quality isn’t as high.

Читайте также:  Microsoft support chat windows

If you have a DVD drive and a compatible DVD decoder installed on your computer, you can use Windows Media Player to play a DVD-Video disc—this is the type of DVD that movies are distributed on. If you encounter an error indicating that you are missing a DVD decoder, select Web Help in the error message dialog box to determine how to obtain a decoder.

To play a CD or DVD

Insert the disc you want to play into the drive.

Typically, the disc will start playing automatically. If it doesn’t play, or if you want to play a disc that is already inserted, open Windows Media Player, and then, in the Player Library, select the disc name in the navigation pane.

If you inserted a DVD, select a DVD title or chapter name.

Note: If you start to play a DVD or VCD in the Player Library, the Player automatically switches to Now Playing mode.

The Blu-ray Disc format is not supported in Windows Media Player. To play a Blu-ray Disc, you need to use a non-Microsoft program that supports Blu-ray playback and a device capable of reading Blu-ray Discs.

If you previously selected Rip CD automatically on the Rip Music tab in the Options dialog box or on the Rip settings menu, a CD will immediately begin ripping after you insert it into the drive.

If you get a message that says that your computer is missing a codec or that you require a DVD decoder, you’re probably trying to play, burn, or sync a file that was compressed by using a codec that Windows or the Player doesn’t include by default. For more information about codecs, see Codecs: frequently asked questions.

Get Windows Media Player

Windows Media Player is available for Windows-based devices. Use this table to find the right version of the Player for your system. (If you’ve got a Mac, you can download Windows Media Components for QuickTime to play Windows Media files.)

Windows Media Player 12
Learn more

Included in clean installs of Windows 10 as well as upgrades to Windows 10 from Windows 8.1 or Windows 7. In some editions of Windows 10, it’s included as an optional feature that you can enable. To do that, select the Start button, then select Settings > Apps > Apps & features > Manage optional features > Add a feature > Windows Media Player, and select Install.

DVD playback isn’t included. Go to the DVD playback for Windows page to find out how to add DVD playback to Windows 10.

Читайте также:  Файл выбора операционной системы windows

Windows Media Player 12
Learn more

Included in Windows 8.1 and Windows 8.1 Pro, but doesn’t include DVD playback. Go to the DVD playback for Windows page to find out how to add DVD playback to Windows 8.1. For Windows Media Player 12 for Windows 8.1 N and KN editions, get the Media Feature Pack.

Windows Media Player isn’t available for Windows RT 8.1.

Windows Media Player 12
Learn more

Included in Windows 7 Starter, Home Premium, Professional, Ultimate, and Enterprise editions. For Windows 7 N or KN editions, get the Media Feature Pack.

Windows Media Components for QuickTime

If you want to reinstall Windows Media Player, try the following:

Click the Start button, type features, and select Turn Windows features on or off.

Scroll down and expand Media Features, clear the Windows Media Player check box, and click OK.

Restart your device. Windows Media Player should be uninstalled.

Scroll down and expand Media Features, select the Windows Media Player check box, and click OK.

Restart your device. Windows Media player should now be reinstalled.

Note: To troubleshoot issues like playback and codec problems, see the «Get help» section in Windows Media Player.

Player.playState

The playState property retrieves a value indicating the state of the Windows Media Player operation.

Syntax

player .playState

Possible Values

This property is a read-only Number (long). The C-style enumeration constant can be derived by prefixing the state value with «wmpps». For example, the constant for the Playing state is wmppsPlaying.

Value State Description
0 Undefined Windows Media Player is in an undefined state.
1 Stopped Playback of the current media item is stopped.
2 Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location.
3 Playing The current media item is playing.
4 ScanForward The current media item is fast forwarding.
5 ScanReverse The current media item is fast rewinding.
6 Buffering The current media item is getting additional data from the server.
7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin.
8 MediaEnded Media item has completed playback.
9 Transitioning Preparing new media item.
10 Ready Ready to begin playing.
11 Reconnecting Reconnecting to stream.

Remarks

Windows Media Player states are not guaranteed to occur in any particular order. Furthermore, not every state necessarily occurs during a sequence of events. You should not write code that relies upon state order.

Examples

The following JScript code shows the use of the player.playState property. An HTML text element, named «myText», displays the current status. The Player object was created with .

Оцените статью