Add the Windows Media Player 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. 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".
Double-click the Play button to reveal the Code window. The following code is displayed:. I have only used media player for video. However I found that duration wasn't available until it started playing the video. It was available immediately though. Add a comment. Active Oldest Votes. After a bit more digging, this code does it Player1. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. I tried to find a good media library or control in Internet but finally I came out with the simplest solution - using the MediaElement from WPF control library. It can play media from almost any source: single songs, videos, playlists, Internet radio etc. Nothing is very hard to understand in this code. The player has four states: Unknown nothing is loaded yet , Stopped, Paused and Playing. A few methods change player state.
The LoadPlayList method loads playlist from selected file. There is also an event Changed which tells subscribers player user controls to update the UI.
Another interesting thing here is a static variable instance. Remember I told you that there was a problem while making player common for all text editor pages. InternetRadioPlayerFactory creates instances of player control for each page. This means that if we had a standalone player encapsulated in each control we would have the situation when different songs are being played from different pages.
Having static instance of Player and a private constructor don't allow user controls to create new instances of Player. Now let's create a user control for our player. Name it PlayerControl. PlayerControl takes Player instance as a constructor parameter, we could just get it from Player.
0コメント