Main.vb 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. 
  2. Imports System.IO
  3. Imports System.Text
  4. Public Class Main
  5. Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
  6. Dim screenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
  7. Private IsFormBeingDragged As Boolean = False
  8. Private MouseDownX As Integer
  9. Private MouseDownY As Integer
  10. Dim Player As New PlayerControl
  11. Dim fm As New FileManagement
  12. Dim basedir As String = My.Settings.Basedir
  13. Dim Arozpath As String = ""
  14. 'Basic Form Movement handler
  15. Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel1.MouseDown
  16. If e.Button = MouseButtons.Left Then
  17. IsFormBeingDragged = True
  18. MouseDownX = e.X
  19. MouseDownY = e.Y
  20. End If
  21. End Sub
  22. Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel1.MouseUp
  23. If e.Button = MouseButtons.Left Then
  24. IsFormBeingDragged = False
  25. End If
  26. End Sub
  27. Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Panel1.MouseMove
  28. If IsFormBeingDragged Then
  29. Dim temp As Point = New Point()
  30. temp.X = Me.Location.X + (e.X - MouseDownX)
  31. temp.Y = Me.Location.Y + (e.Y - MouseDownY)
  32. Me.Location = temp
  33. temp = Nothing
  34. End If
  35. End Sub
  36. ' Controlling Events handling clicks and buttons
  37. Private Sub Panel1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.DoubleClick
  38. My.Settings.Basedir = basedir
  39. My.Settings.Enrichedbg = CheckBox2.Checked
  40. My.Settings.bg = CheckBox1.Checked
  41. My.Settings.Save()
  42. Me.Close()
  43. End Sub
  44. Private Sub Panel1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseClick
  45. If e.Button = MouseButtons.Right Then
  46. MsgBox("Clicked")
  47. End If
  48. End Sub
  49. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
  50. If Label1.Text = "Now Playing" Then
  51. GoTo endhere
  52. End If
  53. PictureBox2.Cursor = Cursors.Arrow
  54. Label1.Text = "Now Playing"
  55. Player.SetVol(0)
  56. Player.Play()
  57. For x As Integer = 0 To My.Settings.Vol Step 1
  58. Player.SetVol(x)
  59. Threading.Thread.Sleep(18)
  60. Next
  61. endhere:
  62. Threading.Thread.Sleep(120)
  63. PictureBox2.Cursor = Cursors.Hand
  64. End Sub
  65. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
  66. PictureBox3.Cursor = Cursors.Arrow
  67. For x As Integer = Player.GetVol To 0 Step -1
  68. Player.SetVol(x)
  69. Threading.Thread.Sleep(20)
  70. Next
  71. Player.Pause()
  72. Player.SetVol(My.Settings.Vol)
  73. Threading.Thread.Sleep(120)
  74. PictureBox3.Cursor = Cursors.Hand
  75. Label1.Text = "Paused"
  76. End Sub
  77. Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  78. 'Player.LoadSong("e:\Music\「アヤノの幸福理論 Piano Ver. 」歌ってみた【εїз】.mp3")
  79. If My.Computer.FileSystem.FileExists(basedir & My.Settings.LastPlay) Then
  80. Player.LoadSong(basedir & My.Settings.LastPlay)
  81. Label2.Text = Player.GetSongName
  82. Else
  83. Label2.Text = "Please select a song to play"
  84. End If
  85. CheckBox1.Checked = My.Settings.bg
  86. CheckBox2.Checked = My.Settings.Enrichedbg
  87. Player.initiateVol()
  88. fm.InitiateFolderSystem()
  89. Player.initiateLoopSetting()
  90. ListBaseDir()
  91. If CheckBox1.Checked = True Then
  92. Background.Show()
  93. End If
  94. If CheckArOZOnline() = True Then
  95. Label7.Text = "ArOZ Linked"
  96. Label7.ForeColor = Color.Red
  97. 'MsgBox(Arozpath)
  98. TellArOZMusicPlaying()
  99. Else
  100. Label7.Text = "Stand alone"
  101. Label7.ForeColor = Color.Black
  102. End If
  103. End Sub
  104. Private Sub ClosingChat() Handles Me.Closing
  105. If Arozpath <> "" Then
  106. Dim ArOZdir = Path.GetDirectoryName(Arozpath)
  107. Dim apidir As String = ArOZdir & "\plugins\API\"
  108. If ReadAPI("api.aro", apidir, "balloon.rx") = "" Then
  109. WriteAPI("api.aro", apidir, "balloon.rx", "AM Player 被你關掉了…")
  110. End If
  111. End If
  112. End Sub
  113. Public Sub TellArOZMusicPlaying()
  114. Dim ArOZdir = Path.GetDirectoryName(Arozpath)
  115. Dim apidir As String = ArOZdir & "\plugins\API\"
  116. 'MsgBox(apifile)
  117. If ReadAPI("api.aro", apidir, "balloon.rx") = "" Then
  118. WriteAPI("api.aro", apidir, "balloon.rx", "AM Player 已開啟~")
  119. End If
  120. End Sub
  121. Public Function CheckArOZOnline()
  122. Dim p() As Process
  123. p = Process.GetProcesses
  124. For Each proc As Process In p
  125. If proc.ProcessName.ToString.Contains("ArOZ") Then
  126. Arozpath = proc.MainModule.FileName
  127. GoTo ArOZfound
  128. End If
  129. Next
  130. Return False
  131. ArOZfound:
  132. Return True
  133. End Function
  134. Public Sub ListBaseDir(Optional ByVal loc As String = "")
  135. If loc = Nothing Then
  136. loc = basedir
  137. End If
  138. If My.Computer.FileSystem.DirectoryExists(loc) Then 'It is a folder, read all content
  139. ListBox1.Items.Clear()
  140. Dim x = fm.ListByDate(basedir)
  141. For Each y In x
  142. If y.ToString.Contains(".mp3") Or y.ToString.Contains(".mp4") Or y.ToString.Contains(".wav") Or y.ToString.Contains(".avi") Then
  143. ListBox1.Items.Add(y.ToString)
  144. Else
  145. End If
  146. Next
  147. Else 'It is a Playlist but not a folder, link all base dir
  148. End If
  149. End Sub
  150. Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
  151. PictureBox1.Cursor = Cursors.Arrow
  152. Player.SoundFadeOut()
  153. ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
  154. Player.LoadSong(basedir & ListBox1.SelectedItem)
  155. My.Settings.LastPlay = ListBox1.SelectedItem
  156. My.Settings.Save()
  157. Threading.Thread.Sleep(120)
  158. PictureBox1.Cursor = Cursors.Hand
  159. Player.SoundFadeIn()
  160. End Sub
  161. Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
  162. PictureBox5.Cursor = Cursors.Arrow
  163. Player.SoundFadeOut()
  164. ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
  165. Player.LoadSong(basedir & ListBox1.SelectedItem)
  166. My.Settings.LastPlay = ListBox1.SelectedItem
  167. My.Settings.Save()
  168. Threading.Thread.Sleep(120)
  169. PictureBox5.Cursor = Cursors.Hand
  170. Player.SoundFadeIn()
  171. End Sub
  172. Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
  173. PictureBox4.Cursor = Cursors.Arrow
  174. Player.StopPlaying()
  175. Threading.Thread.Sleep(120)
  176. PictureBox4.Cursor = Cursors.Hand
  177. Label1.Text = "Stopped"
  178. End Sub
  179. Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
  180. PictureBox7.Cursor = Cursors.Arrow
  181. Player.VolUp()
  182. Threading.Thread.Sleep(120)
  183. PictureBox7.Cursor = Cursors.Hand
  184. My.Settings.Vol = Player.GetVol
  185. My.Settings.Save()
  186. End Sub
  187. Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
  188. PictureBox6.Cursor = Cursors.Arrow
  189. Player.VolDown()
  190. Threading.Thread.Sleep(120)
  191. PictureBox6.Cursor = Cursors.Hand
  192. My.Settings.Vol = Player.GetVol
  193. My.Settings.Save()
  194. End Sub
  195. '////Other form controling Vol.
  196. Public Sub MainVolUP()
  197. On Error Resume Next
  198. PictureBox7.Cursor = Cursors.Arrow
  199. Player.VolUp()
  200. Threading.Thread.Sleep(80)
  201. PictureBox7.Cursor = Cursors.Hand
  202. My.Settings.Vol = Player.GetVol
  203. My.Settings.Save()
  204. End Sub
  205. Public Sub MainVolDown()
  206. On Error Resume Next
  207. PictureBox6.Cursor = Cursors.Arrow
  208. Player.VolDown()
  209. Threading.Thread.Sleep(80)
  210. PictureBox6.Cursor = Cursors.Hand
  211. My.Settings.Vol = Player.GetVol
  212. My.Settings.Save()
  213. End Sub
  214. Public Sub PictureBox10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox10.Click
  215. PictureBox10.Cursor = Cursors.Arrow
  216. If LoopCounter.Enabled Then
  217. LoopCounter.Enabled = False
  218. Label6.Text = "End Stop"
  219. My.Settings.LoopMode = "End Stop"
  220. My.Settings.Save()
  221. Else
  222. LoopCounter.Enabled = True
  223. PlayListCounter.Enabled = False
  224. Label6.Text = "Single Loop"
  225. My.Settings.LoopMode = "Single Loop"
  226. My.Settings.Save()
  227. End If
  228. Threading.Thread.Sleep(120)
  229. PictureBox10.Cursor = Cursors.Hand
  230. End Sub
  231. Public Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click
  232. PictureBox9.Cursor = Cursors.Arrow
  233. If PlayListCounter.Enabled Then
  234. PlayListCounter.Enabled = False
  235. Label6.Text = "End Stop"
  236. My.Settings.LoopMode = "End Stop"
  237. My.Settings.Save()
  238. Else
  239. PlayListCounter.Enabled = True
  240. LoopCounter.Enabled = False
  241. Label6.Text = "Playlist Loop"
  242. My.Settings.LoopMode = "Playlist Loop"
  243. My.Settings.Save()
  244. End If
  245. Threading.Thread.Sleep(120)
  246. PictureBox9.Cursor = Cursors.Hand
  247. End Sub
  248. Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
  249. PictureBox8.Cursor = Cursors.Arrow
  250. Dim fd As OpenFileDialog = New OpenFileDialog()
  251. Dim strFileName As String = ""
  252. fd.Title = "Play Song"
  253. fd.InitialDirectory = basedir
  254. fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
  255. fd.FilterIndex = 2
  256. fd.RestoreDirectory = True
  257. If fd.ShowDialog() = DialogResult.OK Then
  258. strFileName = fd.FileName
  259. Else
  260. GoTo Endhere
  261. End If
  262. Try
  263. Player.LoadSong(strFileName)
  264. Label1.Text = "Now Playing"
  265. Catch ex As Exception
  266. Label1.Text = "File Not Found"
  267. End Try
  268. ListBox1.Items.Clear()
  269. basedir = strFileName.Substring(0, strFileName.LastIndexOf("\") + 1)
  270. ListBox1.Items.Add(strFileName.Replace(basedir, ""))
  271. Endhere:
  272. Threading.Thread.Sleep(120)
  273. PictureBox8.Cursor = Cursors.Hand
  274. ReloadList()
  275. End Sub
  276. 'Update Tiem elft and percentage
  277. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  278. On Error Resume Next
  279. Dim a As Double = Player.GetCurrentPos / 60
  280. Dim b As Integer = Math.Round(a)
  281. If b > a Then
  282. b = b - 1
  283. a = (a - b) * 60
  284. Else
  285. a = (a - b) * 60
  286. End If
  287. Dim n As String
  288. If Math.Round(a) < 10 Then
  289. n = "0" & Math.Round(a)
  290. Else
  291. n = Math.Round(a)
  292. End If
  293. Label3.Text = b & " : " & n
  294. Dim x As Double = Player.GetTotalDuration / 60
  295. Dim y As Integer = Math.Round(x)
  296. Dim m As String
  297. If y > x Then
  298. y = y - 1
  299. x = (x - y) * 60
  300. Else
  301. x = (x - y) * 60
  302. End If
  303. If Math.Round(x) < 10 Then
  304. m = "0" & Math.Round(x)
  305. Else
  306. m = Math.Round(x)
  307. End If
  308. Label4.Text = y & " : " & m
  309. ProgressBar1.Value = Player.GetCurrentPos / Player.GetTotalDuration * 100
  310. Label2.Text = Player.GetSongName
  311. End Sub
  312. '//Soring and browsing
  313. 'Creat File System
  314. Private Sub LoopCounter_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoopCounter.Tick
  315. If Player.GetCurrentPos >= Player.GetTotalDuration - 0.2 Then
  316. Player.StopPlaying()
  317. Player.Play()
  318. End If
  319. End Sub
  320. '//Looping the playlist
  321. Private Sub PlayListCounter_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayListCounter.Tick
  322. If Player.GetCurrentPos < 0.5 Then
  323. Dim itemid As Integer = 0
  324. Dim nowplaying As String = My.Settings.LastPlay
  325. For Each item In ListBox1.Items
  326. If item.ToString.Contains(nowplaying) Then
  327. ListBox1.SelectedItem = item
  328. Exit For
  329. End If
  330. Next
  331. End If
  332. If Player.GetCurrentPos >= Player.GetTotalDuration - 0.2 Then
  333. If Player.GetTotalDuration = 0 Or Player.GetCurrentPos = 0 Then
  334. GoTo endhere
  335. End If
  336. PlayListCounter.Enabled = False
  337. Dim itemid As Integer = 0
  338. Dim nowplaying As String = Player.GetSongName
  339. For Each item In ListBox1.Items
  340. If item.ToString.Contains(nowplaying) Then
  341. ListBox1.SelectedItem = item
  342. Exit For
  343. End If
  344. Next
  345. ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
  346. If ListBox1.SelectedItem.ToString.Contains(My.Settings.LastPlay.Substring(0, My.Settings.LastPlay.LastIndexOf("."))) Then
  347. 'MsgBox(ListBox1.SelectedItem & vbNewLine & ListBox1.SelectedIndex & vbNewLine & My.Settings.LastPlay.Substring(0, My.Settings.LastPlay.LastIndexOf(".")))
  348. ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
  349. 'MsgBox(ListBox1.SelectedItem)
  350. End If
  351. Player.LoadSong(basedir & ListBox1.SelectedItem)
  352. My.Settings.LastPlay = ListBox1.SelectedItem
  353. My.Settings.Save()
  354. PlayListCounter.Enabled = True
  355. 'PlayListCounter.Enabled = False
  356. endhere:
  357. End If
  358. End Sub
  359. Private Sub ReloadList()
  360. ListBaseDir()
  361. Dim itemid As Integer = 0
  362. Dim nowplaying As String = Player.GetSongName
  363. For Each item In ListBox1.Items
  364. If item.ToString.Contains(nowplaying) Then
  365. ListBox1.SelectedItem = item
  366. Exit For
  367. End If
  368. Next
  369. End Sub
  370. Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
  371. Player.SoundFadeOut()
  372. 'MsgBox(basedir & ListBox1.SelectedItem)
  373. Player.LoadSong(basedir & ListBox1.SelectedItem)
  374. Label1.Text = "Now Playing"
  375. My.Settings.LastPlay = ListBox1.SelectedItem
  376. My.Settings.Save()
  377. Player.SoundFadeIn()
  378. End Sub
  379. Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
  380. Player.SetPos(Player.GetTotalDuration - 5)
  381. End Sub
  382. Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
  383. If CheckBox1.Checked = True Then
  384. Background.Show()
  385. Else
  386. Background.Close()
  387. End If
  388. End Sub
  389. Private Sub PictureBox11_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox11.MouseClick
  390. If Me.Top = screenHeight - Me.Height And Me.Left = screenWidth - Me.Width Then
  391. Me.Top = screenHeight / 2 - Me.Height / 2
  392. Me.Left = screenWidth / 2 - Me.Width / 2
  393. Else
  394. Me.Top = screenHeight - Me.Height
  395. Me.Left = screenWidth - Me.Width
  396. End If
  397. End Sub
  398. Public Function ReadAPI(aroname As String, Apploc As String, Item As String)
  399. On Error Resume Next
  400. If aroname.Contains(".aro") = True Then
  401. aroname = aroname.Replace(".aro", "")
  402. End If
  403. 'MsgBox(Apploc & aroname & ".aro")
  404. Item = Item.ToLower()
  405. Dim configloc As String = Apploc & aroname & ".aro"
  406. Return ReadFileContain(configloc, Item & "=").replace(Item & "=", Nothing)
  407. End Function
  408. Public Sub WriteAPI(aroname As String, Apploc As String, Item As String, Content As String)
  409. On Error Resume Next
  410. If aroname.Contains(".aro") = True Then
  411. aroname = aroname.Replace(".aro", "")
  412. End If
  413. Item = Item.ToLower()
  414. Dim configloc As String = Apploc & aroname & ".aro"
  415. Dim configcontent As String = ReadFile(Apploc & aroname & ".aro")
  416. configcontent = configcontent.Replace(ReadFileContain(configloc, Item & "="), Item & "=" & Content)
  417. NewFileAndWrite(configloc, configcontent)
  418. End Sub
  419. Private Function ReadFile(ByVal Filename As String)
  420. On Error Resume Next
  421. Dim code As String = Nothing
  422. If System.IO.File.Exists(Filename) = True Then
  423. Dim objReader As New System.IO.StreamReader(Filename, System.Text.Encoding.GetEncoding(950))
  424. Dim sb As New StringBuilder
  425. Do While objReader.Peek() <> -1
  426. code = objReader.ReadLine()
  427. sb.AppendLine(code)
  428. Loop
  429. objReader.Dispose()
  430. Return sb.ToString
  431. Else
  432. Return Nothing
  433. End If
  434. End Function
  435. Private Function ReadFileContain(ByVal Filename As String, ByVal Contain As String)
  436. On Error Resume Next
  437. Dim code As String = Nothing
  438. If System.IO.File.Exists(Filename) = True Then
  439. Dim objReader As New System.IO.StreamReader(Filename, System.Text.Encoding.GetEncoding(950))
  440. Do While objReader.Peek() <> -1
  441. code = objReader.ReadLine()
  442. If code.Contains(Contain) Then
  443. objReader.Dispose()
  444. Return code
  445. End If
  446. Loop
  447. objReader.Dispose()
  448. Else
  449. Return Nothing
  450. End If
  451. End Function
  452. Private Function NewFileAndWrite(ByVal directory As String, ByVal fill As String)
  453. Dim sb As New StringBuilder
  454. sb.Append(fill)
  455. If My.Computer.FileSystem.DirectoryExists(directory) = True Then
  456. Try
  457. My.Computer.FileSystem.DeleteFile(directory)
  458. Catch ex As Exception
  459. Return False
  460. End Try
  461. End If
  462. Try
  463. IO.File.WriteAllText((directory), sb.ToString, System.Text.Encoding.GetEncoding(950))
  464. Catch ex As Exception
  465. Return False
  466. End Try
  467. Return True
  468. End Function
  469. End Class