Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Aqua Player 2.2 - Form1.vb

Form1.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports DataBase.DataBase
  2. Imports Microsoft.DirectX
  3. Imports Microsoft.DirectX.DirectSound
  4. Imports Microsoft.DirectX.AudioVideoPlayback
  5. Imports Microsoft.DirectX.DirectPlay
  6. Public Class frmSong
  7. #Region "Metodi personalizzati"
  8.     Public Structure Song
  9.         Dim Genere, Gruppo As String
  10.         Dim Anno, Note, Nome, Album As String
  11.         Dim Artista, Compositore, CopyRight As String
  12.         Dim URL, Sottotitolo, Lingua As String
  13.         Dim Valutazione, Traccia As Int16
  14.         Dim UltimoAscolto As Date
  15.         Dim Path As String
  16.     End Structure
  17.     Private Sub AddItem(ByVal F1 As String, ByVal f2 As String)
  18.         Dim L As ListViewItem
  19.         Dim S(1) As String
  20.         S(0) = F1
  21.         S(1) = f2
  22.         L = New ListViewItem(S)
  23.         lstInfo.Items.Add(L)
  24.     End Sub
  25.     Public Sub ResetLabel(ByVal Brano As Song)
  26.         lstInfo.Items.Clear()
  27.         AddItem("Titolo", Brano.Nome)
  28.         AddItem("Sottotitolo", Brano.Sottotitolo)
  29.         If MultimediaType(Brano.Path) = MultimediaFile.AudioFile Then
  30.             AddItem("Artista", Brano.Artista)
  31.             AddItem("Compositore", Brano.Compositore)
  32.         Else
  33.             AddItem("Attori", Brano.Artista)
  34.             AddItem("Regista", Brano.Compositore)
  35.         End If
  36.         AddItem("Genere", Brano.Genere)
  37.         If MultimediaType(Brano.Path) = MultimediaFile.AudioFile Then
  38.             AddItem("Gruppo", Brano.Gruppo)
  39.             AddItem("Album", Brano.Album)
  40.         End If
  41.         AddItem("Anno di pubblicazione", Brano.Anno)
  42.         AddItem("CopyRight", Brano.CopyRight)
  43.         AddItem("Lingua", Brano.Lingua)
  44.         AddItem("Sito internet", Brano.URL)
  45.         AddItem("Valutazione", Brano.Valutazione & " / 100")
  46.         AddItem("Utimo ascolto", Brano.UltimoAscolto)
  47.         AddItem("Note personali", Brano.Note)
  48.         lstInfo.Visible = True
  49.         imgVideo.Visible = False
  50.         If MultimediaType(MainDB(lstSongs.SelectedIndex).Path) = MultimediaFile.AudioFile Then
  51.             cmdAllScreen.Visible = False
  52.             lblPos.Location = New Drawing.Point(240, Me.Height - 122)
  53.         Else
  54.             cmdAllScreen.Visible = True
  55.             lblPos.Location = New Drawing.Point(364, Me.Height - 122)
  56.         End If
  57.     End Sub
  58.     Public Shared Sub Save()
  59.         Dim W As New IO.StreamWriter(Application.StartupPath + "\Songs.dat")
  60.         Dim S As Song
  61.         Dim i As Int32 = 0
  62.         frmSong.lblStatus.Text = "Salvataggio in corso..."
  63.         For Each S In MainDB
  64.             W.WriteLine("@" + S.Nome)
  65.             W.WriteLine(S.Path)
  66.             W.WriteLine(S.Anno)
  67.             W.WriteLine(S.Artista)
  68.             W.WriteLine(S.Genere)
  69.             W.WriteLine(S.Gruppo)
  70.             W.WriteLine(S.Note)
  71.             W.WriteLine(S.UltimoAscolto)
  72.             W.WriteLine(S.Valutazione)
  73.             W.WriteLine(S.Album)
  74.             W.WriteLine(S.Compositore)
  75.             W.WriteLine(S.CopyRight)
  76.             W.WriteLine(S.Lingua)
  77.             W.WriteLine(S.Sottotitolo)
  78.             W.WriteLine(S.Traccia)
  79.             W.WriteLine(S.URL)
  80.             i += 1
  81.             frmSong.lblStatus.Text = "Salvataggio in corso: " & (i * 100 / MainDB.Count) & "%"
  82.         Next
  83.         W.Close()
  84.         W = Nothing
  85.         frmSong.lblStatus.Text = "Salvataggio completato"
  86.     End Sub
  87.     Public Shared Function QuickSearch(ByVal ToSeek As String, ByVal InWhichFind As String) As Int16
  88.         Dim S As String = ""
  89.  
  90.         For i As Int16 = 0 To ToSeek.Length - 1
  91.             S = S & InWhichFind.Chars(i)
  92.         Next
  93.  
  94.         For i As Int64 = ToSeek.Length To InWhichFind.Length - 1
  95.             If S = ToSeek Then
  96.                 Return i
  97.             End If
  98.             S = S.Remove(0, 1)
  99.             S = S & InWhichFind.Chars(i)
  100.         Next
  101.     End Function
  102.     Public Shared Function MultimediaType(ByVal FileName As String) As MultimediaFile
  103.         Dim Ext As String = IO.Path.GetExtension(FileName)
  104.  
  105.         If Ext = ".wav" Or Ext = ".mp3" Or Ext = ".wma" Then
  106.             Return MultimediaFile.AudioFile
  107.         Else
  108.             If Ext = ".wmv" Or Ext = ".mpg" Or Ext = ".avi" Then
  109.                 Return MultimediaFile.VideoFile
  110.             Else
  111.                 Return MultimediaFile.NoMultimediaFile
  112.             End If
  113.         End If
  114.     End Function
  115.     Public Sub SetFormat(ByVal Value As MultimediaFile)
  116.         CF = Value
  117.         If Value = MultimediaFile.AudioFile Then
  118.             lstInfo.Visible = True
  119.             imgVideo.Visible = False
  120.         End If
  121.         If Value = MultimediaFile.VideoFile Then
  122.             lstInfo.Visible = False
  123.             imgVideo.Visible = True
  124.         End If
  125.     End Sub
  126.     Public Sub CenterVideo(ByVal Size As Drawing.Size)
  127.         Dim W As UInt32 = Size.Width
  128.         Dim H As UInt32 = Size.Height
  129.         Dim IW As UInt32 = lstInfo.Size.Width
  130.         Dim IH As UInt32 = lstInfo.Size.Height
  131.  
  132.         If Size = lstInfo.Size Then
  133.             Exit Sub
  134.         End If
  135.         If W * H < IW * IH Then
  136.             Dim X, Y As UInt32
  137.             X = lstInfo.Location.X + Math.Abs(IW - W) / 2
  138.             Y = lstInfo.Location.Y + Math.Abs(IH - H) / 2
  139.             imgVideo.Location = New Drawing.Point(X, Y)
  140.             Me.CenterToScreen()
  141.             Exit Sub
  142.         End If
  143.         If W * H > IW * IH Then
  144.             Me.Height += (H - IH)
  145.             Me.Width += (W - IW)
  146.             imgVideo.Location = lstInfo.Location
  147.             imgVideo.Size = MainF.DefaultSize
  148.             Me.CenterToScreen()
  149.             Exit Sub
  150.         End If
  151.     End Sub
  152.     Public Sub SetLastListen(ByVal Index As Int32)
  153.         Dim C As Song = MainDB(Index)
  154.         C.UltimoAscolto = Date.Now
  155.         MainDB(Index) = C
  156.     End Sub
  157.     Public Sub InitVideo(ByVal Index As Int32)
  158.         If MainDB(Index).Path.StartsWith("http://") Then
  159.             MainF = Video.FromUrl(New System.Uri(MainDB(Index).Path))
  160.             lblStatus.Text = "Streaming in corso: attendere..."
  161.         Else
  162.             MainF = New Video(MainDB(Index).Path)
  163.         End If
  164.         MainF.Owner = imgVideo
  165.  
  166.         MainF.FullScreen = False
  167.         imgVideo.Visible = True
  168.         lstInfo.Visible = False
  169.         cmdAllScreen.Visible = True
  170.         Me.MaximizeBox = False
  171.  
  172.         imgVideo.Location = lstInfo.Location
  173.         CenterVideo(MainF.DefaultSize)
  174.         Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
  175.         lblPos.Location = New Drawing.Point(364, Me.Height - 122)
  176.     End Sub
  177.     Public Sub InitAudio(ByVal Index As Int32)
  178.         cmdAllScreen.Visible = False
  179.         lblPos.Location = New Drawing.Point(240, Me.Height - 122)
  180.         If MainDB(Index).Path.StartsWith("http://") Then
  181.             MainF = Audio.FromUrl(New System.Uri(MainDB(Index).Path))
  182.         Else
  183.             MainF = New Audio(MainDB(Index).Path)
  184.         End If
  185.     End Sub
  186.     Public Sub PlayTheFirstTime(ByVal Index As Int32)
  187.         If Not MainF Is Nothing Then
  188.             MainF.Stop()
  189.         End If
  190.         SetFormat(MultimediaType(MainDB(Index).Path))
  191.         SetLastListen(Index)
  192.         CurrentIndex = Index
  193.         lstSongs.SelectedIndex = Index
  194.         cmdAllScreen.Enabled = False
  195.         If CF = MultimediaFile.AudioFile Then
  196.             InitAudio(Index)
  197.         Else
  198.             InitVideo(Index)
  199.         End If
  200.         MainF.Play()
  201.         cmdStop.Enabled = True
  202.         tmrControl.Enabled = True
  203.         trkSound.Maximum = MainF.Duration
  204.     End Sub
  205.     Public Sub SetPlayingAll(ByVal Mode As Boolean, Optional ByVal Reverse As Boolean = False)
  206.         PlayingAll = Not (Mode Xor Reverse)
  207.         PlayingAllReverse = Reverse
  208.         strAdd.Enabled = Mode
  209.         strModify.Enabled = Mode
  210.         strRemove.Enabled = Mode
  211.         strMove.Enabled = Mode
  212.         strPlayNext.Enabled = Mode
  213.         strPlayBefore.Enabled = Mode
  214.         strPlayRandom.Enabled = Mode
  215.         tmrPlayAll.Enabled = Not Mode
  216.     End Sub
  217.     Public ReadOnly Property IsOldVersion() As Boolean
  218.         Get
  219.             Dim R As New IO.StreamReader(Application.StartupPath + "\Songs.dat")
  220.             Dim s As String = ""
  221.  
  222.             For i As Int16 = 1 To 10
  223.                 s = R.ReadLine
  224.             Next
  225.  
  226.             If s = Nothing Then
  227.                 Return False
  228.             End If
  229.  
  230.             If s(0) = "@" Then
  231.                 'Se l'ottava riga inzia per '@', significa che indica il nome di una canzone:
  232.                 'perciò ci sono solo 7 campi per brano e quindi il file è scritto nella versione precedente
  233.                 Return True
  234.             Else
  235.                 Return False
  236.             End If
  237.         End Get
  238.     End Property
  239. #End Region
  240. #Region "Varabili, Costanti"
  241.     Public Enum MultimediaFile
  242.         AudioFile
  243.         VideoFile
  244.         NoMultimediaFile
  245.     End Enum
  246.     Public Const PBegin As Boolean = False
  247.     Public Const PStop As Boolean = True
  248.     Public CanSeek As Boolean = True
  249.     Public Shared CurrentIndex As Int32
  250.     Public Shared CurrentSound As SecondaryBuffer
  251.     Public Shared MainF As Object
  252.     Public Shared MainDB As New ArrayList
  253.     Public SearchResults As New ArrayList
  254.     Private CF As MultimediaFile
  255.     Private PlayingAll As Boolean = False
  256.     Private PlayingAllReverse As Boolean = False
  257. #End Region
  258.     Private Sub frmSong_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  259.         Try
  260.             Dim r As New IO.StreamReader(Application.StartupPath + "\Songs.dat")
  261.             Dim S As String
  262.             Dim C As Song = Nothing
  263.             Dim OldVersion As Boolean = IsOldVersion
  264.             lblStatus.Text = "Caricamento playlist in corso..."
  265.  
  266.             If OldVersion Then
  267.                 If MsgBox("Il file database è stato scritto con la precedente versione di Aqua Player e contiene meno" + _
  268.                 "dati rispetto alla versione corrente. Se si continua la lettura, solo i dati immessi verranno " + _
  269.                 "visualizzati e si potranno modificare le canzoni normalmente dopo l'accesso, aggiungendo nuovi dati. " + _
  270.                 "Continuare?", MsgBoxStyle.Question + vbYesNo, "Aqua Player 1.1") = MsgBoxResult.No Then
  271.                     Application.Exit()
  272.                 End If
  273.             End If
  274.  
  275.             While Not r.EndOfStream
  276.                 S = r.ReadLine
  277.                 If S(0) = "@" Then
  278.                     C.Nome = S.Remove(0, 1)
  279.                     C.Path = r.ReadLine
  280.                     C.Anno = r.ReadLine
  281.                     C.Artista = r.ReadLine
  282.                     C.Genere = r.ReadLine
  283.                     C.Gruppo = r.ReadLine
  284.                     C.Note = r.ReadLine
  285.                     Try
  286.                         C.UltimoAscolto = r.ReadLine
  287.                     Catch ICE As InvalidCastException
  288.                         C.UltimoAscolto = Nothing
  289.                     End Try
  290.                     C.Valutazione = r.ReadLine
  291.                     If Not OldVersion Then
  292.                         C.Album = r.ReadLine
  293.                         C.Compositore = r.ReadLine
  294.                         C.CopyRight = r.ReadLine
  295.                         C.Lingua = r.ReadLine
  296.                         C.Sottotitolo = r.ReadLine
  297.                         C.Traccia = r.ReadLine
  298.                         C.URL = r.ReadLine
  299.                     End If
  300.  
  301.                     MainDB.Add(C)
  302.                     lstSongs.Items.Add(C.Nome)
  303.  
  304.                 End If
  305.             End While
  306.  
  307.             lblStatus.Text = "Caricamento completato"
  308.         Catch FNFE As System.IO.FileNotFoundException
  309.             Dim w As New IO.StreamWriter("Songs.dat")
  310.             w.Close()
  311.             w = Nothing
  312.         End Try
  313.     End Sub
  314.     Private Sub lstSongs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSongs.SelectedIndexChanged
  315.         Try
  316.             If CanSeek Then
  317.                 ResetLabel(MainDB(lstSongs.SelectedIndex))
  318.             End If
  319.         Catch IOORE As ArgumentOutOfRangeException
  320.  
  321.         End Try
  322.     End Sub
  323.     Private Sub strAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileMultimedialeToolStripMenuItem.Click
  324.         If FOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
  325.             Dim NS As New frmNewSong(FOpen.FileName, "ADD")
  326.             NS.ShowDialog()
  327.         End If
  328.     End Sub
  329.     Private Sub strModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strModify.Click
  330.         If lstSongs.SelectedIndex >= 0 Then
  331.             Dim NS As New frmNewSong(MainDB(lstSongs.SelectedIndex).Path, "MOD", lstSongs.SelectedIndex)
  332.             NS.ShowDialog()
  333.         Else
  334.             MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation)
  335.         End If
  336.     End Sub
  337.     Private Sub strRemoveNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strRemoveNormal.Click
  338.         If lstSongs.SelectedIndex >= 0 Then
  339.             If MsgBox("Rimuovere questo brano?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
  340.                 CanSeek = False
  341.                 MainDB.RemoveAt(lstSongs.SelectedIndex)
  342.                 lstSongs.Items.RemoveAt(lstSongs.SelectedIndex)
  343.                 CanSeek = True
  344.             End If
  345.         End If
  346.     End Sub
  347.     Private Sub strExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  348.         Me.Close()
  349.     End Sub
  350.     Private Sub strMoveDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDown.Click
  351.         If lstSongs.SelectedIndex < 0 Or lstSongs.SelectedIndex = lstSongs.Items.Count - 1 Then
  352.             MsgBox("Impossibile spostare elemento!", MsgBoxStyle.Exclamation)
  353.             Exit Sub
  354.         End If
  355.         CanSeek = False
  356.  
  357.         Dim Temp As Song = MainDB.Item(lstSongs.SelectedIndex + 1)
  358.         Dim S As String = lstSongs.Items.Item(lstSongs.SelectedIndex + 1)
  359.         'Sposta elemento avanti
  360.         MainDB.Item(lstSongs.SelectedIndex + 1) = MainDB.Item(lstSongs.SelectedIndex)
  361.         'Porta l'elemento sostituito indietro
  362.         MainDB.Item(lstSongs.SelectedIndex) = Temp
  363.  
  364.         lstSongs.Items.Item(lstSongs.SelectedIndex + 1) = lstSongs.Items.Item(lstSongs.SelectedIndex)
  365.         lstSongs.Items.Item(lstSongs.SelectedIndex) = S
  366.         lstSongs.SelectedIndex += 1
  367.  
  368.         CanSeek = True
  369.     End Sub
  370.     Private Sub strMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strUp.Click
  371.         If lstSongs.SelectedIndex <= 0 Then
  372.             MsgBox("Impossibile spostare elemento!", MsgBoxStyle.Exclamation)
  373.             Exit Sub
  374.         End If
  375.         CanSeek = False
  376.  
  377.         Dim Temp As Song = MainDB.Item(lstSongs.SelectedIndex - 1)
  378.         Dim S As String = lstSongs.Items.Item(lstSongs.SelectedIndex - 1)
  379.         'Sposta elemento avanti
  380.         MainDB.Item(lstSongs.SelectedIndex - 1) = MainDB.Item(lstSongs.SelectedIndex)
  381.         'Porta l'elemento sostituito indietro
  382.         MainDB.Item(lstSongs.SelectedIndex) = Temp
  383.  
  384.         lstSongs.Items.Item(lstSongs.SelectedIndex - 1) = lstSongs.Items.Item(lstSongs.SelectedIndex)
  385.         lstSongs.Items.Item(lstSongs.SelectedIndex) = S
  386.         lstSongs.SelectedIndex -= 1
  387.  
  388.         CanSeek = True
  389.     End Sub
  390.     Private Sub strSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSave.Click
  391.         Save()
  392.     End Sub
  393.     Private Sub frmSong_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  394.         If Not MainF Is Nothing Then
  395.             MainF.Stop()
  396.         End If
  397.         If MsgBox("Salvare cambiamenti applicati?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
  398.             Save()
  399.         End If
  400.     End Sub
  401.     Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPLay.Click
  402.         If PlayingAll Or PlayingAllReverse Then
  403.             If Not MainF Is Nothing Then
  404.                 If MainF.Paused Then
  405.                     MainF.Play()
  406.                     cmdPause.Enabled = True
  407.                     Exit Sub
  408.                 End If
  409.             End If
  410.             If MsgBox("E' attualmente in corso la riproduzione di tutti i brani: premendo Play la si interromperà. Procedere comunque?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
  411.                 SetPlayingAll(PStop)
  412.             Else
  413.                 Exit Sub
  414.             End If
  415.         End If
  416.         If lstSongs.SelectedIndex < 0 Then
  417.             MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation)
  418.             Exit Sub
  419.         End If
  420.  
  421.         SetFormat(MultimediaType(MainDB(lstSongs.SelectedIndex).Path))
  422.         SetLastListen(lstSongs.SelectedIndex)
  423.         CurrentIndex = lstSongs.SelectedIndex
  424.         cmdAllScreen.Enabled = False
  425.  
  426.         Try
  427.             If MainF.Paused Then
  428.                 MainF.Play()
  429.                 cmdStop.Enabled = True
  430.                 cmdPause.Enabled = True
  431.             Else
  432.                 If MainF.State = StateFlags.Running Then
  433.                     MainF.Stop()
  434.                 End If
  435.                 If CF = MultimediaFile.AudioFile Then
  436.                     InitAudio(lstSongs.SelectedIndex)
  437.                 Else
  438.                     InitVideo(lstSongs.SelectedIndex)
  439.                 End If
  440.                 MainF.Play()
  441.                 cmdStop.Enabled = True
  442.                 trkSound.Maximum = MainF.Duration
  443.             End If
  444.             tmrControl.Enabled = True
  445.         Catch NRE As NullReferenceException
  446.             If CF = MultimediaFile.AudioFile Then
  447.                 InitAudio(lstSongs.SelectedIndex)
  448.             Else
  449.                 InitVideo(lstSongs.SelectedIndex)
  450.             End If
  451.             MainF.Play()
  452.             cmdStop.Enabled = True
  453.             cmdPause.Enabled = True
  454.             tmrControl.Enabled = True
  455.             trkSound.Maximum = MainF.Duration
  456.         End Try
  457.     End Sub
  458.     Private Sub cmdStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdStop.Click
  459.         If PlayingAll Or PlayingAllreverse Then
  460.             If MsgBox("E' attualmente in corso la riproduzione di tutti i brani: premendo Stop la si interromperà. Procedere comunque?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
  461.                 SetPlayingAll(PStop)
  462.             Else
  463.                 Exit Sub
  464.             End If
  465.         End If
  466.         MainF.Stop()
  467.         trkSound.Value = 0
  468.         MainF.CurrentPosition = 0
  469.         MainF = Nothing
  470.         cmdStop.Enabled = False
  471.         cmdPause.Enabled = False
  472.         tmrControl.Enabled = False
  473.         Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
  474.         Me.MaximizeBox = True
  475.         cmdAllScreen.Enabled = True
  476.         lblStatus.Text = "Riproduzione interrotta"
  477.     End Sub
  478.     Private Sub tmrControl_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrControl.Tick
  479.         Dim TimeElapsed, TimeTotal As TimeSpan
  480.  
  481.         TimeElapsed = TimeSpan.FromSeconds(CInt(MainF.CurrentPosition))
  482.         TimeTotal = TimeSpan.FromSeconds(CInt(MainF.Duration))
  483.         trkSound.Value = MainF.CurrentPosition
  484.         lblPos.Text = TimeElapsed.ToString & " secondi riprodotti su " & TimeTotal.ToString
  485.         lblStatus.Text = "Riproduzione in corso"
  486.         If TypeOf MainF Is Video Then
  487.             lblStatus.Text = lblStatus.Text + ": circa " & CInt(1 / MainF.AverageTimePerFrame) & " frame al secondo"
  488.         End If
  489.     End Sub
  490.     Private Sub trkSound_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trkSound.Scroll
  491.         If tmrControl.Enabled Then
  492.             MainF.CurrentPosition = trkSound.Value
  493.         End If
  494.     End Sub
  495.     Private Sub strSeekInPlaylist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSeek.Click
  496.         Dim ToSeek As String = InputBox("Nome o parte del nome della canzone da cercare:", "Cerca nella playlist")
  497.         Dim S As String
  498.  
  499.         If lstSongs.SelectedIndex < 0 Then
  500.             lstSongs.SelectedIndex = 0
  501.         End If
  502.  
  503.         For I As Int32 = lstSongs.SelectedIndex To MainDB.Count - 1
  504.             S = lstSongs.Items(I)
  505.             If S.Contains(ToSeek) Then
  506.                 lstSongs.SelectedIndex = I
  507.                 Exit For
  508.             End If
  509.         Next
  510.     End Sub
  511.     Private Sub strSeekInComputer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CercaNelComputerToolStripMenuItem.Click
  512.         Dim S As New frmSeek
  513.         S.ShowDialog()
  514.     End Sub
  515.     Private Sub strRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strRemoveAll.Click
  516.         If MsgBox("Rimuovere veramente tutti i brani?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
  517.             lstSongs.Items.Clear()
  518.             MainDB.Clear()
  519.         End If
  520.     End Sub
  521.     Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
  522.         MainF.Pause()
  523.         cmdPause.Enabled = False
  524.         tmrControl.Enabled = False
  525.         lblStatus.Text = "In pausa"
  526.     End Sub
  527.     Private Sub strRemoveChecked_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strRemoveChecked.Click
  528.         If MsgBox("Procedere con la cancellazione degli elementi spuntati?", MsgBoxStyle.Question + vbYesNo, "Conferma") = MsgBoxResult.No Then
  529.             Exit Sub
  530.         End If
  531.  
  532.         Dim ToDel As New ArrayList
  533.         Dim S As Song
  534.         Dim A As Int16
  535.  
  536.         For Each A In lstSongs.CheckedIndices
  537.             ToDel.Add(MainDB(A))
  538.         Next
  539.  
  540.         For Each S In ToDel
  541.             lstSongs.Items.Remove(S.Nome)
  542.             MainDB.Remove(S)
  543.         Next
  544.     End Sub
  545.     Private Sub cmdAllScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAllScreen.Click
  546.         cmdPlay_Click(Me, New System.EventArgs)
  547.         MainF.FullScreen = True
  548.     End Sub
  549.     Private Sub strSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearch.Click
  550.         If lstSongs.SelectedIndex < 0 Then
  551.             lstSongs.SelectedIndex = 0
  552.         End If
  553.         If lstSongs.SelectedIndex > 0 And lstSongs.SelectedIndex < lstSongs.Items.Count - 1 Then
  554.             lstSongs.SelectedIndex += 1
  555.         End If
  556.         If strSearchMode.SelectedIndex < 0 Then
  557.             MsgBox("Nessuna modalità di ricerca selezionata!", MsgBoxStyle.Exclamation)
  558.             Exit Sub
  559.         End If
  560.         If strSearchKey.Text = "" Then
  561.             MsgBox("Nessuna chiave di ricerca inserita!", MsgBoxStyle.Exclamation)
  562.             Exit Sub
  563.         End If
  564.  
  565.         lblStatus.Text = "Ricerca in corso..."
  566.         prgSearch.Visible = True
  567.         prgSearch.Maximum = lstSongs.Items.Count
  568.         prgSearch.Width = Me.Width - lblStatus.Size.Width - 20
  569.         SearchResults.Clear()
  570.  
  571.         Select Case strSearchMode.SelectedIndex
  572.             Case 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12
  573.                 Dim Key As String = strSearchKey.Text
  574.                 Dim S As String = ""
  575.  
  576.                 For I As Int32 = lstSongs.SelectedIndex To MainDB.Count - 1
  577.                     Select Case strSearchMode.SelectedIndex
  578.                         Case 0
  579.                             S = MainDB(I).Nome
  580.                         Case 1
  581.                             S = MainDB(I).Artista
  582.                         Case 2
  583.                             S = MainDB(I).Genere
  584.                         Case 3
  585.                             S = MainDB(I).Gruppo
  586.                         Case 4
  587.                             S = MainDB(I).Anno
  588.                         Case 6
  589.                             S = MainDB(I).Note
  590.                         Case 7
  591.                             S = MainDB(I).Album
  592.                         Case 8
  593.                             S = MainDB(I).Compositore
  594.                         Case 9
  595.                             S = MainDB(I).CopyRight
  596.                         Case 10
  597.                             S = MainDB(I).URL
  598.                         Case 11
  599.                             S = MainDB(I).Sottotitolo
  600.                         Case 12
  601.                             S = MainDB(I).Lingua
  602.                     End Select
  603.                     If S.Contains(Key) Then
  604.                         strSearchResult.Items.Add(lstSongs.Items(I))
  605.                         SearchResults.Add(I)
  606.                     End If
  607.                     prgSearch.Value += 1
  608.                 Next
  609.             Case Else
  610.                 Dim Key As Int32 = strSearchKey.Text
  611.                 Dim S As Int32
  612.  
  613.                 For I As Int32 = lstSongs.SelectedIndex To MainDB.Count - 1
  614.                     Select Case strSearchMode.SelectedIndex
  615.                         Case 5
  616.                             S = MainDB(I).Valutazione
  617.                         Case 13
  618.                             S = MainDB(I).Traccia
  619.                     End Select
  620.                     If S = Key Then
  621.                         strSearchResult.Items.Add(lstSongs.Items(I))
  622.                         SearchResults.Add(I)
  623.                     End If
  624.                 Next
  625.                 prgSearch.Value += 1
  626.         End Select
  627.  
  628.         lblStatus.Text = "Ricerca terminata"
  629.         strSearchResult.Visible = True
  630.         strSep.Visible = True
  631.         strlblSearch.Visible = True
  632.         prgSearch.Value = 0
  633.         prgSearch.Visible = False
  634.         strSearchResult.Items.Add("Nascondi risultati")
  635.     End Sub
  636.     Private Sub strSearchKey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearchKey.Click
  637.         If strSearchKey.Text = "[Chiave di ricerca]" Then
  638.             strSearchKey.Text = Nothing
  639.         End If
  640.     End Sub
  641.     Private Sub strSearchResult_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearchResult.SelectedIndexChanged
  642.         If strSearchResult.SelectedIndex >= 0 Then
  643.             If strSearchResult.SelectedIndex = strSearchResult.Items.Count - 1 Then
  644.                 strSearchResult.Visible = False
  645.                 strSep.Visible = False
  646.                 strlblSearch.Visible = False
  647.                 Exit Sub
  648.             End If
  649.             lstSongs.SelectedIndex = SearchResults(strSearchResult.SelectedIndex)
  650.         End If
  651.     End Sub
  652.     Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
  653.         Dim A As New frmAbout
  654.         A.ShowDialog()
  655.     End Sub
  656.     Private Sub RiproduciSuccessivoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPlayNext.Click
  657.         If CurrentIndex < lstSongs.Items.Count - 1 Then
  658.             If Not MainF Is Nothing Then
  659.                 MainF.Stop()
  660.             End If
  661.             CurrentIndex += 1
  662.             lstSongs.SelectedIndex = CurrentIndex
  663.             SetFormat(MultimediaType(MainDB(lstSongs.SelectedIndex).Path))
  664.             SetLastListen(lstSongs.SelectedIndex)
  665.             CurrentIndex = lstSongs.SelectedIndex
  666.             cmdAllScreen.Enabled = False
  667.  
  668.             If CF = MultimediaFile.AudioFile Then
  669.                 InitAudio(lstSongs.SelectedIndex)
  670.             Else
  671.                 InitVideo(lstSongs.SelectedIndex)
  672.             End If
  673.             MainF.Play()
  674.             cmdStop.Enabled = True
  675.             tmrControl.Enabled = True
  676.             trkSound.Maximum = MainF.Duration
  677.         End If
  678.     End Sub
  679.     Private Sub RiproduciPrecedenteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPlayBefore.Click
  680.         If CurrentIndex > 0 Then
  681.             If Not MainF Is Nothing Then
  682.                 MainF.Stop()
  683.             End If
  684.             CurrentIndex -= 1
  685.             lstSongs.SelectedIndex = CurrentIndex
  686.             SetFormat(MultimediaType(MainDB(lstSongs.SelectedIndex).Path))
  687.             SetLastListen(lstSongs.SelectedIndex)
  688.             CurrentIndex = lstSongs.SelectedIndex
  689.             cmdAllScreen.Enabled = False
  690.  
  691.             If CF = MultimediaFile.AudioFile Then
  692.                 InitAudio(lstSongs.SelectedIndex)
  693.             Else
  694.                 InitVideo(lstSongs.SelectedIndex)
  695.             End If
  696.             MainF.Play()
  697.             cmdStop.Enabled = True
  698.             tmrControl.Enabled = True
  699.             trkSound.Maximum = MainF.Duration
  700.         End If
  701.     End Sub
  702.     Private Sub RiproduciTuttoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RiproduciTuttoToolStripMenuItem.Click
  703.         SetPlayingAll(PBegin)
  704.         PlayTheFirstTime(0)
  705.         lblStatus.Text = "Riproduzione di tutti i brani"
  706.     End Sub
  707.     Private Sub tmrPlayAll_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPlayAll.Tick
  708.         If MainF.CurrentPosition = MainF.Duration Then
  709.             If PlayingAll Then
  710.                 If CurrentIndex = lstSongs.Items.Count - 1 Then
  711.                     lblStatus.Text = "Riproduzione terminata"
  712.                     tmrPlayAll.Enabled = False
  713.                     PlayingAll = False
  714.                     Exit Sub
  715.                 End If
  716.                 PlayTheFirstTime(CurrentIndex + 1)
  717.             End If
  718.             If PlayingAllreverse Then
  719.                 If CurrentIndex = 0 Then
  720.                     lblStatus.Text = "Riproduzione terminata"
  721.                     tmrPlayAll.Enabled = False
  722.                     PlayingAllreverse = False
  723.                     Exit Sub
  724.                 End If
  725.                 PlayTheFirstTime(CurrentIndex - 1)
  726.             End If
  727.         End If
  728.     End Sub
  729.     Private Sub InOrdineInversoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InOrdineInversoToolStripMenuItem.Click
  730.         SetPlayingAll(PBegin, True)
  731.         PlayTheFirstTime(lstSongs.Items.Count - 1)
  732.         lblStatus.Text = "Riproduzione di tutti i brani in ordine inverso"
  733.     End Sub
  734.     Private Sub strPlayRandom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPlayRandom.Click
  735.         Randomize()
  736.         Dim R As New Random()
  737.         PlayTheFirstTime(R.Next(lstSongs.Items.Count - 1))
  738.     End Sub
  739.     Private Sub frmSong_ResizeBegin(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ResizeBegin
  740.         imgVideo.Visible = False
  741.         lstInfo.Visible = True
  742.     End Sub
  743.     Private Sub ControlloVolumeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ControlloVolumeToolStripMenuItem.Click
  744.         Try
  745.             Shell("C:\WINDOWS\System32\sndvol32.exe", AppWinStyle.NormalFocus)
  746.         Catch FNFE As IO.FileNotFoundException
  747.             MsgBox("Probabilmente non si sta lavorando su un sistema operativo Windows o non si dispone del controllo volume di sistema!", MsgBoxStyle.Exclamation)
  748.         End Try
  749.     End Sub
  750.     Private Sub strAddWeb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAddWeb.Click
  751.         Dim URL As String = InputBox("Incollare qui l'indirizzo:", "Acquisisci file dal web")
  752.         Dim A As New frmNewSong(URL, "ADD")
  753.         A.ShowDialog()
  754.     End Sub
  755.     Private Sub strSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSort.Click
  756.         Dim List As New ArrayList
  757.  
  758.         lblStatus.Text = "Attendere, ordinamento in corso..."
  759.  
  760.         'Scrive nell'array il nome di tutte le canzoni nell'ordine corrente
  761.         For i As Int32 = 0 To lstSongs.Items.Count - 1
  762.             List.Add(lstSongs.Items(i))
  763.         Next
  764.  
  765.         'Ordina la lista
  766.         lstSongs.Sorted = True
  767.  
  768.         'Controlla ogni elemento dell'arraylist, ne preleva il nome, cerca il nome
  769.         'nella lista ordinata e colloca al posto del nome nell'arraylist l'indice corrispondente
  770.         'nella lista ordinata
  771.         Dim S As String = ""
  772.         Dim Index As Int32
  773.         For i As Int32 = 0 To lstSongs.Items.Count - 1
  774.             S = List(i)
  775.             Index = lstSongs.Items.IndexOf(S)
  776.             List(i) = Index
  777.         Next
  778.  
  779.         'Riordina MainDB associando ogni elemento dell'arraylist a un'altra
  780.         'arraylist di backup
  781.         Dim Backup As New ArrayList
  782.         Dim Counter As Int32 = 0
  783.         'Crea List.Count elementi in Backup
  784.         For i As Int32 = 0 To List.Count - 1
  785.             Backup.Add(Nothing)
  786.         Next
  787.         'Associa all'elemento List(i) di Backup l'elemento i di MainDB: in pratica, ad ogni iterazione
  788.         'aggiunge elementi successivi di MainDB in celle di memoria diverse di Backup, descritte dalla
  789.         'lista ordinata di indici List
  790.         For Each Index In List
  791.             Backup(Index) = MainDB(Counter)
  792.             Counter += 1
  793.         Next
  794.         MainDB = Backup
  795.  
  796.         lblStatus.Text = "Ordinamento completato"
  797.     End Sub
  798. End Class