📄 mainform.vb
字号:
Me.TopMost = False
End If
' Reset image so it's correct when form is shown again.
picMinimize.Image = My.Resources.Minimize_Mouse_Up
End Sub
Private Sub picMinimize_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picMinimize.MouseEnter
picMinimize.Image = My.Resources.Minimize_Mouse_Hover
End Sub
Private Sub picMinimize_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picMinimize.MouseLeave
picMinimize.Image = My.Resources.Minimize_Mouse_Up
End Sub
Private Sub picMinimize_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picMinimize.MouseUp
picMinimize.Image = My.Resources.Minimize_Mouse_Up
End Sub
#End Region
#Region " Notify Context Icon Menu Events "
Private Sub mnuNiRestore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiRestore.Click
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
Me.Opacity = 1
NotifyIcon1.Visible = False
NotifyIcon1.ContextMenuStrip = Nothing
' If topmost is set, enable it now because form is shown.
If Settings.KeepOnTop = True Then
Me.TopMost = True
End If
End Sub
Private Sub mnuNiMute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiMute.Click
Mute()
End Sub
Private Sub mnuNiPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiPlay.Click
Play()
End Sub
Private Sub mnuNiVolume_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiVolume.Click
If VolumeForm.Visible = False Then
VolumeForm.ShowDialog()
End If
End Sub
Private Sub mnuNiShowVisualizationsFullScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiShowVisualizationsFullScreen.Click
' Display visualization full screen.
If Player.playState = WMPPlayState.wmppsPlaying Then
If Player.Visible = True Then
Player.fullScreen = True
End If
End If
End Sub
Private Sub mnuNiDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiDisconnect.Click
Disconnect()
ClearRadioButtons(Me)
End Sub
Private Sub mnuNiAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiAbout.Click
' StartPosition is set to CenterParent when displaying AboutDialog from MainForm.
AboutDialog.StartPosition = FormStartPosition.Manual
AboutDialog.ShowDialog()
End Sub
Private Sub mnuNiExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNiExit.Click
AppExit()
End Sub
#End Region
#Region " Notify Icon Events "
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
Me.Opacity = 1
NotifyIcon1.Visible = False
NotifyIcon1.ContextMenuStrip = Nothing
' If topmost is set, enable it now because form is shown.
If Settings.KeepOnTop = True Then
Me.TopMost = True
End If
End Sub
#End Region
#Region " PictureBox Events "
Private Sub picStation_LoadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles picStation.LoadCompleted
If picStation.Image.Width < 50 Then
If Settings.DisplayCoverArt = True Then
' Disable rotation timer.
tmrRotatePictureText.Enabled = False
ElseIf Settings.DisplayVisualizations = True Then
' Enable rotation timer.
tmrRotatePictureText.Enabled = True
End If
ElseIf Settings.DisplayCoverArt = True Or Settings.DisplayVisualizations = True Then
' Enable rotation timer.
tmrRotatePictureText.Enabled = True
Else
' Do not rotate. Display station info only.
tmrRotatePictureText.Enabled = False
End If
End Sub
#End Region
#Region " Player Control Methods "
''' <summary>
''' Start streaming and play selected station.
''' </summary>
''' <param name="name">Station Name</param>
''' <param name="location">Location</param>
''' <param name="format">Format</param>
''' <param name="website">Website</param>
''' <param name="uri">Stream Uri</param>
Private Sub PlayStation(ByVal name As String, ByVal location As String, ByVal format As String, _
ByVal website As String, ByVal uri As String)
Dim msg As String
' Validate uri and exit if it is empty.
If uri = "" Then
Exit Sub
End If
' Disconnect from current media.
'Disconnect() ' todo - debug
Try
' Set selected values.
mSelectedName = name
mSelectedLocation = location
mSelectedFormat = format
mSelectedWebsite = website
mSelectedUri = uri
' Display form information.
lblStation.Text = name
lblLocation.Text = location
llbWebsite.Text = website
' Set timer interval. (Will be changed when timer event fires.)
tmrRotatePictureText.Interval = 5000
' Slogan will be filled in by timer event, so clear it because a previous station may have been played.
lblSlogan.Text = ""
' Set message for notifyicon text and balloon tip.
If mSelectedName.ToLower <> "url" Then
msg = mSelectedName & vbCrLf & mSelectedLocation & vbCrLf & "格式: " & mSelectedFormat
Else
msg = "手动选择"
End If
' Set notifyicon balloon tip.
NotifyIcon1.BalloonTipTitle = My.Application.Info.Title
NotifyIcon1.BalloonTipText = msg
' Set notifyicon text - which must be 63 characters or less.
If msg.Length > 63 Then
NotifyIcon1.Text = msg.Substring(0, 63)
Else
NotifyIcon1.Text = msg
End If
' Show notifyicon ballon tip if icon is visible.
If NotifyIcon1.Visible = True Then
NotifyIcon1.ShowBalloonTip(2000)
End If
Catch exc As ArgumentOutOfRangeException
'If error occurs, cancel topmost.
If Me.TopMost = True Then Me.TopMost = False
MessageBox.Show("PlayStation: ArgumentOutOfRangeException. The system returned the following information:" & vbCrLf & _
exc.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
' Reset mute.
ResetMute()
' Start streaming.
Try
Player.enableContextMenu = False ' Disable media player built-in context menu as it interfers with ours.
Player.URL = uri ' Load uri.
Player.Ctlcontrols.play() ' Attempt to start streaming.
Application.DoEvents() ' todo - debug.
Catch comExc As COMException
Dim hr As Integer = comExc.ErrorCode
Dim Message As String = "HRESULT = " & hr.ToString() & vbCrLf & comExc.Message
' If error occurs, cancel topmost.
If Me.TopMost = True Then Me.TopMost = False
MessageBox.Show("PlayStation: COM Exception:" & vbCrLf & Message, My.Application.Info.Title, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
''' <summary>
''' Stop player if it is playing, close the media, and disable info and rotation timers.
''' </summary>
Private Sub Disconnect()
Try
If mPlayerLoaded = True Then
Player.Ctlcontrols.stop()
Player.URL = ""
Player.close()
' Stop rotating text and image. Set text visible. Image Invisible.
tmrRotatePictureText.Enabled = False
picStation.Visible = False
pnlStationInfo.Visible = True
pnlStationInfo.BackgroundImage = My.Resources.StreamRadio
tmrInfo.Enabled = False
ClearStructures()
' Hide media player.
Player.Visible = False
' Clear picture box.
picStation.Image = Nothing
picStation.ImageLocation = ""
picStation.BackColor = Color.White
' Clear form information.
lblStation.Text = ""
lblLocation.Text = ""
lblSlogan.Text = ""
llbWebsite.Text = ""
' Clear StatusStrip info.
prgStatusStrip.Visible = False
lblBuffering.Text = ""
lblCurrentPosition.Text = ""
lblStatus.Text = ""
' Clear balloon tip.
NotifyIcon1.BalloonTipText = "No station is selected."
' Clear radiobuttons.
ClearRadioButtons(Me)
' Reset mute.
ResetMute()
End If
Catch comExc As COMException
Dim hr As Integer = comExc.ErrorCode
Dim Message As String = "HRESULT = " & hr.ToString() & vbCrLf & comExc.Message
' If error occurs, cancel topmost.
If Me.TopMost = True Then Me.TopMost = False
MessageBox.Show("Disconnect: COM Exception:" & vbCrLf & Message, My.Application.Info.Title, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
''' <summary>
''' Reset mute. Used when playing a new stream in case mute is on
''' to sync buttons and menus. Starting a new stream will always
''' unmute the player.
''' </summary>
Private Sub ResetMute()
If Player IsNot Nothing Then
Player.settings.mute = False
mnuNiMute.Text = "Mute"
mnuNiMute.Image = My.Resources.Mute
btnMute.Image = My.Resources.Mute
ToolTip2.SetToolTip(btnMute, "Click to Mute")
VolumeForm.btnMute.Image = My.Resources.Mute
VolumeForm.ToolTip1.SetToolTip(VolumeForm.btnMute, "Click to Mute")
' Change notification icon.
NotifyIcon1.Icon = My.Resources._Default
End If
End Sub
''' <summary>
''' Toggle mute and unmute sound and set appropriate labels and images.
''' </summary>
''' <remarks>
''' Method is Public so it is visible from VolumeForm.
''' </remarks>
Friend Sub Mute()
Try
If Player IsNot Nothing Then
If Player.settings.mute = False Then
Player.settings.mute = True
mnuNiMute.Text = "Muted"
mnuNiMute.Image = My.Resources.Muted
btnMute.Image = My.Resources.Muted
ToolTip2.SetToolTip(btnMute, "Click to Listen")
VolumeForm.btnMute.Image = My.Resources.Muted
VolumeForm.ToolTip1.SetToolTip(VolumeForm.btnMute, "Click to Listen")
' Change notification icon.
NotifyIcon1.Icon = My.Resources.DefaultMuted
Else
Player.settings.mute = False
mnuNiMute.Text = "Mute"
mnuNiMute.Image = My.Resources.Mute
btnMute.Image = My.Resources.Mute
ToolTip2.SetToolTip(btnMute, "Click to Mute")
VolumeForm.btnMute.Image = My.Resources.Mute
VolumeForm.ToolTip1.SetToolTip(VolumeForm.btnMute, "Click to Mute")
' Change notification icon.
NotifyIcon1.Icon = My.Resources._Default
End If
End If
Catch comExc As COMException
Dim hr As Integer = comExc.ErrorCode
Dim Message As String = "HRESULT = " & hr.ToString() & vbCrLf & comExc.Message
' If error occurs, cancel topm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -