How to avoid type casting exceptions when using the wmplib?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hmmmm having discovered that using the mciAPI doesnt utilise 5.1 sound, but using a virtual WMP does - I started a new approach to my multimedia project using some code from the net. BUT I keep getting exceptions (particularly with type casting). In the
subrountine Player_PlayStateChange.
The listing (see below) is now well commented by me. Can anybody please help concerning the damn annoying exceptions and stop me pulling my hair out. Thankyou in advance.
Allan

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Public <span style="color:Blue; Class _5dot1MP3player
<span style="color:Green; Adapted, modified and extended by Allan Mee (20011) from original code by Adam Speight (2008)
<span style="color:Green; at the following URL:
<span style="color:Green; http://www.dreamincode.net/forums/topic/57357-mymusic-player/
<span style="color:Green;
<span style="color:Green;
<span style="color:Blue; Private <span style="color:Blue; Sub _5dot1MP3player_FormClosed(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.FormClosedEventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.FormClosed
<span style="color:Green; Dispose of player
Player = <span style="color:Blue; Nothing
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub _5dot1MP3player_FormClosing(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.FormClosingEventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.FormClosing
<span style="color:Blue; If MessageBox.Show(<span style="color:#A31515; "Are you sure that you want to exit 5.1 MP3 Player?", <span style="color:#A31515; "Exit 5.1 MP3 Player", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = DialogResult.Yes <span style="color:Blue; Then
e.Cancel = <span style="color:Blue; False
<span style="color:Green; Form is closing, so shutdown player
Timer1.<span style="color:Blue; Stop()
Timer1.Enabled = <span style="color:Blue; False
Player.URL = <span style="color:#A31515; ""
Player.currentMedia.name = <span style="color:#A31515; ""
Player.currentPlaylist.clear()
Player.controls.<span style="color:Blue; stop()
Player.close()
Player = <span style="color:Blue; Nothing <span style="color:Green; Damn - how do I kill it???
<span style="color:Blue; Else
e.Cancel = <span style="color:Blue; True
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub _5dot1MP3player_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
<span style="color:Blue; Me.StartPosition = FormStartPosition.CenterScreen
TrackCol.Width = TrackList.Width - 20
TrackList.Scrollable = <span style="color:Blue; True
btnPause.Enabled = <span style="color:Blue; True
btnStop.Enabled = <span style="color:Blue; True
btnPlay.Enabled = <span style="color:Blue; False
files = FileIO.FileSystem.GetFiles(<span style="color:#A31515; "G:newmp3s", FileIO.SearchOption.SearchAllSubDirectories, <span style="color:#A31515; "*.mp3")
<span style="color:Green; files = FileIO.FileSystem.GetFiles("G:temp", FileIO.SearchOption.SearchAllSubDirectories, "*.mp3")
<span style="color:Blue; For <span style="color:Blue; Each a <span style="color:Blue; As <span style="color:Blue; String <span style="color:Blue; In files
<span style="color:Blue; Me.TrackList.Items.Add(FileIO.FileSystem.GetName(a))
<span style="color:Blue; Next
Player.settings.volume = 2
Volume.Value = Player.settings.volume
lblVolume.Text = Volume.Value
<span style="color:Blue; Me.Txt_TrackName.Text = Player.URL
Player.settings.autoStart = <span style="color:Blue; False <span style="color:Green; should in theory stop the player autoplaying
Player.URL = files(0)
TrackList.Items(CurrentPlaying).ForeColor = CurrentTrackColor
Txt_TrackName.Text = Player.currentMedia.name
<span style="color:Green; Txt_Progress.Text = Player.controls.currentPositionString & vbTab & Player.currentMedia.durationString
Player.enableContextMenu = <span style="color:Blue; False
<span style="color:Blue; With <span style="color:Blue; Me.Timer1
.Interval = 500
.Start()
.Enabled = <span style="color:Blue; True
<span style="color:Blue; End <span style="color:Blue; With
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; #Region <span style="color:#A31515; "Color Settings"
<span style="color:Blue; Dim CurrentTrackColor <span style="color:Blue; As System.Drawing.Color = Color.Red
<span style="color:Blue; Dim PausedTrackColor <span style="color:Blue; As System.Drawing.Color = Color.LightYellow
<span style="color:Blue; #End Region
<span style="color:Blue; Dim <span style="color:Blue; WithEvents Player <span style="color:Blue; As <span style="color:Blue; New WMPLib.WindowsMediaPlayer
<span style="color:Blue; Dim files <span style="color:Blue; As Collections.ObjectModel.ReadOnlyCollection(Of <span style="color:Blue; String)
<span style="color:Blue; Dim titles <span style="color:Blue; As <span style="color:Blue; New List(Of <span style="color:Blue; String)
<span style="color:Blue; Dim CurrentPlaying <span style="color:Blue; As <span style="color:Blue; Integer = 0
<span style="color:Blue; Dim PreviouslyPlaying <span style="color:Blue; As <span style="color:Blue; Integer = 0

<span style="color:Blue; Private <span style="color:Blue; Sub ClickedOnPlayButton(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
GUIMode(<span style="color:#A31515; "Play")
updatePlayer()
Player.controls.play()
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub ClickedonstopNutton(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
Player.controls.<span style="color:Blue; stop()
GUIMode(<span style="color:#A31515; "Stopped")
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub ClickedonpauseButton(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
<span style="color:Blue; If Player.playState = WMPLib.WMPPlayState.wmppsPaused <span style="color:Blue; Then
GUIMode(<span style="color:#A31515; "Play")
<span style="color:Blue; Else
GUIMode(<span style="color:#A31515; "Paused")
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub GUIMode(<span style="color:Blue; ByRef Guimode <span style="color:Blue; As <span style="color:Blue; String)
<span style="color:Blue; Select <span style="color:Blue; Case Guimode
<span style="color:Blue; Case <span style="color:#A31515; "Play"
<span style="color:Green; Put GUI in playing mode guise
Player.controls.play()
<span style="color:Green; btnPause.BackColor = System.Drawing.SystemColors.Control
btnPause.Enabled = <span style="color:Blue; True
btnStop.Enabled = <span style="color:Blue; True
btnPlay.Enabled = <span style="color:Blue; True
<span style="color:Blue; Case <span style="color:#A31515; "Paused"
<span style="color:Green; put gui in paused mode guise
btnPause.Enabled = <span style="color:Blue; True
btnStop.Enabled = <span style="color:Blue; False
btnPlay.Enabled = <span style="color:Blue; False
<span style="color:Green; btnPause.BackColor = PausedTrackColor
Player.controls.pause()
<span style="color:Blue; Case <span style="color:#A31515; "Stopped"
btnPause.Enabled = <span style="color:Blue; False
btnStop.Enabled = <span style="color:Blue; False
<span style="color:Blue; End <span style="color:Blue; Select
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub ScrollingVolume(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
<span style="color:Green; Change the players volume
Player.settings.volume = Volume.Value
lblVolume.Text = Volume.Value
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub Player_MediaError(<span style="color:Blue; ByVal pMediaObject <span style="color:Blue; As <span style="color:Blue; Object) <span style="color:Blue; Handles Player.MediaError
MessageBox.Show(<span style="color:#A31515; "Unrecoverable Problem. Shutting Down", <span style="color:#A31515; "MyMusic Player")
<span style="color:Blue; Me.Close()
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub Player_PlayStateChange(<span style="color:Blue; ByVal NewState <span style="color:Blue; As <span style="color:Blue; Integer) <span style="color:Blue; Handles Player.PlayStateChange
<span style="color:Blue; Static <span style="color:Blue; Dim PlayAllowed <span style="color:Blue; As <span style="color:Blue; Boolean = <span style="color:Blue; True
<span style="color:Blue; If Player <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
<span style="color:Blue; Try
<span style="color:Green; Ok will REM out the offending Select Case structure and use IF statements instead

<span style="color:Green; Select Case CType(NewState, WMPLib.WMPPlayState) A casting error here?
<span style="color:Green; Newstate is an integer and WMPPlayState is an enum as integer and a type? Im confused here
<span style="color:Green; Case WMPLib.WMPPlayState.wmppsReady
<span style="color:Green; If PlayAllowed Then
<span style="color:Green; If Player IsNot Nothing Then
<span style="color:Green; Player.controls.play()
<span style="color:Green; End If
<span style="color:Green; End If
<span style="color:Green; Case WMPLib.WMPPlayState.wmppsMediaEnded
<span style="color:Green; If Player IsNot Nothing Then
<span style="color:Green; Reach end of track move onto next, looping around
<span style="color:Green; PreviouslyPlaying = CurrentPlaying
<span style="color:Green; CurrentPlaying = (CurrentPlaying + 1) Mod files.Count
<span style="color:Green; Start protection (without it next wouldnt play
<span style="color:Green; PlayAllowed = False
<span style="color:Green; Play track
<span style="color:Green; Player.URL = files(CurrentPlaying)
<span style="color:Green; Player.controls.play()
<span style="color:Green; End Protection
<span style="color:Green; PlayAllowed = True
<span style="color:Green; updatePlayer()
<span style="color:Green; Timer1.Enabled = True
<span style="color:Green; End If
<span style="color:Green; End Select
<span style="color:Blue; If NewState = <span style="color:Blue; CInt(WMPLib.WMPPlayState.wmppsReady) <span style="color:Blue; Then
<span style="color:Blue; If PlayAllowed <span style="color:Blue; Then
<span style="color:Blue; If Player <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
Player.controls.play()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; If NewState = <span style="color:Blue; CInt(WMPLib.WMPPlayState.wmppsMediaEnded) <span style="color:Blue; Then
<span style="color:Blue; If Player <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
<span style="color:Green; Reach end of track move onto next, looping around
PreviouslyPlaying = CurrentPlaying
CurrentPlaying = (CurrentPlaying + 1) <span style="color:Blue; Mod files.<span style="color:Blue; Count
<span style="color:Green; Start protection (without it next wouldnt play
PlayAllowed = <span style="color:Blue; False
<span style="color:Green; Play track
Player.URL = files(CurrentPlaying)
Player.controls.play()
<span style="color:Green; End Protection
PlayAllowed = <span style="color:Blue; True
updatePlayer()
Timer1.Enabled = <span style="color:Blue; True
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Green; Not as neat as Select case but should avoid that nasty Casting error!!!
<span style="color:Green; Hmmm reduced the errors a bit I think - but still getting a damn
<span style="color:Green; System.Runtime.InteropServices.COMException - damn it. Im slowly getting
<span style="color:Green; there but still no cigar as yet - still waiting for the fat lady to sing!
<span style="color:Green; Full error message (in my lblSYsMessage.Text on a double-click on the tracklist listview) is:
<span style="color:Green; Serious error in Player_PlayStateChange: Exception from HRESULT: 0xC00D105
<span style="color:Green; But a search on the Net or on Microsofts/MSDNs sites dont give much details concerning this error
<span style="color:Green; - or what to do about it!! Im very perplexed now!!!
<span style="color:Green; Playing around a bit and trying a Cint on WMPLib.WMPPlayState states still results in bad casting
<span style="color:Green; (its annoying issues like this that makes working in VB.Net such a pain in the a**.
<span style="color:Green; The errors dont actually stop the player working in debug development mode - but, good as
<span style="color:Green; [most] of this code is - I couldnt release it with those errors in.

<span style="color:Green; Taking a leaf from MSs book at http://msdn.microsoft.com/en-us/library/dd562692(v=vs.85).aspx
<span style="color:Green; MS does the following:
<span style="color:Green;
<span style="color:Green; Private Sub Player_PlayStateChange(ByVal NewState As Integer) _
<span style="color:Green; Handles Player.PlayStateChange
<span style="color:Green; If NewState = WMPLib.WMPPlayState.wmppsStopped Then
<span style="color:Green; Me.Close()
<span style="color:Green; End If
<span style="color:Green;
<span style="color:Green; So why on Earth are exceptions being raised - assuming M$ code it right????
<span style="color:Green; God I hate MS and Vb.Net at times - its almost ALWAYS such an uphill struggle.
<span style="color:Green; God only knows how newbies cope.
<span style="color:Green; Whats M$ vb.Net slogan? Imagine it, do it - yeah right!!! Hey M$, imagine a simple
<span style="color:Green; programming framework that is easy to use, [very neary] bug-free and which works -
<span style="color:Green; still waiting on M$ to do it after 30+ years. I bet this is what M$ calls being
<span style="color:Green; type-safe! The rest of the program preforms well and as expected, tg :)
<span style="color:Green;
<span style="color:Blue; Catch ex <span style="color:Blue; As InvalidCastException
lblSysMessage.Text = <span style="color:#A31515; "Yep invalidcast error in Player_PlayStateChange: " & ex.Message
<span style="color:Blue; Catch ex <span style="color:Blue; As System.Runtime.InteropServices.COMException
lblSysMessage.Text = <span style="color:#A31515; "Serious error in Player_PlayStateChange: " & ex.Message
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
lblSysMessage.Text = <span style="color:#A31515; "Some other error in Player_PlayStateChange: " & ex.Message
<span style="color:Blue; Finally
<span style="color:Green; Just carry on regardless - if possible. Dunno what else to do - except maybe exit
<span style="color:Green; unnecessarily. Maybe the forums can help out?
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub


<span style="color:Blue; Private <span style="color:Blue; Sub updatePlayer()
<span style="color:Blue; Try
<span style="color:Green; Display track name
<span style="color:Blue; If Player.currentMedia.name <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
Txt_TrackName.Text = Player.currentMedia.name
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Green; Update TrackPostion
<span style="color:Blue; With prgTrack
<span style="color:Blue; If Player <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
.Minimum = 0
.Maximum = <span style="color:Blue; CInt(Player.currentMedia.duration)
.Value = <span style="color:Blue; CInt(Player.controls.currentPosition())
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; With
<span style="color:Blue; With TrackPosition
<span style="color:Blue; If Player <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
.TickFrequency = 10
.Minimum = 0
.Maximum = <span style="color:Blue; CInt(Player.currentMedia.duration)
.Value = <span style="color:Blue; CInt(Player.controls.currentPosition())
lblTrackPos.Text = .Value
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; With

<span style="color:Blue; If Player <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
<span style="color:Green; Display Current Time Position and Duration
Txt_Progress.Text = Player.controls.currentPositionString & vbTab & Player.currentMedia.durationString
<span style="color:Green; Set Volume slide to match current volume
Volume.Value = Player.settings.volume
lblVolume.Text = Volume.Value
<span style="color:Green; Is the CurrentPlaying Track No. is different to the Previous Track number.
<span style="color:Blue; If CurrentPlaying <> PreviouslyPlaying <span style="color:Blue; Then
<span style="color:Green; Yes,
<span style="color:Green; Set the forecolor of the corresponding track, associated with the previous playing track, with the control color
TrackList.Items(PreviouslyPlaying).ForeColor = System.Drawing.SystemColors.ControlText
Player.controls.<span style="color:Blue; stop()
<span style="color:Green; Player.currentMedia = TrackList.Items(CurrentPlaying)
<span style="color:Green; Player.URL = TrackList.Items(CurrentPlaying).Text
TrackList.Items(CurrentPlaying).Selected = <span style="color:Blue; True
TrackList.EnsureVisible(CurrentPlaying) <span style="color:Green; Peform an autoscroll if needed
Player.URL = files(CurrentPlaying)
Player.controls.play()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Green; Set the forecolor of the corresponding track, associated with the currently playing track, with the current track color
TrackList.Items(CurrentPlaying).ForeColor = CurrentTrackColor
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Catch ex <span style="color:Blue; As InvalidCastException
lblSysMessage.Text = <span style="color:#A31515; "Yep invalidcast error in updatePlayer: " & ex.Message
<span style="color:Blue; Catch ex <span style="color:Blue; As System.Runtime.InteropServices.COMException
lblSysMessage.Text = <span style="color:#A31515; "Serious error in updatePlayer: " & ex.Message
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
lblSysMessage.Text = <span style="color:#A31515; "Some other error in updatePlayer: " & ex.Message
<span style="color:Blue; Finally
<span style="color:Green; Just carry on regardless
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub Track_MouseDoubleClick(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.MouseEventArgs)
<span style="color:Blue; Try
GUIMode(<span style="color:#A31515; "Play")
<span style="color:Green; A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
<span style="color:Green; Set CurrentPlaying to position of selected track.
CurrentPlaying = TrackList.SelectedIndices(0)
<span style="color:Green; Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
lblSysMessage.Text = <span style="color:#A31515; "Error in Track_MouseDoubleClick: " & ex.Message
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub ScrollingTrackPosition(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
<span style="color:Blue; Try
<span style="color:Green; Seek through the track
Player.controls.pause()
Player.controls.currentPosition = TrackPosition.Value
lblTrackPos.Text = TrackPosition.Value
Player.controls.play()
updatePlayer()
<span style="color:Green; Allow the app to do some processing
Application.DoEvents()
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
lblSysMessage.Text = <span style="color:#A31515; "Error in ScrollingTrackPosition: " & ex.Message
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub UpdatePlayerTimer(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
updatePlayer()
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub Timer1_Tick(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Timer1.Tick
<span style="color:Blue; Try
<span style="color:Blue; If Player <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
Txt_Progress.Text = Player.controls.currentPositionString & vbTab & Player.currentMedia.durationString
<span style="color:Blue; With prgTrack
.Minimum = 0
.Maximum = <span style="color:Blue; CInt(Player.currentMedia.duration)
.Value = <span style="color:Blue; CInt(Player.controls.currentPosition())
<span style="color:Blue; End <span style="color:Blue; With
<span style="color:Blue; With TrackPosition
.TickFrequency = 10
.Minimum = 0
.Maximum = <span style="color:Blue; CInt(Player.currentMedia.duration)
.Value = <span style="color:Blue; CInt(Player.controls.currentPosition())
lblTrackPos.Text = .Value
<span style="color:Blue; End <span style="color:Blue; With
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
Timer1.Enabled = <span style="color:Blue; False
lblSysMessage.Text = <span style="color:#A31515; "Error in Timer1_Tick: " & ex.Message
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub btnPlay_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnPlay.Click
Player.controls.play()
btnStop.Enabled = <span style="color:Blue; True
btnPause.Enabled = <span style="color:Blue; True
btnPlay.Enabled = <span style="color:Blue; False
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub btnStop_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnStop.Click
Player.controls.<span style="color:Blue; stop()
btnStop.Enabled = <span style="color:Blue; False
btnPause.Enabled = <span style="color:Blue; False
btnPlay.Enabled = <span style="color:Blue; True
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub btnPause_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnPause.Click
Player.controls.pause()
btnPause.Enabled = <span style="color:Blue; False
btnPlay.Enabled = <span style="color:Blue; True
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub Volume_Scroll(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Volume.Scroll
<span style="color:Green; Change the players volume
Player.settings.volume = Volume.Value
lblVolume.Text = Volume.Value
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub TrackList_DoubleClick(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TrackList.DoubleClick
GUIMode(<span style="color:#A31515; "Play")
<span style="color:Green; A track in the tracks listing has been double clicked on
PreviouslyPlaying = CurrentPlaying
<span style="color:Green; Set CurrentPlaying to position of selected track.
CurrentPlaying = TrackList.SelectedIndices(0)
<span style="color:Blue; Try
<span style="color:Green; Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()
TrackList.Items(CurrentPlaying).ForeColor = CurrentTrackColor
btnPlay.Enabled = <span style="color:Blue; False
btnPause.Enabled = <span style="color:Blue; True
btnStop.Enabled = <span style="color:Blue; True
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
lblSysMessage.Text = <span style="color:#A31515; "Error in tracklist double-click: " & ex.Message
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub btnExit_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles btnExit.Click
frmKAOS.Show()
<span style="color:Blue; Me.Close()
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub TrackList_MouseUp(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.Windows.Forms.MouseEventArgs) <span style="color:Blue; Handles TrackList.MouseUp
<span style="color:Green; Dont need to use this event to tell whats under the mouse on a right-click
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub TrackList_SelectedIndexChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TrackList.SelectedIndexChanged
<span style="color:Green; Dont need to use this event
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub ShowMP3InfoToolStripMenuItem_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles ShowMP3InfoToolStripMenuItem.Click
<span style="color:Blue; Dim MP3List <span style="color:Blue; As ListView.SelectedListViewItemCollection = <span style="color:Blue; Me.TrackList.SelectedItems
<span style="color:Blue; Dim item <span style="color:Blue; As ListViewItem, reply <span style="color:Blue; As <span style="color:Blue; Integer
reply = MsgBox(<span style="color:#A31515; "Note: You cannot EDIT the mp3 tags while the file is in use, though you can view the tags (which includes when running the show MP3 info dialogue box from here - as you are currently doing)! So, if you want to actually EDIT any MP3 tags, choose the edit MP3 tags menu item from the KAOS main form and then when in the tag editor select/open the file (in the tag editor) whose tags you want to edit (do all of this after first closing this 5.1 channel media player of course).", vbYesNoCancel <span style="color:Blue; Or vbInformation, <span style="color:#A31515; "KAOS 5.1 MP3 Player")
lblSysMessage.Text = <span style="color:#A31515; "Note: You cannot EDIT the mp3 tags while the file is in use, though you can view the tags (which includes when running the show MP3 info dialogue box from here - as you are currently doing)! So, if you want to actually EDIT any MP3 tags, choose the edit MP3 tags menu item from the KAOS main form and then when in the tag editor select/open the file (in the tag editor) whose tags you want to edit (do all of this after first closing this 5.1 channel media player of course)."
<span style="color:Blue; If reply = vbYes <span style="color:Blue; Then
<span style="color:Blue; For <span style="color:Blue; Each item <span style="color:Blue; In MP3List
frmMP3Dialogue.lblMP3name.Text = item.Text
frmMP3Dialogue.lblMP3Path.Text = files(item.Index)
frmMP3Dialogue.Tag = <span style="color:#A31515; "NoEdit"
frmMP3Dialogue.Show()
<span style="color:Blue; Next
<span style="color:Blue; Else
lblSysMessage.Text = <span style="color:#A31515; ""
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Private <span style="color:Blue; Sub TrackPosition_Scroll(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TrackPosition.Scroll
<span style="color:Blue; Try
<span style="color:Green; Seek through the track
Player.controls.pause()
Player.controls.currentPosition = TrackPosition.Value
lblTrackPos.Text = TrackPosition.Value
Player.controls.play()
updatePlayer()
<span style="color:Green; Allow the app to do some processing
Application.DoEvents()
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
lblSysMessage.Text = <span style="color:#A31515; "Error in TrackPosition_Scroll: " & ex.Message
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class

[/code]
<hr class="sig Big Al

View the full article
 
Back
Top