123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
-
- Imports System.IO
- Imports System.Text
- Public Class Main
- Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
- Dim screenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
- Private IsFormBeingDragged As Boolean = False
- Private MouseDownX As Integer
- Private MouseDownY As Integer
- Dim Player As New PlayerControl
- Dim fm As New FileManagement
- Dim basedir As String = My.Settings.Basedir
- Dim Arozpath As String = ""
- 'Basic Form Movement handler
- Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel1.MouseDown
- If e.Button = MouseButtons.Left Then
- IsFormBeingDragged = True
- MouseDownX = e.X
- MouseDownY = e.Y
- End If
- End Sub
- Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel1.MouseUp
- If e.Button = MouseButtons.Left Then
- IsFormBeingDragged = False
- End If
- End Sub
- Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel1.MouseMove
- If IsFormBeingDragged Then
- Dim temp As Point = New Point()
- temp.X = Me.Location.X + (e.X - MouseDownX)
- temp.Y = Me.Location.Y + (e.Y - MouseDownY)
- Me.Location = temp
- temp = Nothing
- End If
- End Sub
- ' Controlling Events handling clicks and buttons
- Private Sub Panel1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.DoubleClick
- My.Settings.Basedir = basedir
- My.Settings.Enrichedbg = CheckBox2.Checked
- My.Settings.bg = CheckBox1.Checked
- My.Settings.Save()
- Me.Close()
- End Sub
- Private Sub Panel1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseClick
- If e.Button = MouseButtons.Right Then
- MsgBox("Clicked")
- End If
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
- If Label1.Text = "Now Playing" Then
- GoTo endhere
- End If
- PictureBox2.Cursor = Cursors.Arrow
- Label1.Text = "Now Playing"
- Player.SetVol(0)
- Player.Play()
- For x As Integer = 0 To My.Settings.Vol Step 1
- Player.SetVol(x)
- Threading.Thread.Sleep(18)
- Next
- endhere:
- Threading.Thread.Sleep(120)
- PictureBox2.Cursor = Cursors.Hand
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
- PictureBox3.Cursor = Cursors.Arrow
- For x As Integer = Player.GetVol To 0 Step -1
- Player.SetVol(x)
- Threading.Thread.Sleep(20)
- Next
- Player.Pause()
- Player.SetVol(My.Settings.Vol)
- Threading.Thread.Sleep(120)
- PictureBox3.Cursor = Cursors.Hand
- Label1.Text = "Paused"
- End Sub
- Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'Player.LoadSong("e:\Music\「アヤノの幸福理論 Piano Ver. 」歌ってみた【εїз】.mp3")
- If My.Computer.FileSystem.FileExists(basedir & My.Settings.LastPlay) Then
- Player.LoadSong(basedir & My.Settings.LastPlay)
- Label2.Text = Player.GetSongName
- Else
- Label2.Text = "Please select a song to play"
- End If
- CheckBox1.Checked = My.Settings.bg
- CheckBox2.Checked = My.Settings.Enrichedbg
- Player.initiateVol()
- fm.InitiateFolderSystem()
- Player.initiateLoopSetting()
- ListBaseDir()
- If CheckBox1.Checked = True Then
- Background.Show()
- End If
- If CheckArOZOnline() = True Then
- Label7.Text = "ArOZ Linked"
- Label7.ForeColor = Color.Red
- 'MsgBox(Arozpath)
- TellArOZMusicPlaying()
- Else
- Label7.Text = "Stand alone"
- Label7.ForeColor = Color.Black
- End If
- End Sub
- Private Sub ClosingChat() Handles Me.Closing
- If Arozpath <> "" Then
- Dim ArOZdir = Path.GetDirectoryName(Arozpath)
- Dim apidir As String = ArOZdir & "\plugins\API\"
- If ReadAPI("api.aro", apidir, "balloon.rx") = "" Then
- WriteAPI("api.aro", apidir, "balloon.rx", "AM Player 被你關掉了…")
- End If
- End If
- End Sub
- Public Sub TellArOZMusicPlaying()
- Dim ArOZdir = Path.GetDirectoryName(Arozpath)
- Dim apidir As String = ArOZdir & "\plugins\API\"
- 'MsgBox(apifile)
- If ReadAPI("api.aro", apidir, "balloon.rx") = "" Then
- WriteAPI("api.aro", apidir, "balloon.rx", "AM Player 已開啟~")
- End If
- End Sub
- Public Function CheckArOZOnline()
- Dim p() As Process
- p = Process.GetProcesses
- For Each proc As Process In p
- If proc.ProcessName.ToString.Contains("ArOZ") Then
- Arozpath = proc.MainModule.FileName
- GoTo ArOZfound
- End If
- Next
- Return False
- ArOZfound:
- Return True
- End Function
- Public Sub ListBaseDir(Optional ByVal loc As String = "")
- If loc = Nothing Then
- loc = basedir
- End If
- If My.Computer.FileSystem.DirectoryExists(loc) Then 'It is a folder, read all content
- ListBox1.Items.Clear()
- Dim x = fm.ListByDate(basedir)
- For Each y In x
- If y.ToString.Contains(".mp3") Or y.ToString.Contains(".mp4") Or y.ToString.Contains(".wav") Or y.ToString.Contains(".avi") Then
- ListBox1.Items.Add(y.ToString)
- Else
- End If
- Next
- Else 'It is a Playlist but not a folder, link all base dir
- End If
- End Sub
- Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
- PictureBox1.Cursor = Cursors.Arrow
- Player.SoundFadeOut()
- ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
- Player.LoadSong(basedir & ListBox1.SelectedItem)
- My.Settings.LastPlay = ListBox1.SelectedItem
- My.Settings.Save()
- Threading.Thread.Sleep(120)
- PictureBox1.Cursor = Cursors.Hand
- Player.SoundFadeIn()
- End Sub
- Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
- PictureBox5.Cursor = Cursors.Arrow
- Player.SoundFadeOut()
- ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
- Player.LoadSong(basedir & ListBox1.SelectedItem)
- My.Settings.LastPlay = ListBox1.SelectedItem
- My.Settings.Save()
- Threading.Thread.Sleep(120)
- PictureBox5.Cursor = Cursors.Hand
- Player.SoundFadeIn()
- End Sub
- Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
- PictureBox4.Cursor = Cursors.Arrow
- Player.StopPlaying()
- Threading.Thread.Sleep(120)
- PictureBox4.Cursor = Cursors.Hand
- Label1.Text = "Stopped"
- End Sub
- Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
- PictureBox7.Cursor = Cursors.Arrow
- Player.VolUp()
- Threading.Thread.Sleep(120)
- PictureBox7.Cursor = Cursors.Hand
- My.Settings.Vol = Player.GetVol
- My.Settings.Save()
- End Sub
- Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
- PictureBox6.Cursor = Cursors.Arrow
- Player.VolDown()
- Threading.Thread.Sleep(120)
- PictureBox6.Cursor = Cursors.Hand
- My.Settings.Vol = Player.GetVol
- My.Settings.Save()
- End Sub
- '////Other form controling Vol.
- Public Sub MainVolUP()
- On Error Resume Next
- PictureBox7.Cursor = Cursors.Arrow
- Player.VolUp()
- Threading.Thread.Sleep(80)
- PictureBox7.Cursor = Cursors.Hand
- My.Settings.Vol = Player.GetVol
- My.Settings.Save()
- End Sub
- Public Sub MainVolDown()
- On Error Resume Next
- PictureBox6.Cursor = Cursors.Arrow
- Player.VolDown()
- Threading.Thread.Sleep(80)
- PictureBox6.Cursor = Cursors.Hand
- My.Settings.Vol = Player.GetVol
- My.Settings.Save()
- End Sub
- Public Sub PictureBox10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox10.Click
- PictureBox10.Cursor = Cursors.Arrow
- If LoopCounter.Enabled Then
- LoopCounter.Enabled = False
- Label6.Text = "End Stop"
- My.Settings.LoopMode = "End Stop"
- My.Settings.Save()
- Else
- LoopCounter.Enabled = True
- PlayListCounter.Enabled = False
- Label6.Text = "Single Loop"
- My.Settings.LoopMode = "Single Loop"
- My.Settings.Save()
- End If
- Threading.Thread.Sleep(120)
- PictureBox10.Cursor = Cursors.Hand
- End Sub
- Public Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click
- PictureBox9.Cursor = Cursors.Arrow
- If PlayListCounter.Enabled Then
- PlayListCounter.Enabled = False
- Label6.Text = "End Stop"
- My.Settings.LoopMode = "End Stop"
- My.Settings.Save()
- Else
- PlayListCounter.Enabled = True
- LoopCounter.Enabled = False
- Label6.Text = "Playlist Loop"
- My.Settings.LoopMode = "Playlist Loop"
- My.Settings.Save()
- End If
- Threading.Thread.Sleep(120)
- PictureBox9.Cursor = Cursors.Hand
- End Sub
- Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
- PictureBox8.Cursor = Cursors.Arrow
- Dim fd As OpenFileDialog = New OpenFileDialog()
- Dim strFileName As String = ""
- fd.Title = "Play Song"
- fd.InitialDirectory = basedir
- fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
- fd.FilterIndex = 2
- fd.RestoreDirectory = True
- If fd.ShowDialog() = DialogResult.OK Then
- strFileName = fd.FileName
- Else
- GoTo Endhere
- End If
- Try
- Player.LoadSong(strFileName)
- Label1.Text = "Now Playing"
- Catch ex As Exception
- Label1.Text = "File Not Found"
- End Try
- ListBox1.Items.Clear()
- basedir = strFileName.Substring(0, strFileName.LastIndexOf("\") + 1)
- ListBox1.Items.Add(strFileName.Replace(basedir, ""))
- Endhere:
- Threading.Thread.Sleep(120)
- PictureBox8.Cursor = Cursors.Hand
- ReloadList()
- End Sub
- 'Update Tiem elft and percentage
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- On Error Resume Next
- Dim a As Double = Player.GetCurrentPos / 60
- Dim b As Integer = Math.Round(a)
- If b > a Then
- b = b - 1
- a = (a - b) * 60
- Else
- a = (a - b) * 60
- End If
- Dim n As String
- If Math.Round(a) < 10 Then
- n = "0" & Math.Round(a)
- Else
- n = Math.Round(a)
- End If
- Label3.Text = b & " : " & n
- Dim x As Double = Player.GetTotalDuration / 60
- Dim y As Integer = Math.Round(x)
- Dim m As String
- If y > x Then
- y = y - 1
- x = (x - y) * 60
- Else
- x = (x - y) * 60
- End If
- If Math.Round(x) < 10 Then
- m = "0" & Math.Round(x)
- Else
- m = Math.Round(x)
- End If
- Label4.Text = y & " : " & m
- ProgressBar1.Value = Player.GetCurrentPos / Player.GetTotalDuration * 100
- Label2.Text = Player.GetSongName
- End Sub
- '//Soring and browsing
- 'Creat File System
- Private Sub LoopCounter_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoopCounter.Tick
- If Player.GetCurrentPos >= Player.GetTotalDuration - 0.2 Then
- Player.StopPlaying()
- Player.Play()
- End If
- End Sub
- '//Looping the playlist
- Private Sub PlayListCounter_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayListCounter.Tick
- If Player.GetCurrentPos < 0.5 Then
- Dim itemid As Integer = 0
- Dim nowplaying As String = My.Settings.LastPlay
- For Each item In ListBox1.Items
- If item.ToString.Contains(nowplaying) Then
- ListBox1.SelectedItem = item
- Exit For
- End If
- Next
- End If
- If Player.GetCurrentPos >= Player.GetTotalDuration - 0.2 Then
- If Player.GetTotalDuration = 0 Or Player.GetCurrentPos = 0 Then
- GoTo endhere
- End If
- PlayListCounter.Enabled = False
- Dim itemid As Integer = 0
- Dim nowplaying As String = Player.GetSongName
- For Each item In ListBox1.Items
- If item.ToString.Contains(nowplaying) Then
- ListBox1.SelectedItem = item
- Exit For
- End If
- Next
- ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
- If ListBox1.SelectedItem.ToString.Contains(My.Settings.LastPlay.Substring(0, My.Settings.LastPlay.LastIndexOf("."))) Then
- 'MsgBox(ListBox1.SelectedItem & vbNewLine & ListBox1.SelectedIndex & vbNewLine & My.Settings.LastPlay.Substring(0, My.Settings.LastPlay.LastIndexOf(".")))
- ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
- 'MsgBox(ListBox1.SelectedItem)
- End If
- Player.LoadSong(basedir & ListBox1.SelectedItem)
- My.Settings.LastPlay = ListBox1.SelectedItem
- My.Settings.Save()
- PlayListCounter.Enabled = True
- 'PlayListCounter.Enabled = False
- endhere:
- End If
- End Sub
- Private Sub ReloadList()
- ListBaseDir()
- Dim itemid As Integer = 0
- Dim nowplaying As String = Player.GetSongName
- For Each item In ListBox1.Items
- If item.ToString.Contains(nowplaying) Then
- ListBox1.SelectedItem = item
- Exit For
- End If
- Next
- End Sub
- Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
- Player.SoundFadeOut()
- 'MsgBox(basedir & ListBox1.SelectedItem)
- Player.LoadSong(basedir & ListBox1.SelectedItem)
- Label1.Text = "Now Playing"
- My.Settings.LastPlay = ListBox1.SelectedItem
- My.Settings.Save()
- Player.SoundFadeIn()
- End Sub
- Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Player.SetPos(Player.GetTotalDuration - 5)
- End Sub
- Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
- If CheckBox1.Checked = True Then
- Background.Show()
- Else
- Background.Close()
- End If
- End Sub
- Private Sub PictureBox11_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox11.MouseClick
- If Me.Top = screenHeight - Me.Height And Me.Left = screenWidth - Me.Width Then
- Me.Top = screenHeight / 2 - Me.Height / 2
- Me.Left = screenWidth / 2 - Me.Width / 2
- Else
- Me.Top = screenHeight - Me.Height
- Me.Left = screenWidth - Me.Width
- End If
- End Sub
- Public Function ReadAPI(aroname As String, Apploc As String, Item As String)
- On Error Resume Next
- If aroname.Contains(".aro") = True Then
- aroname = aroname.Replace(".aro", "")
- End If
- 'MsgBox(Apploc & aroname & ".aro")
- Item = Item.ToLower()
- Dim configloc As String = Apploc & aroname & ".aro"
- Return ReadFileContain(configloc, Item & "=").replace(Item & "=", Nothing)
- End Function
- Public Sub WriteAPI(aroname As String, Apploc As String, Item As String, Content As String)
- On Error Resume Next
- If aroname.Contains(".aro") = True Then
- aroname = aroname.Replace(".aro", "")
- End If
- Item = Item.ToLower()
- Dim configloc As String = Apploc & aroname & ".aro"
- Dim configcontent As String = ReadFile(Apploc & aroname & ".aro")
- configcontent = configcontent.Replace(ReadFileContain(configloc, Item & "="), Item & "=" & Content)
- NewFileAndWrite(configloc, configcontent)
- End Sub
- Private Function ReadFile(ByVal Filename As String)
- On Error Resume Next
- Dim code As String = Nothing
- If System.IO.File.Exists(Filename) = True Then
- Dim objReader As New System.IO.StreamReader(Filename, System.Text.Encoding.GetEncoding(950))
- Dim sb As New StringBuilder
- Do While objReader.Peek() <> -1
- code = objReader.ReadLine()
- sb.AppendLine(code)
- Loop
- objReader.Dispose()
- Return sb.ToString
- Else
- Return Nothing
- End If
- End Function
- Private Function ReadFileContain(ByVal Filename As String, ByVal Contain As String)
- On Error Resume Next
- Dim code As String = Nothing
- If System.IO.File.Exists(Filename) = True Then
- Dim objReader As New System.IO.StreamReader(Filename, System.Text.Encoding.GetEncoding(950))
- Do While objReader.Peek() <> -1
- code = objReader.ReadLine()
- If code.Contains(Contain) Then
- objReader.Dispose()
- Return code
- End If
- Loop
- objReader.Dispose()
- Else
- Return Nothing
- End If
- End Function
- Private Function NewFileAndWrite(ByVal directory As String, ByVal fill As String)
- Dim sb As New StringBuilder
- sb.Append(fill)
- If My.Computer.FileSystem.DirectoryExists(directory) = True Then
- Try
- My.Computer.FileSystem.DeleteFile(directory)
- Catch ex As Exception
- Return False
- End Try
- End If
- Try
- IO.File.WriteAllText((directory), sb.ToString, System.Text.Encoding.GetEncoding(950))
- Catch ex As Exception
- Return False
- End Try
- Return True
- End Function
- End Class
|