📄 frmmain.vb
字号:
Imports System
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.IO
'Simple MP3 player for Pocket PC
'-------------------------------
'using FMOD Sound System http://www.fmod.org by Brett and the Team, FireLight Technologies
'tricks I used :
'* I did not manage to create a good callback wrapper, so I use a timer set on high rate to check if we have reached the end of a track
'* To pause a track, I first record the actual position and close the stream, as if I stopped playing. To unpause, start playing the same track, starting at recorded position
'* To get a handle on the mp3 file, I used a trick found on fmod's forum, which I implemented in C#: fmod_getStream
'Julien - codeProject - 09/2005
'Contributors : mattias73, lonifasiko
'Credits : MSDN CF faq, FMOD's forums
'Updates
'26.10.2005 - Got rid of external C# fmod wrapper, and implemented it inside main module
'14.11.2005 - AddrOfPinnedObject bug fix for .NET CF 1.0
Public Class frmMain
Inherits System.Windows.Forms.Form
Friend WithEvents lblIntroText As System.Windows.Forms.Label
Friend WithEvents btnBrowse As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtSoundTrack As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents timSound As System.Windows.Forms.Timer
Friend WithEvents ofdSound As System.Windows.Forms.OpenFileDialog
Friend WithEvents btnPause As System.Windows.Forms.Button
Friend WithEvents btnStop As System.Windows.Forms.Button
Friend WithEvents btnPlay As System.Windows.Forms.Button
Friend WithEvents trackBar As System.Windows.Forms.ProgressBar
Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmMain))
Me.timSound = New System.Windows.Forms.Timer
Me.ofdSound = New System.Windows.Forms.OpenFileDialog
Me.lblIntroText = New System.Windows.Forms.Label
Me.btnBrowse = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.txtSoundTrack = New System.Windows.Forms.TextBox
Me.btnPlay = New System.Windows.Forms.Button
Me.btnPause = New System.Windows.Forms.Button
Me.btnStop = New System.Windows.Forms.Button
Me.Label3 = New System.Windows.Forms.Label
Me.trackBar = New System.Windows.Forms.ProgressBar
'
'timSound
'
Me.timSound.Interval = 500
'
'ofdSound
'
Me.ofdSound.Filter = "MP3 files|*.mp3"
'
'lblIntroText
'
Me.lblIntroText.Location = New System.Drawing.Point(8, 16)
Me.lblIntroText.Size = New System.Drawing.Size(224, 32)
Me.lblIntroText.Text = "Browse to select an mp3 file and click play to listen to it."
'
'btnBrowse
'
Me.btnBrowse.Location = New System.Drawing.Point(8, 56)
Me.btnBrowse.Size = New System.Drawing.Size(224, 24)
Me.btnBrowse.Text = "Browse"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 88)
Me.Label1.Size = New System.Drawing.Size(216, 16)
Me.Label1.Text = "Selected sound track :"
'
'txtSoundTrack
'
Me.txtSoundTrack.Location = New System.Drawing.Point(8, 112)
Me.txtSoundTrack.ReadOnly = True
Me.txtSoundTrack.Size = New System.Drawing.Size(224, 21)
Me.txtSoundTrack.Text = "no file selected"
'
'btnPlay
'
Me.btnPlay.Location = New System.Drawing.Point(8, 224)
Me.btnPlay.Size = New System.Drawing.Size(64, 32)
Me.btnPlay.Text = "Play"
'
'btnPause
'
Me.btnPause.Location = New System.Drawing.Point(88, 224)
Me.btnPause.Size = New System.Drawing.Size(64, 32)
Me.btnPause.Text = "Pause"
'
'btnStop
'
Me.btnStop.Location = New System.Drawing.Point(168, 224)
Me.btnStop.Size = New System.Drawing.Size(64, 32)
Me.btnStop.Text = "Stop"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(7, 170)
Me.Label3.Size = New System.Drawing.Size(96, 16)
Me.Label3.Text = "Elapsed time :"
'
'trackBar
'
Me.trackBar.Location = New System.Drawing.Point(8, 192)
Me.trackBar.Size = New System.Drawing.Size(224, 21)
'
'frmMain
'
Me.Controls.Add(Me.trackBar)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.btnStop)
Me.Controls.Add(Me.btnPause)
Me.Controls.Add(Me.btnPlay)
Me.Controls.Add(Me.txtSoundTrack)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnBrowse)
Me.Controls.Add(Me.lblIntroText)
Me.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Text = "MP3 Player"
End Sub
#End Region
'currentSoundTrack - the file name of the currently selected file
Private currentSoundTrack As String = String.Empty
'isOnPause - Boolean which shows if track is paused or not
Private isOnPause As Boolean = False
'currentPosition - used to store current position in the track
Private currentPosition As Integer = 0
'soundHandle - handle to the sound track
Private soundHandle As IntPtr = IntPtr.Zero
'currentSoundLength - the length of the current track
Private currentSoundLength As Integer = 0
'uPausePosition - the current position as uint
Private uPausePosition As UInt32
'frmMain_Load - start point of the application
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'set the selected file text box to "no file selected"
txtSoundTrack.Text = "no file selected"
'disable play/pause/stop button, as their is no file selected
btnPlay.Enabled = False
btnPause.Enabled = False
btnStop.Enabled = False
'set the progress bar value to 0
trackBar.Value = 0
End Sub
'setEnabled - sub which enables the play button
'used when no sound is playing but a file is selected
Private Sub setEnabled()
btnPlay.Enabled = True
btnPause.Enabled = False
btnStop.Enabled = False
trackBar.Value = 0
End Sub
'btnBrowse_Click - fired when user browses for a MP3 file
'note that the openFileDialog as a *.mp3 filter
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
If ofdSound.ShowDialog = DialogResult.OK Then
'if the user has selected a file then check if the file really exists
If File.Exists(ofdSound.FileName) Then
'file exists so enable play button
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -