H
helder227
Guest
Hi hello every body.
i build a new software a media player and i need to perform mouse right click on the video screen and do something on this case made a panel visible
I use a different player i have modified to make a DJ version of it
I have take the example on codeproject
This is my code
#Region "Imports"
Imports System.Text
Imports PVS.AVPlayer
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Diagnostics
Imports Emgu.CV
Imports Emgu.CV.UI
Imports Emgu.CV.Structure
#End Region
Public Class Form1
' **** Class Fields ***************************************************************************
#Region "Class Fields"
Private Angle As Double = 270
Dim folderxxl As String
Dim xbit As Integer = 0
Dim ybit As Integer = 0
Dim txBrush As TextureBrush
Dim Off As Point
Dim a As String = CSng(1000 * Angle / 360).ToString("f1")
Private myPlayer As Player
Private myOverlay As Overlay ' in file Overlay.vb
Private shapeStatus As Integer ' shapes - 0:none, 1val, 2:none, 3:rounded, 4:none, 5:star
Private myInfoLabel As InfoLabel
Private myInfoLabelText As StringBuilder = New StringBuilder(64)
' used with drawing audio output levels
' levelUnit = size of 1 unit (of 32767) / 140 = width of Panel4 and Panel5
Private levelUnit As Double = 140 ' / 32767.0 - changed in PVS.AVPlayer version 0.91
Private leftLevel As Integer
Private rightLevel As Integer
Private myTagInfo As TagInfo ' media (audio mp3/wma/asf) tag info
Private myOpenFileDlg As OpenFileDialog ' used with selection of media to play
Private Const OPENMEDIA_FILTER As String =
" Video Files (*.*)|*.asf;*.avi;*.bik;*.divx;*.dvx;*.f4v;*.flv;*.h264;*.hdmov;*.m2ts;*.mkv;*.mod;*.mov;*.mp2;*.mp4;*.mpeg;*.mpeg4;*.mpg;*.mpv;*.ogg;*.ogm;*.ogv;*.qt;*.rm;*.rms;*.rmvb;*.swf;*.ts;*.vfw;*.vob;*.webm;*.wmv;*.xvid|" +
" Audio Files (*.*)|*.3gp;*.aa;*.aac;*.aiff;*.amr;*.ape;*.flac;*.m4a;*.mid;*.midi;*.mka;*.mp3;*.mpc;*.ogg;*.opus;*.ra;*.rm;*.wav;*.webm;*.wma;*.wv|" +
" Image Files (*.*)|*.bmp;*.gif;*.img;*.jpeg;*.jpg;*.png;*.tga;*.tiff|" +
" All Files|*.*"
Private isInitializing As Boolean
Private wasDisposed As Boolean
#End Region
' **** Main ***********************************************************************************
#Region "Main"
Public Sub New()
isInitializing = True
InitializeComponent() ' this call is required by the designer
isInitializing = False
myPlayer = New Player() ' create a player
myPlayer.Display.Window = Panel1 ' and set its display to Panel1
myPlayer.Repeat = True ' repeat media playback when finished
myPlayer.SleepDisabled = True ' prevent the computer from entering sleep mode
' create a file selector
myOpenFileDlg = New OpenFileDialog() With
{
.Title = "Play Media",
.Filter = OPENMEDIA_FILTER,
.FilterIndex = 4
}
' You might want to add one or more of the following options to your player:
' **** 1. DISPLAY OVERLAY *****************************************************************
' A display overlay is a Form that allows you to display items on top of a movie.
' The sample overlay 'Overlay' is created with the designer - please see Overlay.vb
myOverlay = New Overlay() ' create (an instance of) the overlay
myPlayer.Overlay.Window = myOverlay ' and attach it to the player
' To remove a display overlay from the player set the overlay window to another overlay
' or to Nothing: myPlayer.Overlay.Window = Nothing
' **** 2. DISPLAY OVERLAY ALWAYS VISIBLE **************************************************
' A display overlay is usually only shown when media is playing, but if you want to always
' show the overlay you can use: myPlayer.Overlay.Hold = True
' The player's display has to be created and visible for this, so if you want
' to show the overlay right from the start of your application (without media playing) you
' have to put the 'Overlay.Hold' instruction in the Form1.Shown event handler (see below).
' **** 3. DISPLAY CLONES ******************************************************************
' For special purposes you can create one or more player display clones (display copies).
' Display clones require sufficient computing (cpu) power and may slow some computers:
'myPlayer.DisplayClones.AddRange(New Control() {Panel2, Panel3})
' cpu load can be reduced by lowering the framerate, quality or size of the clones:
' e.g. myPlayer.DisplayClones.FrameRate = 10
' You can also 'stretch' display clones (as with displaymode.stretch of the main display):
'myPlayer.DisplayClones.SetLayout(Panel2, CloneLayout.Stretch)
' To remove display clones from the player use one of the clones remove methods, e.g.:
myPlayer.DisplayClones.Remove(Panel2)
' **** 4. POSITION SLIDER *****************************************************************
' The player can control your media playback position slider (trackbar) with:
myPlayer.Sliders.Position = TrackBar1
'myPlayer.Sliders.Position = GTrackBar3.Value
' The position slider controlled by the player is only for input by the user. The value of
' the slider should not be set from code. If you want to change the playback position (and
' the slider value), use the position methods of the player, for example:
' myPlayer.Position.FromBegin = TimeSpan.FromSeconds(30).
' To remove a slider from the player set the slider to Nothing:
' myPlayer.Sliders.Position = Nothing
' **** 5. POSITION TIME *******************************************************************
' If you want to display the elapsed and/or remaining media playback time (or use your
' 'own' position slider) you can get continuous media playback position information with:
AddHandler myPlayer.Events.MediaPositionChanged, AddressOf MyPlayer_MediaPositionChanged
' please see the eventhandler below.
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 6. AUDIO SLIDERS *******************************************************************
' The player can also control your audio sliders (trackbars) with:
myPlayer.Sliders.AudioVolume = TrackBar2 ' audio volume slider
myPlayer.Sliders.AudioBalance = TrackBar3 ' audio balance slider
' The audio sliders controlled by the player are only for input by the user. The values of
' the sliders should not be set from code. If you want to change the audio properties (and
' the sliders values) of the player, use the audio methods of the player, for example:
' myPlayer.Audio.Volume = 500
' To remove a slider from the player set the slider to Nothing:
' myPlayer.Sliders.AudioVolume = Nothing
' **** 7. AUDIO VALUES ********************************************************************
' To get the changed values of the player's audio volume and balance use these events:
AddHandler myPlayer.Events.MediaAudioVolumeChanged, AddressOf MyPlayer_MediaAudioVolumeChanged
AddHandler myPlayer.Events.MediaAudioBalanceChanged, AddressOf MyPlayer_MediaAudioBalanceChanged
' please see the eventhandlers below.
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 8. AUDIO OUTPUT PEAK LEVELS ********************************************************
' From version 0.91, the use of the 'Stereo Mix' device has been replaced by the use of
' some functions from the Windows Core Audio Api (Windows Vista or higher only).
' Audio output levels can be used to display the peak levels of the system's default audio
' output device (eg speakers) in a numeric or graphical (eg level/vu meters) form or for
' other purposes.
' To get the audio peak values from the system default audio device you can use the
' MediaPeakLevelChanged event of the player:
AddHandler myPlayer.Events.MediaPeakLevelChanged, AddressOf MyPlayer_MediaPeakLevelChanged
' see the eventhandler below.
' Check if there is an audio device or if this function is not supported (Windows Vista or
' higher) with: If myPlayer.LastError Then ...
' The values received in the eventhandler are between 0.0 and 1.0 (inclusive) or -1 when media
' playback has paused, stopped or ended - for every audio channel (usually 2 for stereo).
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 9. MOUSE EVENTS ON DISPLAY, MOVIE OR OVERLAY ***************************************
' Note: Because of the new drag option (see item #15 below) this option is now left unused.
' Normally you don't get mouse events from a (MCI) movie window, but with this you can:
' AddHandler myPlayer.Events.MediaMouseClick, AddressOf myPlayer_MediaMouseClick
' it combines mouse events for display, movie and overlay in one, so you always can get a
' mouse event (click, move, wheel etc.) on a player's display. Also see: myPlayer.PointTo
' For completeness, mouse click event handlers are added for the display clones which are
' 'normal' controls with 'normal' mouse events:
AddHandler Panel1.MouseDown, AddressOf Clone_MouseClick ' Using mousedown for speed
'AddHandler Panel3.MouseDown, AddressOf Clone_MouseClick ' fast mouseclick = dubbelclick
' please see the eventhandlers below.
' **** 10. MEDIA FINISHED PLAYING *********************************************************
' You may want to know when media has finished playing to play other (next) media and/or
' stop certain processes (e.g. animation on a display overlay).
' To detect that media has finished playing just subscribe to the MediaEnded event:
AddHandler myPlayer.Events.MediaEnded, AddressOf MyPlayer_MediaEnded
' You don't want new media started from the MediaEnded event before all processes have
' been notified that the previous media has finished playing, so there's another event:
AddHandler myPlayer.Events.MediaEndedNotice, AddressOf MyPlayer_MediaEndedNotice
' You can use this event to just stop any active processes (and not start any new media).
' (With the MediaStarted event you can (re)start processes when new media starts playing.)
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 11. MEDIA SUBTITLES ****************************************************************
' You can get the SubRip (.srt) subtitles (if any) of the playing media by subscribing to
' the MediaSubtitleChanged event:
AddHandler myPlayer.Events.MediaSubtitleChanged, AddressOf MyPlayer_MediaSubtitleChanged
' please see the eventhandler below.
' By default the subtitles file should be in the same folder and with the same name (but
' with the .srt extension) as the media file, or one of its containing folders. You can
' specify to search in any containing folders with (0 = media file 'base' folder):
myPlayer.Subtitles.DirectoryDepth = 1 ' search base folder and containing folders 1 deep
' If the subtitles file is located somewhere else or it has another name, you can specify
' where to search with the myPlayer.Subtitles.Directory and/or myPlayer.Subtitles.FileName
' functions. The Folder depth search applies also to this location.
' There are some more convenient functions, e.g. to synchronize subtitles (TimeShift).
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 12. MEDIA TAG INFORMATION (MP3 (ID3) AND WMA (ASF) TAGS) ***************************
' You can get media tag information (MP3 (ID3) or WMA (ASF) Tags) with:
' TagInfo info = myPlayer.Media.GetTagInfo()
' Please see the methods PlayMedia, MyPlayer_MediaEnded, MyPlayer_MediaStopped and
' DisposeTagInfo for an example of the use of the media tag information option.
' **** 13. PLAY (OR REPEAT) ONLY A PART OF A MEDIA FILE ***********************************
' N.B. 'Begin' and 'End' is used to indicate the natural begin and end of media
' 'Start' and 'Stop' is used to indicate the actual start and stop positions of media
' If not changed, 'Start' and 'Stop' values are the same as 'Begin' and 'End' values.
' You can play (or repeat) only a part of a media file by specifying the start- and/or stopposition:
' a. before media starts playing, e.g. from 00:10:15 to 00:20:00 (uses '...Next' keywords):
' myPlayer.Media.StartPositionNext = New TimeSpan(0, 10, 15)
' myPlayer.Media.StopPositionNext = TimeSpan.FromMinutes(20)
'
' b. while media is playing, e.g. finish in 10 minutes from the current position:
' myPlayer.Media.StopPosition = myPlayer.Position.FromBegin + TimeSpan.FromMinutes(10)
' **** 14. ADD A TASKBAR PROGRESS INDICATOR ***********************************************
' To add a progress indicator in the taskbar button of a Form, all you have to do is instruct
' the player to do so by specifying the Form
myPlayer.TaskbarProgress.Add(Me)
' You can specify any Form you like (not just the Form the display of the player is on) and use
' multiple and/or duplicate Forms.
' You can specify the mode of the progress indicator (progress (default) or track (= 'begin to end')):
myPlayer.TaskbarProgress.Mode = TaskbarProgressMode.Track
' **** 15. DRAG A FORM BY DRAGGING A PLAYER'S DISPLAY WINDOW ******************************
' In some cases it may be convenient to drag a Form not only by its title bar but also by a
' player's display window on the Form. You can enable this option with:
myPlayer.Display.DragEnabled = True
' You can specify the mouse cursor being used while dragging the Form/display window, e.g.
myPlayer.Display.DragCursor = Cursors.SizeAll 'SizeAll' is also the default drag cursor
' If you need to process other mouse events (like in item #9 above) or for other reasons,
' you can disable this option (if you had previously enabled it) with:
' myPlayer.Display.DragEnabled = False
' **** 16. ADD AN INFO LABEL TO THE PLAYER'S POSITION SLIDER *******************************
' Displaying slider information with an info label is made easy with the slider methods
' 'myPlayer.Sliders.ValueToPoint' gives the x/y-coordinate of a value on the slider and
' 'myPlayer.Sliders.PointToValue' gives the value of the slider at a certain x/y-coordinate.
' These methods can be used for any .net trackbar (not just the PVS.AVPlayer sliders).
' (Without a player you can use: SliderValue.ToPoint or SliderValue.FromPoint)
' Info Labels can be used 'everywhere', not just with sliders as in this example.
' Just use the info label Show method to display an info label wherever you want.
' The location of the info label is determined by the specified location in the Show method
' and the Align (e.g. TopCenter (default)) and AlignOffset settings.
' The size of the info label is determined by font, bordersize, etc. but the 'additional' size
' is set with the TextMargin (or TextSize for a fixed size info label) option.
' Most options will probably be clear, but here's some tips:
' - border and other brushes: first set the full size of the info label (e.g. fontsize,
' bordersize etc. etc. and, in most cases, also a 'dummy' text) then create the brush
' - setting a fixed size info label, same as with brushes and then use:
' myInfoLabel.TextSize = myInfoLabel.TextSize; // this sets the current size and autosize to false
' - the order in which the settings are made can be important.
' Create an info label for use with all sliders in this application:
myInfoLabel = New InfoLabel() ' create an info label
myInfoLabel.RoundedCorners = True ' use rounded corners
myInfoLabel.FontSize = 9.75F ' set font size (same as main window)
myInfoLabel.TextMargin = New Padding(2, 0, 2, 0) ' fine tuning inner spacing
myInfoLabel.AlignOffset = New Point(0, 7) ' move closer to slider thumb
' Here are some more examples (uncomment one at a time):
' for the background any type of brush can be used (uncomment only this one to use)
'Dim myBackBrush As LinearGradientBrush = New LinearGradientBrush(New Rectangle(New Point(0, 0), myInfoLabel.Size), SystemColors.ButtonHighlight, SystemColors.ButtonShadow, LinearGradientMode.Vertical)
'myInfoLabel.BackBrush = myBackBrush
' or maybe no background at all (uncomment only this one to use):
'myInfoLabel.ForeColor = Color.Red
'myInfoLabel.BackColor = Color.OrangeRed ' reduce visible edges around the text (anti-aliasing on transparent background)
'myInfoLabel.BorderThickness = New Padding(0)
'myInfoLabel.FontSize = 36
'myInfoLabel.Transparent = True
' here's a fixed size info label with a background picture (uncomment only this one to use):
'myInfoLabel.TextMargin = New Padding(10, 70, 10, 10)
'myInfoLabel.ForeColor = Color.White
'myInfoLabel.Text = "Balance: Right 10.0" ' set size with the 'longest' possible text
'myInfoLabel.TextSize = myInfoLabel.TextSize ' set size + autosize off
'Dim infoImage As Image = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg")
'myInfoLabel.BackImage = infoImage ' set image after turning off autosize (with TextSize)
' Display an info label above the position slider's thumb using the slider's scroll event:
AddHandler TrackBar1.Scroll, AddressOf TrackBar1_Scroll ' please see below
' Same for the audio volume and balance sliders:
AddHandler TrackBar2.Scroll, AddressOf TrackBar2_Scroll ' please see below
AddHandler TrackBar3.Scroll, AddressOf TrackBar3_Scroll ' please see below
' **** 17. CHANGE THE SHAPE OF THE PLAYER'S DISPLAY WINDOW ********************************
' The shape of a player's display can be changed from the usual rectangular shape to any
' other shape with the Player.Display.SetShape method.
'
' The shape of the display, a 'region', is provided by a special method (callback)
' called by the player when the size of the player's display window has changed.
' PVS.AVPlayer also provides some preset shapes.
'
' You can create a display shape callback method like this (use any method name you want):
'
' Private Function MyCallbackMethod(player As Player, videoShape As Boolean, shapeBounds As Rectangle) As Region
' Dim path As GraphicsPath = New GraphicsPath()
' path.AddEllipse(shapeBounds)
' Dim shapeRegion As New Region(path)
' path.Dispose()
' Return shapeRegion
' End Function
'
' You can activate the display (and optional overlay) shape with for example:
' myPlayer.Display.SetShape(AddressOf MyCallbackMethod, True, False)
' This sets the callback method and specifies using video bounds and a normal overlay.
' Or you can use one of the preset display shapes (without a callback method), e.g.
' myPlayer.Display.SetShape(DisplayShape.Oval)
' Custom shaped overlays may not display (background colors) properly with display clones.
' When using custom display shapes (eg in full-screen mode), underlying interface items may
' become visible that were not visible with a normally formed display.
' Display shapes are activated and deactivated with CheckBox4.CheckedChanged - see below
' **** 18. USING MEDIA SIGNALS ************************************************************
' If you want to be informed that a certain media playback time has been reached, you can
' use "media signals":
'
' You can create media signals:
' a. by creating a .msf (media signals file) file to be used with certain media, or
' b. with the Player.Signals.Add method while media is playing
'
' You can receive media signals by subscribing to the Player.Events.MediaSignal event:
' AddHandler myPlayer.Events.MediaSignal, AddressOf MyPlayer_MediaSignal
'
' The media signal eventhandler:
' Private Sub MyPlayer_MediaSignal(sender As Object, e As SignalEventArgs)
' ' signal index = e.Index
' ' signal message = e.Message
' End Sub
'
' There are no "standard messages" in media signals, you must use your own "system" to
' set and interpret the media signal messages.
'
' For more information please see the file "About PVS.AVPlayer versions.txt", version 0.85
' **** 19. AUTOMATICALLY HIDE THE MOUSE CURSOR DURING MEDIA PLAYBACK *********************
' If you want to keep the mouse cursor 'out of the way' when a movie (or any other media)
' is playing, you can use the "Player.CursorHide" methods of the player. By specifying the
' form(s) on which the cursor is to be hidden, the player automatically hides the cursor on
' those forms (when in the foreground) when media is played and the mouse has not been used
' for a while, for example on this form:
myPlayer.CursorHide.Add(Me)
' You can add as many "cursor hiding" forms to the player as you like, for example forms
' that contain a display clone of the player or even forms that are not directly related
' to the player.
' If you want to be notified when the mouse cursor is hidden or shown by the player, you can
' subscribe to the "Player.Events.MediaCursorHideChanged" event (see eventhandler below):
AddHandler myPlayer.Events.MediaCursorHideChanged, AddressOf MyPlayer_MediaCursorHideChanged
End Sub
' Display overlay right from the start - handler created from the designer
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
' show the display overlay at the start of the application (even if no movie is playing):
' this instruction is put here because the player's display has to be 'created and visible'
' to show the overlay
myPlayer.Overlay.Hold = True
End Sub
' Clean Up - this is moved here from the 'Form1.Designer.vb' file and appended:
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If Not wasDisposed Then
wasDisposed = True
If disposing Then
' disposing a player also stops its overlay, display clones, eventhandlers etc.
myPlayer.Dispose() ' dispose the player
myOverlay.Dispose() ' dispose the display overlay
myOpenFileDlg.Dispose() ' dispose the file selector
If myInfoLabel IsNot Nothing Then
myInfoLabel.Dispose()
End If
' used by the designer - clean up
If components IsNot Nothing Then components.Dispose()
End If
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
' Dispose media tag info
Private Sub DisposeTagInfo()
If myTagInfo IsNot Nothing Then
myOverlay.subtitlesLabel.Text = String.Empty
Panel1.BackgroundImage = Nothing
myTagInfo.Dispose()
myTagInfo = Nothing
End If
End Sub
#End Region
' **** Media Play / Pause - Resume / Stop *****************************************************
#Region "Media Play / Pause - Resume / Stop"
Private Sub PlayMedia()
' select and play media
If (myOpenFileDlg.ShowDialog() = DialogResult.OK) Then
myPlayer.Play(myOpenFileDlg.FileName)
If (myPlayer.LastError) Then
MessageBox.Show(myPlayer.LastErrorString)
Else
' show media tag information (for audio media only)
If Not myPlayer.HasVideo Then
myTagInfo = myPlayer.Media.GetTagInfo()
Panel1.BackgroundImageLayout = ImageLayout.Zoom
Panel1.BackgroundImage = myTagInfo.Image
myOverlay.subtitlesLabel.Text = myTagInfo.Artist + vbNewLine + myTagInfo.Title
End If
End If
End If
End Sub
Private Sub PauseMedia()
myPlayer.Paused = Not myPlayer.Paused
If (myPlayer.Paused) Then
Button2.Text = "Resume"
Else
Button2.Text = "Pause"
End If
End Sub
Private Sub StopMedia()
myPlayer.Stop()
End Sub
#End Region
' **** Player Eventhandlers *******************************************************************
#Region "Player Eventhandlers"
' Show changed audio volume value
Private Sub MyPlayer_MediaAudioVolumeChanged(sender As Object, e As EventArgs)
Label3.Text = myPlayer.Audio.Volume.ToString()
End Sub
' Show changed audio balance value
Private Sub MyPlayer_MediaAudioBalanceChanged(sender As Object, e As EventArgs)
Label4.Text = myPlayer.Audio.Balance.ToString()
End Sub
' Display the elapsed and remaining playback time
Private Sub MyPlayer_MediaPositionChanged(sender As Object, e As PositionEventArgs)
Label1.Text = e.FromStart.ToString().Substring(0, 8) ' "hh:mm:ss"
Label2.Text = e.ToStop.ToString().Substring(0, 8) ' "hh:mm:ss"
' from .NET 4.0 TimeSpan supports (custom) format strings e.g.
' Label1.Text = e.FromStart.ToString("hh\:mm\:ss") ' "hh:mm:ss"
End Sub
' Handle media audio output peak levels - calculate the values and paint the level displays
Private Sub MyPlayer_MediaPeakLevelChanged(sender As Object, e As PeakLevelEventArgs)
' you could add some 'logic' here to make the movements of the indicators less 'jumpy'
If e.MasterPeakValue = -1 Then ' Media playback has stopped or paused or volume set to 0
' graphical presentation
leftLevel = 0
rightLevel = 0
' value display
Label5.Text = "0.00" ' same format as below
Label6.Text = "0.00"
Else
' check e.ChannelCount for more than 2 (= stereo) channels
' if you want to display the peak levels of all audio channels
' graphical presentation
leftLevel = CInt(e.ChannelsValues(0) * levelUnit) ' levelUnit is the width of panel4 and 5
rightLevel = CInt(e.ChannelsValues(1) * levelUnit)
' value display (use string format because of 'Single' rounding errors - zero can become a small value):
Label5.Text = e.ChannelsValues(0).ToString("0.00")
Label6.Text = e.ChannelsValues(1).ToString("0.00")
End If
Panel4.Invalidate() ' draw the new values
Panel5.Invalidate()
End Sub
Continue reading...
i build a new software a media player and i need to perform mouse right click on the video screen and do something on this case made a panel visible
I use a different player i have modified to make a DJ version of it
I have take the example on codeproject
This is my code
#Region "Imports"
Imports System.Text
Imports PVS.AVPlayer
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Diagnostics
Imports Emgu.CV
Imports Emgu.CV.UI
Imports Emgu.CV.Structure
#End Region
Public Class Form1
' **** Class Fields ***************************************************************************
#Region "Class Fields"
Private Angle As Double = 270
Dim folderxxl As String
Dim xbit As Integer = 0
Dim ybit As Integer = 0
Dim txBrush As TextureBrush
Dim Off As Point
Dim a As String = CSng(1000 * Angle / 360).ToString("f1")
Private myPlayer As Player
Private myOverlay As Overlay ' in file Overlay.vb
Private shapeStatus As Integer ' shapes - 0:none, 1val, 2:none, 3:rounded, 4:none, 5:star
Private myInfoLabel As InfoLabel
Private myInfoLabelText As StringBuilder = New StringBuilder(64)
' used with drawing audio output levels
' levelUnit = size of 1 unit (of 32767) / 140 = width of Panel4 and Panel5
Private levelUnit As Double = 140 ' / 32767.0 - changed in PVS.AVPlayer version 0.91
Private leftLevel As Integer
Private rightLevel As Integer
Private myTagInfo As TagInfo ' media (audio mp3/wma/asf) tag info
Private myOpenFileDlg As OpenFileDialog ' used with selection of media to play
Private Const OPENMEDIA_FILTER As String =
" Video Files (*.*)|*.asf;*.avi;*.bik;*.divx;*.dvx;*.f4v;*.flv;*.h264;*.hdmov;*.m2ts;*.mkv;*.mod;*.mov;*.mp2;*.mp4;*.mpeg;*.mpeg4;*.mpg;*.mpv;*.ogg;*.ogm;*.ogv;*.qt;*.rm;*.rms;*.rmvb;*.swf;*.ts;*.vfw;*.vob;*.webm;*.wmv;*.xvid|" +
" Audio Files (*.*)|*.3gp;*.aa;*.aac;*.aiff;*.amr;*.ape;*.flac;*.m4a;*.mid;*.midi;*.mka;*.mp3;*.mpc;*.ogg;*.opus;*.ra;*.rm;*.wav;*.webm;*.wma;*.wv|" +
" Image Files (*.*)|*.bmp;*.gif;*.img;*.jpeg;*.jpg;*.png;*.tga;*.tiff|" +
" All Files|*.*"
Private isInitializing As Boolean
Private wasDisposed As Boolean
#End Region
' **** Main ***********************************************************************************
#Region "Main"
Public Sub New()
isInitializing = True
InitializeComponent() ' this call is required by the designer
isInitializing = False
myPlayer = New Player() ' create a player
myPlayer.Display.Window = Panel1 ' and set its display to Panel1
myPlayer.Repeat = True ' repeat media playback when finished
myPlayer.SleepDisabled = True ' prevent the computer from entering sleep mode
' create a file selector
myOpenFileDlg = New OpenFileDialog() With
{
.Title = "Play Media",
.Filter = OPENMEDIA_FILTER,
.FilterIndex = 4
}
' You might want to add one or more of the following options to your player:
' **** 1. DISPLAY OVERLAY *****************************************************************
' A display overlay is a Form that allows you to display items on top of a movie.
' The sample overlay 'Overlay' is created with the designer - please see Overlay.vb
myOverlay = New Overlay() ' create (an instance of) the overlay
myPlayer.Overlay.Window = myOverlay ' and attach it to the player
' To remove a display overlay from the player set the overlay window to another overlay
' or to Nothing: myPlayer.Overlay.Window = Nothing
' **** 2. DISPLAY OVERLAY ALWAYS VISIBLE **************************************************
' A display overlay is usually only shown when media is playing, but if you want to always
' show the overlay you can use: myPlayer.Overlay.Hold = True
' The player's display has to be created and visible for this, so if you want
' to show the overlay right from the start of your application (without media playing) you
' have to put the 'Overlay.Hold' instruction in the Form1.Shown event handler (see below).
' **** 3. DISPLAY CLONES ******************************************************************
' For special purposes you can create one or more player display clones (display copies).
' Display clones require sufficient computing (cpu) power and may slow some computers:
'myPlayer.DisplayClones.AddRange(New Control() {Panel2, Panel3})
' cpu load can be reduced by lowering the framerate, quality or size of the clones:
' e.g. myPlayer.DisplayClones.FrameRate = 10
' You can also 'stretch' display clones (as with displaymode.stretch of the main display):
'myPlayer.DisplayClones.SetLayout(Panel2, CloneLayout.Stretch)
' To remove display clones from the player use one of the clones remove methods, e.g.:
myPlayer.DisplayClones.Remove(Panel2)
' **** 4. POSITION SLIDER *****************************************************************
' The player can control your media playback position slider (trackbar) with:
myPlayer.Sliders.Position = TrackBar1
'myPlayer.Sliders.Position = GTrackBar3.Value
' The position slider controlled by the player is only for input by the user. The value of
' the slider should not be set from code. If you want to change the playback position (and
' the slider value), use the position methods of the player, for example:
' myPlayer.Position.FromBegin = TimeSpan.FromSeconds(30).
' To remove a slider from the player set the slider to Nothing:
' myPlayer.Sliders.Position = Nothing
' **** 5. POSITION TIME *******************************************************************
' If you want to display the elapsed and/or remaining media playback time (or use your
' 'own' position slider) you can get continuous media playback position information with:
AddHandler myPlayer.Events.MediaPositionChanged, AddressOf MyPlayer_MediaPositionChanged
' please see the eventhandler below.
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 6. AUDIO SLIDERS *******************************************************************
' The player can also control your audio sliders (trackbars) with:
myPlayer.Sliders.AudioVolume = TrackBar2 ' audio volume slider
myPlayer.Sliders.AudioBalance = TrackBar3 ' audio balance slider
' The audio sliders controlled by the player are only for input by the user. The values of
' the sliders should not be set from code. If you want to change the audio properties (and
' the sliders values) of the player, use the audio methods of the player, for example:
' myPlayer.Audio.Volume = 500
' To remove a slider from the player set the slider to Nothing:
' myPlayer.Sliders.AudioVolume = Nothing
' **** 7. AUDIO VALUES ********************************************************************
' To get the changed values of the player's audio volume and balance use these events:
AddHandler myPlayer.Events.MediaAudioVolumeChanged, AddressOf MyPlayer_MediaAudioVolumeChanged
AddHandler myPlayer.Events.MediaAudioBalanceChanged, AddressOf MyPlayer_MediaAudioBalanceChanged
' please see the eventhandlers below.
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 8. AUDIO OUTPUT PEAK LEVELS ********************************************************
' From version 0.91, the use of the 'Stereo Mix' device has been replaced by the use of
' some functions from the Windows Core Audio Api (Windows Vista or higher only).
' Audio output levels can be used to display the peak levels of the system's default audio
' output device (eg speakers) in a numeric or graphical (eg level/vu meters) form or for
' other purposes.
' To get the audio peak values from the system default audio device you can use the
' MediaPeakLevelChanged event of the player:
AddHandler myPlayer.Events.MediaPeakLevelChanged, AddressOf MyPlayer_MediaPeakLevelChanged
' see the eventhandler below.
' Check if there is an audio device or if this function is not supported (Windows Vista or
' higher) with: If myPlayer.LastError Then ...
' The values received in the eventhandler are between 0.0 and 1.0 (inclusive) or -1 when media
' playback has paused, stopped or ended - for every audio channel (usually 2 for stereo).
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 9. MOUSE EVENTS ON DISPLAY, MOVIE OR OVERLAY ***************************************
' Note: Because of the new drag option (see item #15 below) this option is now left unused.
' Normally you don't get mouse events from a (MCI) movie window, but with this you can:
' AddHandler myPlayer.Events.MediaMouseClick, AddressOf myPlayer_MediaMouseClick
' it combines mouse events for display, movie and overlay in one, so you always can get a
' mouse event (click, move, wheel etc.) on a player's display. Also see: myPlayer.PointTo
' For completeness, mouse click event handlers are added for the display clones which are
' 'normal' controls with 'normal' mouse events:
AddHandler Panel1.MouseDown, AddressOf Clone_MouseClick ' Using mousedown for speed
'AddHandler Panel3.MouseDown, AddressOf Clone_MouseClick ' fast mouseclick = dubbelclick
' please see the eventhandlers below.
' **** 10. MEDIA FINISHED PLAYING *********************************************************
' You may want to know when media has finished playing to play other (next) media and/or
' stop certain processes (e.g. animation on a display overlay).
' To detect that media has finished playing just subscribe to the MediaEnded event:
AddHandler myPlayer.Events.MediaEnded, AddressOf MyPlayer_MediaEnded
' You don't want new media started from the MediaEnded event before all processes have
' been notified that the previous media has finished playing, so there's another event:
AddHandler myPlayer.Events.MediaEndedNotice, AddressOf MyPlayer_MediaEndedNotice
' You can use this event to just stop any active processes (and not start any new media).
' (With the MediaStarted event you can (re)start processes when new media starts playing.)
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 11. MEDIA SUBTITLES ****************************************************************
' You can get the SubRip (.srt) subtitles (if any) of the playing media by subscribing to
' the MediaSubtitleChanged event:
AddHandler myPlayer.Events.MediaSubtitleChanged, AddressOf MyPlayer_MediaSubtitleChanged
' please see the eventhandler below.
' By default the subtitles file should be in the same folder and with the same name (but
' with the .srt extension) as the media file, or one of its containing folders. You can
' specify to search in any containing folders with (0 = media file 'base' folder):
myPlayer.Subtitles.DirectoryDepth = 1 ' search base folder and containing folders 1 deep
' If the subtitles file is located somewhere else or it has another name, you can specify
' where to search with the myPlayer.Subtitles.Directory and/or myPlayer.Subtitles.FileName
' functions. The Folder depth search applies also to this location.
' There are some more convenient functions, e.g. to synchronize subtitles (TimeShift).
' To unsubscribe from the event you can use the RemoveHandler statement.
' **** 12. MEDIA TAG INFORMATION (MP3 (ID3) AND WMA (ASF) TAGS) ***************************
' You can get media tag information (MP3 (ID3) or WMA (ASF) Tags) with:
' TagInfo info = myPlayer.Media.GetTagInfo()
' Please see the methods PlayMedia, MyPlayer_MediaEnded, MyPlayer_MediaStopped and
' DisposeTagInfo for an example of the use of the media tag information option.
' **** 13. PLAY (OR REPEAT) ONLY A PART OF A MEDIA FILE ***********************************
' N.B. 'Begin' and 'End' is used to indicate the natural begin and end of media
' 'Start' and 'Stop' is used to indicate the actual start and stop positions of media
' If not changed, 'Start' and 'Stop' values are the same as 'Begin' and 'End' values.
' You can play (or repeat) only a part of a media file by specifying the start- and/or stopposition:
' a. before media starts playing, e.g. from 00:10:15 to 00:20:00 (uses '...Next' keywords):
' myPlayer.Media.StartPositionNext = New TimeSpan(0, 10, 15)
' myPlayer.Media.StopPositionNext = TimeSpan.FromMinutes(20)
'
' b. while media is playing, e.g. finish in 10 minutes from the current position:
' myPlayer.Media.StopPosition = myPlayer.Position.FromBegin + TimeSpan.FromMinutes(10)
' **** 14. ADD A TASKBAR PROGRESS INDICATOR ***********************************************
' To add a progress indicator in the taskbar button of a Form, all you have to do is instruct
' the player to do so by specifying the Form
myPlayer.TaskbarProgress.Add(Me)
' You can specify any Form you like (not just the Form the display of the player is on) and use
' multiple and/or duplicate Forms.
' You can specify the mode of the progress indicator (progress (default) or track (= 'begin to end')):
myPlayer.TaskbarProgress.Mode = TaskbarProgressMode.Track
' **** 15. DRAG A FORM BY DRAGGING A PLAYER'S DISPLAY WINDOW ******************************
' In some cases it may be convenient to drag a Form not only by its title bar but also by a
' player's display window on the Form. You can enable this option with:
myPlayer.Display.DragEnabled = True
' You can specify the mouse cursor being used while dragging the Form/display window, e.g.
myPlayer.Display.DragCursor = Cursors.SizeAll 'SizeAll' is also the default drag cursor
' If you need to process other mouse events (like in item #9 above) or for other reasons,
' you can disable this option (if you had previously enabled it) with:
' myPlayer.Display.DragEnabled = False
' **** 16. ADD AN INFO LABEL TO THE PLAYER'S POSITION SLIDER *******************************
' Displaying slider information with an info label is made easy with the slider methods
' 'myPlayer.Sliders.ValueToPoint' gives the x/y-coordinate of a value on the slider and
' 'myPlayer.Sliders.PointToValue' gives the value of the slider at a certain x/y-coordinate.
' These methods can be used for any .net trackbar (not just the PVS.AVPlayer sliders).
' (Without a player you can use: SliderValue.ToPoint or SliderValue.FromPoint)
' Info Labels can be used 'everywhere', not just with sliders as in this example.
' Just use the info label Show method to display an info label wherever you want.
' The location of the info label is determined by the specified location in the Show method
' and the Align (e.g. TopCenter (default)) and AlignOffset settings.
' The size of the info label is determined by font, bordersize, etc. but the 'additional' size
' is set with the TextMargin (or TextSize for a fixed size info label) option.
' Most options will probably be clear, but here's some tips:
' - border and other brushes: first set the full size of the info label (e.g. fontsize,
' bordersize etc. etc. and, in most cases, also a 'dummy' text) then create the brush
' - setting a fixed size info label, same as with brushes and then use:
' myInfoLabel.TextSize = myInfoLabel.TextSize; // this sets the current size and autosize to false
' - the order in which the settings are made can be important.
' Create an info label for use with all sliders in this application:
myInfoLabel = New InfoLabel() ' create an info label
myInfoLabel.RoundedCorners = True ' use rounded corners
myInfoLabel.FontSize = 9.75F ' set font size (same as main window)
myInfoLabel.TextMargin = New Padding(2, 0, 2, 0) ' fine tuning inner spacing
myInfoLabel.AlignOffset = New Point(0, 7) ' move closer to slider thumb
' Here are some more examples (uncomment one at a time):
' for the background any type of brush can be used (uncomment only this one to use)
'Dim myBackBrush As LinearGradientBrush = New LinearGradientBrush(New Rectangle(New Point(0, 0), myInfoLabel.Size), SystemColors.ButtonHighlight, SystemColors.ButtonShadow, LinearGradientMode.Vertical)
'myInfoLabel.BackBrush = myBackBrush
' or maybe no background at all (uncomment only this one to use):
'myInfoLabel.ForeColor = Color.Red
'myInfoLabel.BackColor = Color.OrangeRed ' reduce visible edges around the text (anti-aliasing on transparent background)
'myInfoLabel.BorderThickness = New Padding(0)
'myInfoLabel.FontSize = 36
'myInfoLabel.Transparent = True
' here's a fixed size info label with a background picture (uncomment only this one to use):
'myInfoLabel.TextMargin = New Padding(10, 70, 10, 10)
'myInfoLabel.ForeColor = Color.White
'myInfoLabel.Text = "Balance: Right 10.0" ' set size with the 'longest' possible text
'myInfoLabel.TextSize = myInfoLabel.TextSize ' set size + autosize off
'Dim infoImage As Image = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg")
'myInfoLabel.BackImage = infoImage ' set image after turning off autosize (with TextSize)
' Display an info label above the position slider's thumb using the slider's scroll event:
AddHandler TrackBar1.Scroll, AddressOf TrackBar1_Scroll ' please see below
' Same for the audio volume and balance sliders:
AddHandler TrackBar2.Scroll, AddressOf TrackBar2_Scroll ' please see below
AddHandler TrackBar3.Scroll, AddressOf TrackBar3_Scroll ' please see below
' **** 17. CHANGE THE SHAPE OF THE PLAYER'S DISPLAY WINDOW ********************************
' The shape of a player's display can be changed from the usual rectangular shape to any
' other shape with the Player.Display.SetShape method.
'
' The shape of the display, a 'region', is provided by a special method (callback)
' called by the player when the size of the player's display window has changed.
' PVS.AVPlayer also provides some preset shapes.
'
' You can create a display shape callback method like this (use any method name you want):
'
' Private Function MyCallbackMethod(player As Player, videoShape As Boolean, shapeBounds As Rectangle) As Region
' Dim path As GraphicsPath = New GraphicsPath()
' path.AddEllipse(shapeBounds)
' Dim shapeRegion As New Region(path)
' path.Dispose()
' Return shapeRegion
' End Function
'
' You can activate the display (and optional overlay) shape with for example:
' myPlayer.Display.SetShape(AddressOf MyCallbackMethod, True, False)
' This sets the callback method and specifies using video bounds and a normal overlay.
' Or you can use one of the preset display shapes (without a callback method), e.g.
' myPlayer.Display.SetShape(DisplayShape.Oval)
' Custom shaped overlays may not display (background colors) properly with display clones.
' When using custom display shapes (eg in full-screen mode), underlying interface items may
' become visible that were not visible with a normally formed display.
' Display shapes are activated and deactivated with CheckBox4.CheckedChanged - see below
' **** 18. USING MEDIA SIGNALS ************************************************************
' If you want to be informed that a certain media playback time has been reached, you can
' use "media signals":
'
' You can create media signals:
' a. by creating a .msf (media signals file) file to be used with certain media, or
' b. with the Player.Signals.Add method while media is playing
'
' You can receive media signals by subscribing to the Player.Events.MediaSignal event:
' AddHandler myPlayer.Events.MediaSignal, AddressOf MyPlayer_MediaSignal
'
' The media signal eventhandler:
' Private Sub MyPlayer_MediaSignal(sender As Object, e As SignalEventArgs)
' ' signal index = e.Index
' ' signal message = e.Message
' End Sub
'
' There are no "standard messages" in media signals, you must use your own "system" to
' set and interpret the media signal messages.
'
' For more information please see the file "About PVS.AVPlayer versions.txt", version 0.85
' **** 19. AUTOMATICALLY HIDE THE MOUSE CURSOR DURING MEDIA PLAYBACK *********************
' If you want to keep the mouse cursor 'out of the way' when a movie (or any other media)
' is playing, you can use the "Player.CursorHide" methods of the player. By specifying the
' form(s) on which the cursor is to be hidden, the player automatically hides the cursor on
' those forms (when in the foreground) when media is played and the mouse has not been used
' for a while, for example on this form:
myPlayer.CursorHide.Add(Me)
' You can add as many "cursor hiding" forms to the player as you like, for example forms
' that contain a display clone of the player or even forms that are not directly related
' to the player.
' If you want to be notified when the mouse cursor is hidden or shown by the player, you can
' subscribe to the "Player.Events.MediaCursorHideChanged" event (see eventhandler below):
AddHandler myPlayer.Events.MediaCursorHideChanged, AddressOf MyPlayer_MediaCursorHideChanged
End Sub
' Display overlay right from the start - handler created from the designer
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
' show the display overlay at the start of the application (even if no movie is playing):
' this instruction is put here because the player's display has to be 'created and visible'
' to show the overlay
myPlayer.Overlay.Hold = True
End Sub
' Clean Up - this is moved here from the 'Form1.Designer.vb' file and appended:
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If Not wasDisposed Then
wasDisposed = True
If disposing Then
' disposing a player also stops its overlay, display clones, eventhandlers etc.
myPlayer.Dispose() ' dispose the player
myOverlay.Dispose() ' dispose the display overlay
myOpenFileDlg.Dispose() ' dispose the file selector
If myInfoLabel IsNot Nothing Then
myInfoLabel.Dispose()
End If
' used by the designer - clean up
If components IsNot Nothing Then components.Dispose()
End If
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
' Dispose media tag info
Private Sub DisposeTagInfo()
If myTagInfo IsNot Nothing Then
myOverlay.subtitlesLabel.Text = String.Empty
Panel1.BackgroundImage = Nothing
myTagInfo.Dispose()
myTagInfo = Nothing
End If
End Sub
#End Region
' **** Media Play / Pause - Resume / Stop *****************************************************
#Region "Media Play / Pause - Resume / Stop"
Private Sub PlayMedia()
' select and play media
If (myOpenFileDlg.ShowDialog() = DialogResult.OK) Then
myPlayer.Play(myOpenFileDlg.FileName)
If (myPlayer.LastError) Then
MessageBox.Show(myPlayer.LastErrorString)
Else
' show media tag information (for audio media only)
If Not myPlayer.HasVideo Then
myTagInfo = myPlayer.Media.GetTagInfo()
Panel1.BackgroundImageLayout = ImageLayout.Zoom
Panel1.BackgroundImage = myTagInfo.Image
myOverlay.subtitlesLabel.Text = myTagInfo.Artist + vbNewLine + myTagInfo.Title
End If
End If
End If
End Sub
Private Sub PauseMedia()
myPlayer.Paused = Not myPlayer.Paused
If (myPlayer.Paused) Then
Button2.Text = "Resume"
Else
Button2.Text = "Pause"
End If
End Sub
Private Sub StopMedia()
myPlayer.Stop()
End Sub
#End Region
' **** Player Eventhandlers *******************************************************************
#Region "Player Eventhandlers"
' Show changed audio volume value
Private Sub MyPlayer_MediaAudioVolumeChanged(sender As Object, e As EventArgs)
Label3.Text = myPlayer.Audio.Volume.ToString()
End Sub
' Show changed audio balance value
Private Sub MyPlayer_MediaAudioBalanceChanged(sender As Object, e As EventArgs)
Label4.Text = myPlayer.Audio.Balance.ToString()
End Sub
' Display the elapsed and remaining playback time
Private Sub MyPlayer_MediaPositionChanged(sender As Object, e As PositionEventArgs)
Label1.Text = e.FromStart.ToString().Substring(0, 8) ' "hh:mm:ss"
Label2.Text = e.ToStop.ToString().Substring(0, 8) ' "hh:mm:ss"
' from .NET 4.0 TimeSpan supports (custom) format strings e.g.
' Label1.Text = e.FromStart.ToString("hh\:mm\:ss") ' "hh:mm:ss"
End Sub
' Handle media audio output peak levels - calculate the values and paint the level displays
Private Sub MyPlayer_MediaPeakLevelChanged(sender As Object, e As PeakLevelEventArgs)
' you could add some 'logic' here to make the movements of the indicators less 'jumpy'
If e.MasterPeakValue = -1 Then ' Media playback has stopped or paused or volume set to 0
' graphical presentation
leftLevel = 0
rightLevel = 0
' value display
Label5.Text = "0.00" ' same format as below
Label6.Text = "0.00"
Else
' check e.ChannelCount for more than 2 (= stereo) channels
' if you want to display the peak levels of all audio channels
' graphical presentation
leftLevel = CInt(e.ChannelsValues(0) * levelUnit) ' levelUnit is the width of panel4 and 5
rightLevel = CInt(e.ChannelsValues(1) * levelUnit)
' value display (use string format because of 'Single' rounding errors - zero can become a small value):
Label5.Text = e.ChannelsValues(0).ToString("0.00")
Label6.Text = e.ChannelsValues(1).ToString("0.00")
End If
Panel4.Invalidate() ' draw the new values
Panel5.Invalidate()
End Sub
Continue reading...