[Winform] Issues encountered in Media Player COM component application

Source: Internet
Author: User

Summary

In a recent project, you need to use the full-screen loop to play the video on the client, then consider using an open source player, but not easy to control, and then consider that since all are Windows systems, then consider using Microsoft's own media player player. So in development, the media Player component is embedded in the WinForm. The following will be the development of the problems encountered, do a summary.

Problems and Solutions

The first thing to figure out is whether Media Player is x86 or x86. My Computer system is x64, you can try to open media Player and see if it is x64 in Task Manager.

So media Player is x86 or x86. In development, it is best to run or produce the project as any CPU or x86, otherwise the failure of rendering COM components may occur. Because this project introduced the Cefsharp component, I need to specify the running platform, which I set as x86.

If you make an error when adding a COM component, you can try turning off vs, deleting the file containing the vshost, and then restarting VS, rebuilding the attempt.

This is set to normal, then we can set its properties, right-click on the player above the property,

Select mode, you can set the playback control button below the player, is full display, or not display, this item is as a screensaver, so let it hide, so set to none, full screen set to true.

For full-screen settings, you can also control the code, you can refer to this article:

[Winform] Settings for full-screen playback of Media player components

This can be set through the properties, it is more convenient, it is best to set through the property. One is convenient, the second is to let the control of the full-screen logic to the component.

Tick scale stretch to allow the video to be tiled. and set the player's properties Dock=fill.

  this. Windowsmediaplay.dock = System.Windows.Forms.DockStyle.Fill;

Let it fill the window.

In the project, because it is set to run in a x64 manner, and no padding is set. A bug that causes white edges to play video.

Settings for looping playback

WindowsMediaPlay.settings.setMode ("loop"true);

When initializing media Player, it is best to add the end-of-initialization tag

Windowsmediaplay.endinit ();

Add playlist, default playlist, if include mp4,wmv file, join playlist

WindowsMediaPlay.settings.setMode ("Loop",true); string[] filepaths = Directory.GetFiles (_videodirpath). Where (x = X.endswith (". mp4") || X.endswith (". wmv")).                    ToArray (); //Empty PlaylistwindowsMediaPlay.currentPlaylist.clear (); //Add a looping playlist                    foreach(varIteminchfilepaths)                    {WindowsMediaPlay.currentPlaylist.appendItem (Windowsmediaplay.newmedia (item)); }

Play

WindowsMediaPlay.Ctlcontrols.play ();

Stop it

WindowsMediaPlay.Ctlcontrols.stop ();

Time out

WindowsMediaPlay.Ctlcontrols.pause ();

Properties Introduction

Enablecontextmenu:boolean Display/Do not display the right-click menu for playback position
Fullscreen:boolean Full Screen display
Stretchtofit:boolean whether to stretch to optimal size when not in full-screen state
Umode:string player mode, full: The following control bar; None: Only the playback section has no control bar
Playstate:integer the current control state, here are three basic states:
3: Playing
2: Pause
1: Stopped
OnStatusChange events are triggered when a state changes
[Controls]
The player can be controlled by windowsmediaplayer.controls and some related information is obtained:
Controls.play; Play
Controls.stop; Stop it
Controls.pause; Time out
Controls.currentPosition:Double Current Playback Progress
Controls.currentPositionString:string time-format string "0:32"
[Currentmedia]
Can get information about the current media through Windowsmediaplayer.currentmedia
Currentmedia.duration Double Total length
Currentmedia.durationstring time-format string "4:34"
[Settings]
The player can be set by windowsmediaplayer.settings, including volume and channel.
Settings.volume:integer Volume (0-100)
The Settings.balance:integer channel, through which it should be able to control the stereo, left channel, right channel.
=================
Version 2:
Attribute/Method Name: Description:
[Basic Properties]
Url:string Specify media location, native or network address
uimode:string; Player interface mode, available for full, Mini, None, Invisible
Playstate:integer; Playback status, 1 = stop, 2 = pause, 3= play, 6 = buffering, 9 = connecting, 10 = Ready
Enablecontextmenu:boolean; Enable/Disable right-click menu
Fullscreen:boolean; Whether to display full screen
[Controls] Wmp.controls//Player Basic control
Controls.play; Play
Controls.pause; Time out
Controls.stop; Stop it
controls.currentPosition:double; Current progress
controls.currentPositionString:string; Current progress, string format. such as "00:23"
Controls.fastforward; Fast Forward
Controls.fastreverse; Go back
Controls.next; Next song
controls.previous; Previous song
[Settings] Wmp.settings//Player basic settings
Settings.volume:integer; Volume, 0-100
Settings.autoStart:Boolean; Whether to play automatically
Settings.mute:Boolean; is muted
Settings.playCount:integer; Number of plays
[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); Setting media information by property name
currentMedia.name:string; With Currentmedia.getiteminfo ("Title")
[Currentplaylist] Wmp.currentplaylist//Current Playlist properties
CurrentPlaylist.count:integer; The current playlist contains the number of media
Currentplaylist.item[integer]; Gets or sets the specified project media information whose sub-properties are the same as Wmp.currentmedia

Media Player event properties can be found in the MSDN

https://msdn.microsoft.com/en-us/library/windows/desktop/dd562419 (v=vs.85). aspx

[Winform] Issues encountered in Media Player COM component application

Related Article

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.