Imports DataBase.DataBase
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Imports Microsoft.DirectX.AudioVideoPlayback
Imports Microsoft.DirectX.DirectPlay
Public Class frmSong
#Region "Metodi personalizzati"
Public Structure Song
Dim Genere, Gruppo As String
Dim Anno, Note, Nome, Album As String
Dim Artista, Compositore, CopyRight As String
Dim URL, Sottotitolo, Lingua As String
Dim Valutazione, Traccia As Int16
Dim UltimoAscolto As Date
Dim Path As String
End Structure
Private Sub AddItem(ByVal F1 As String, ByVal f2 As String)
Dim L As ListViewItem
Dim S(1) As String
S(0) = F1
S(1) = f2
L = New ListViewItem(S)
lstInfo.Items.Add(L)
End Sub
Public Sub ResetLabel(ByVal Brano As Song)
lstInfo.Items.Clear()
AddItem("Titolo", Brano.Nome)
AddItem("Sottotitolo", Brano.Sottotitolo)
If MultimediaType(Brano.Path) = MultimediaFile.AudioFile Then
AddItem("Artista", Brano.Artista)
AddItem("Compositore", Brano.Compositore)
Else
AddItem("Attori", Brano.Artista)
AddItem("Regista", Brano.Compositore)
End If
AddItem("Genere", Brano.Genere)
If MultimediaType(Brano.Path) = MultimediaFile.AudioFile Then
AddItem("Gruppo", Brano.Gruppo)
AddItem("Album", Brano.Album)
End If
AddItem("Anno di pubblicazione", Brano.Anno)
AddItem("CopyRight", Brano.CopyRight)
AddItem("Lingua", Brano.Lingua)
AddItem("Sito internet", Brano.URL)
AddItem("Valutazione", Brano.Valutazione & " / 100")
AddItem("Utimo ascolto", Brano.UltimoAscolto)
AddItem("Note personali", Brano.Note)
lstInfo.Visible = True
imgVideo.Visible = False
If MultimediaType(MainDB(lstSongs.SelectedIndex).Path) = MultimediaFile.AudioFile Then
cmdAllScreen.Visible = False
lblPos.Location = New Drawing.Point(240, Me.Height - 122)
Else
cmdAllScreen.Visible = True
lblPos.Location = New Drawing.Point(364, Me.Height - 122)
End If
End Sub
Public Shared Sub Save()
Dim W As New IO.StreamWriter(Application.StartupPath + "\Songs.dat")
Dim S As Song
Dim i As Int32 = 0
frmSong.lblStatus.Text = "Salvataggio in corso..."
For Each S In MainDB
W.WriteLine("@" + S.Nome)
W.WriteLine(S.Path)
W.WriteLine(S.Anno)
W.WriteLine(S.Artista)
W.WriteLine(S.Genere)
W.WriteLine(S.Gruppo)
W.WriteLine(S.Note)
W.WriteLine(S.UltimoAscolto)
W.WriteLine(S.Valutazione)
W.WriteLine(S.Album)
W.WriteLine(S.Compositore)
W.WriteLine(S.CopyRight)
W.WriteLine(S.Lingua)
W.WriteLine(S.Sottotitolo)
W.WriteLine(S.Traccia)
W.WriteLine(S.URL)
i += 1
frmSong.lblStatus.Text = "Salvataggio in corso: " & (i * 100 / MainDB.Count) & "%"
Next
W.Close()
W = Nothing
frmSong.lblStatus.Text = "Salvataggio completato"
End Sub
Public Shared Function QuickSearch(ByVal ToSeek As String, ByVal InWhichFind As String) As Int16
Dim S As String = ""
For i As Int16 = 0 To ToSeek.Length - 1
S = S & InWhichFind.Chars(i)
Next
For i As Int64 = ToSeek.Length To InWhichFind.Length - 1
If S = ToSeek Then
Return i
End If
S = S.Remove(0, 1)
S = S & InWhichFind.Chars(i)
Next
End Function
Public Shared Function MultimediaType(ByVal FileName As String) As MultimediaFile
Dim Ext As String = IO.Path.GetExtension(FileName)
If Ext = ".wav" Or Ext = ".mp3" Or Ext = ".wma" Then
Return MultimediaFile.AudioFile
Else
If Ext = ".wmv" Or Ext = ".mpg" Or Ext = ".avi" Then
Return MultimediaFile.VideoFile
Else
Return MultimediaFile.NoMultimediaFile
End If
End If
End Function
Public Sub SetFormat(ByVal Value As MultimediaFile)
CF = Value
If Value = MultimediaFile.AudioFile Then
lstInfo.Visible = True
imgVideo.Visible = False
End If
If Value = MultimediaFile.VideoFile Then
lstInfo.Visible = False
imgVideo.Visible = True
End If
End Sub
Public Sub CenterVideo(ByVal Size As Drawing.Size)
Dim W As UInt32 = Size.Width
Dim H As UInt32 = Size.Height
Dim IW As UInt32 = lstInfo.Size.Width
Dim IH As UInt32 = lstInfo.Size.Height
If Size = lstInfo.Size Then
Exit Sub
End If
If W * H < IW * IH Then
Dim X, Y As UInt32
X = lstInfo.Location.X + Math.Abs(IW - W) / 2
Y = lstInfo.Location.Y + Math.Abs(IH - H) / 2
imgVideo.Location = New Drawing.Point(X, Y)
Me.CenterToScreen()
Exit Sub
End If
If W * H > IW * IH Then
Me.Height += (H - IH)
Me.Width += (W - IW)
imgVideo.Location = lstInfo.Location
imgVideo.Size = MainF.DefaultSize
Me.CenterToScreen()
Exit Sub
End If
End Sub
Public Sub SetLastListen(ByVal Index As Int32)
Dim C As Song = MainDB(Index)
C.UltimoAscolto = Date.Now
MainDB(Index) = C
End Sub
Public Sub InitVideo(ByVal Index As Int32)
If MainDB(Index).Path.StartsWith("http://") Then
MainF = Video.FromUrl(New System.Uri(MainDB(Index).Path))
lblStatus.Text = "Streaming in corso: attendere..."
Else
MainF = New Video(MainDB(Index).Path)
End If
MainF.Owner = imgVideo
MainF.FullScreen = False
imgVideo.Visible = True
lstInfo.Visible = False
cmdAllScreen.Visible = True
Me.MaximizeBox = False
imgVideo.Location = lstInfo.Location
CenterVideo(MainF.DefaultSize)
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
lblPos.Location = New Drawing.Point(364, Me.Height - 122)
End Sub
Public Sub InitAudio(ByVal Index As Int32)
cmdAllScreen.Visible = False
lblPos.Location = New Drawing.Point(240, Me.Height - 122)
If MainDB(Index).Path.StartsWith("http://") Then
MainF = Audio.FromUrl(New System.Uri(MainDB(Index).Path))
Else
MainF = New Audio(MainDB(Index).Path)
End If
End Sub
Public Sub PlayTheFirstTime(ByVal Index As Int32)
If Not MainF Is Nothing Then
MainF.Stop()
End If
SetFormat(MultimediaType(MainDB(Index).Path))
SetLastListen(Index)
CurrentIndex = Index
lstSongs.SelectedIndex = Index
cmdAllScreen.Enabled = False
If CF = MultimediaFile.AudioFile Then
InitAudio(Index)
Else
InitVideo(Index)
End If
MainF.Play()
cmdStop.Enabled = True
tmrControl.Enabled = True
trkSound.Maximum = MainF.Duration
End Sub
Public Sub SetPlayingAll(ByVal Mode As Boolean, Optional ByVal Reverse As Boolean = False)
PlayingAll = Not (Mode Xor Reverse)
PlayingAllReverse = Reverse
strAdd.Enabled = Mode
strModify.Enabled = Mode
strRemove.Enabled = Mode
strMove.Enabled = Mode
strPlayNext.Enabled = Mode
strPlayBefore.Enabled = Mode
strPlayRandom.Enabled = Mode
tmrPlayAll.Enabled = Not Mode
End Sub
Public ReadOnly Property IsOldVersion() As Boolean
Get
Dim R As New IO.StreamReader(Application.StartupPath + "\Songs.dat")
Dim s As String = ""
For i As Int16 = 1 To 10
s = R.ReadLine
Next
If s = Nothing Then
Return False
End If
If s(0) = "@" Then
'Se l'ottava riga inzia per '@', significa che indica il nome di una canzone:
'perciò ci sono solo 7 campi per brano e quindi il file è scritto nella versione precedente
Return True
Else
Return False
End If
End Get
End Property
#End Region
#Region "Varabili, Costanti"
Public Enum MultimediaFile
AudioFile
VideoFile
NoMultimediaFile
End Enum
Public Const PBegin As Boolean = False
Public Const PStop As Boolean = True
Public CanSeek As Boolean = True
Public Shared CurrentIndex As Int32
Public Shared CurrentSound As SecondaryBuffer
Public Shared MainF As Object
Public Shared MainDB As New ArrayList
Public SearchResults As New ArrayList
Private CF As MultimediaFile
Private PlayingAll As Boolean = False
Private PlayingAllReverse As Boolean = False
#End Region
Private Sub frmSong_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim r As New IO.StreamReader(Application.StartupPath + "\Songs.dat")
Dim S As String
Dim C As Song = Nothing
Dim OldVersion As Boolean = IsOldVersion
lblStatus.Text = "Caricamento playlist in corso..."
If OldVersion Then
If MsgBox("Il file database è stato scritto con la precedente versione di Aqua Player e contiene meno" + _
"dati rispetto alla versione corrente. Se si continua la lettura, solo i dati immessi verranno " + _
"visualizzati e si potranno modificare le canzoni normalmente dopo l'accesso, aggiungendo nuovi dati. " + _
"Continuare?", MsgBoxStyle.Question + vbYesNo, "Aqua Player 1.1") = MsgBoxResult.No Then
Application.Exit()
End If
End If
While Not r.EndOfStream
S = r.ReadLine
If S(0) = "@" Then
C.Nome = S.Remove(0, 1)
C.Path = r.ReadLine
C.Anno = r.ReadLine
C.Artista = r.ReadLine
C.Genere = r.ReadLine
C.Gruppo = r.ReadLine
C.Note = r.ReadLine
Try
C.UltimoAscolto = r.ReadLine
Catch ICE As InvalidCastException
C.UltimoAscolto = Nothing
End Try
C.Valutazione = r.ReadLine
If Not OldVersion Then
C.Album = r.ReadLine
C.Compositore = r.ReadLine
C.CopyRight = r.ReadLine
C.Lingua = r.ReadLine
C.Sottotitolo = r.ReadLine
C.Traccia = r.ReadLine
C.URL = r.ReadLine
End If
MainDB.Add(C)
lstSongs.Items.Add(C.Nome)
End If
End While
lblStatus.Text = "Caricamento completato"
Catch FNFE As System.IO.FileNotFoundException
Dim w As New IO.StreamWriter("Songs.dat")
w.Close()
w = Nothing
End Try
End Sub
Private Sub lstSongs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSongs.SelectedIndexChanged
Try
If CanSeek Then
ResetLabel(MainDB(lstSongs.SelectedIndex))
End If
Catch IOORE As ArgumentOutOfRangeException
End Try
End Sub
Private Sub strAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileMultimedialeToolStripMenuItem.Click
If FOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim NS As New frmNewSong(FOpen.FileName, "ADD")
NS.ShowDialog()
End If
End Sub
Private Sub strModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strModify.Click
If lstSongs.SelectedIndex >= 0 Then
Dim NS As New frmNewSong(MainDB(lstSongs.SelectedIndex).Path, "MOD", lstSongs.SelectedIndex)
NS.ShowDialog()
Else
MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation)
End If
End Sub
Private Sub strRemoveNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strRemoveNormal.Click
If lstSongs.SelectedIndex >= 0 Then
If MsgBox("Rimuovere questo brano?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
CanSeek = False
MainDB.RemoveAt(lstSongs.SelectedIndex)
lstSongs.Items.RemoveAt(lstSongs.SelectedIndex)
CanSeek = True
End If
End If
End Sub
Private Sub strExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub strMoveDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDown.Click
If lstSongs.SelectedIndex < 0 Or lstSongs.SelectedIndex = lstSongs.Items.Count - 1 Then
MsgBox("Impossibile spostare elemento!", MsgBoxStyle.Exclamation)
Exit Sub
End If
CanSeek = False
Dim Temp As Song = MainDB.Item(lstSongs.SelectedIndex + 1)
Dim S As String = lstSongs.Items.Item(lstSongs.SelectedIndex + 1)
'Sposta elemento avanti
MainDB.Item(lstSongs.SelectedIndex + 1) = MainDB.Item(lstSongs.SelectedIndex)
'Porta l'elemento sostituito indietro
MainDB.Item(lstSongs.SelectedIndex) = Temp
lstSongs.Items.Item(lstSongs.SelectedIndex + 1) = lstSongs.Items.Item(lstSongs.SelectedIndex)
lstSongs.Items.Item(lstSongs.SelectedIndex) = S
lstSongs.SelectedIndex += 1
CanSeek = True
End Sub
Private Sub strMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strUp.Click
If lstSongs.SelectedIndex <= 0 Then
MsgBox("Impossibile spostare elemento!", MsgBoxStyle.Exclamation)
Exit Sub
End If
CanSeek = False
Dim Temp As Song = MainDB.Item(lstSongs.SelectedIndex - 1)
Dim S As String = lstSongs.Items.Item(lstSongs.SelectedIndex - 1)
'Sposta elemento avanti
MainDB.Item(lstSongs.SelectedIndex - 1) = MainDB.Item(lstSongs.SelectedIndex)
'Porta l'elemento sostituito indietro
MainDB.Item(lstSongs.SelectedIndex) = Temp
lstSongs.Items.Item(lstSongs.SelectedIndex - 1) = lstSongs.Items.Item(lstSongs.SelectedIndex)
lstSongs.Items.Item(lstSongs.SelectedIndex) = S
lstSongs.SelectedIndex -= 1
CanSeek = True
End Sub
Private Sub strSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSave.Click
Save()
End Sub
Private Sub frmSong_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Not MainF Is Nothing Then
MainF.Stop()
End If
If MsgBox("Salvare cambiamenti applicati?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
Save()
End If
End Sub
Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPLay.Click
If PlayingAll Or PlayingAllReverse Then
If Not MainF Is Nothing Then
If MainF.Paused Then
MainF.Play()
cmdPause.Enabled = True
Exit Sub
End If
End If
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
SetPlayingAll(PStop)
Else
Exit Sub
End If
End If
If lstSongs.SelectedIndex < 0 Then
MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation)
Exit Sub
End If
SetFormat(MultimediaType(MainDB(lstSongs.SelectedIndex).Path))
SetLastListen(lstSongs.SelectedIndex)
CurrentIndex = lstSongs.SelectedIndex
cmdAllScreen.Enabled = False
Try
If MainF.Paused Then
MainF.Play()
cmdStop.Enabled = True
cmdPause.Enabled = True
Else
If MainF.State = StateFlags.Running Then
MainF.Stop()
End If
If CF = MultimediaFile.AudioFile Then
InitAudio(lstSongs.SelectedIndex)
Else
InitVideo(lstSongs.SelectedIndex)
End If
MainF.Play()
cmdStop.Enabled = True
trkSound.Maximum = MainF.Duration
End If
tmrControl.Enabled = True
Catch NRE As NullReferenceException
If CF = MultimediaFile.AudioFile Then
InitAudio(lstSongs.SelectedIndex)
Else
InitVideo(lstSongs.SelectedIndex)
End If
MainF.Play()
cmdStop.Enabled = True
cmdPause.Enabled = True
tmrControl.Enabled = True
trkSound.Maximum = MainF.Duration
End Try
End Sub
Private Sub cmdStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdStop.Click
If PlayingAll Or PlayingAllreverse Then
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
SetPlayingAll(PStop)
Else
Exit Sub
End If
End If
MainF.Stop()
trkSound.Value = 0
MainF.CurrentPosition = 0
MainF = Nothing
cmdStop.Enabled = False
cmdPause.Enabled = False
tmrControl.Enabled = False
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
Me.MaximizeBox = True
cmdAllScreen.Enabled = True
lblStatus.Text = "Riproduzione interrotta"
End Sub
Private Sub tmrControl_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrControl.Tick
Dim TimeElapsed, TimeTotal As TimeSpan
TimeElapsed = TimeSpan.FromSeconds(CInt(MainF.CurrentPosition))
TimeTotal = TimeSpan.FromSeconds(CInt(MainF.Duration))
trkSound.Value = MainF.CurrentPosition
lblPos.Text = TimeElapsed.ToString & " secondi riprodotti su " & TimeTotal.ToString
lblStatus.Text = "Riproduzione in corso"
If TypeOf MainF Is Video Then
lblStatus.Text = lblStatus.Text + ": circa " & CInt(1 / MainF.AverageTimePerFrame) & " frame al secondo"
End If
End Sub
Private Sub trkSound_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trkSound.Scroll
If tmrControl.Enabled Then
MainF.CurrentPosition = trkSound.Value
End If
End Sub
Private Sub strSeekInPlaylist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSeek.Click
Dim ToSeek As String = InputBox("Nome o parte del nome della canzone da cercare:", "Cerca nella playlist")
Dim S As String
If lstSongs.SelectedIndex < 0 Then
lstSongs.SelectedIndex = 0
End If
For I As Int32 = lstSongs.SelectedIndex To MainDB.Count - 1
S = lstSongs.Items(I)
If S.Contains(ToSeek) Then
lstSongs.SelectedIndex = I
Exit For
End If
Next
End Sub
Private Sub strSeekInComputer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CercaNelComputerToolStripMenuItem.Click
Dim S As New frmSeek
S.ShowDialog()
End Sub
Private Sub strRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strRemoveAll.Click
If MsgBox("Rimuovere veramente tutti i brani?", MsgBoxStyle.Question + vbYesNo) = MsgBoxResult.Yes Then
lstSongs.Items.Clear()
MainDB.Clear()
End If
End Sub
Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
MainF.Pause()
cmdPause.Enabled = False
tmrControl.Enabled = False
lblStatus.Text = "In pausa"
End Sub
Private Sub strRemoveChecked_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strRemoveChecked.Click
If MsgBox("Procedere con la cancellazione degli elementi spuntati?", MsgBoxStyle.Question + vbYesNo, "Conferma") = MsgBoxResult.No Then
Exit Sub
End If
Dim ToDel As New ArrayList
Dim S As Song
Dim A As Int16
For Each A In lstSongs.CheckedIndices
ToDel.Add(MainDB(A))
Next
For Each S In ToDel
lstSongs.Items.Remove(S.Nome)
MainDB.Remove(S)
Next
End Sub
Private Sub cmdAllScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAllScreen.Click
cmdPlay_Click(Me, New System.EventArgs)
MainF.FullScreen = True
End Sub
Private Sub strSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearch.Click
If lstSongs.SelectedIndex < 0 Then
lstSongs.SelectedIndex = 0
End If
If lstSongs.SelectedIndex > 0 And lstSongs.SelectedIndex < lstSongs.Items.Count - 1 Then
lstSongs.SelectedIndex += 1
End If
If strSearchMode.SelectedIndex < 0 Then
MsgBox("Nessuna modalità di ricerca selezionata!", MsgBoxStyle.Exclamation)
Exit Sub
End If
If strSearchKey.Text = "" Then
MsgBox("Nessuna chiave di ricerca inserita!", MsgBoxStyle.Exclamation)
Exit Sub
End If
lblStatus.Text = "Ricerca in corso..."
prgSearch.Visible = True
prgSearch.Maximum = lstSongs.Items.Count
prgSearch.Width = Me.Width - lblStatus.Size.Width - 20
SearchResults.Clear()
Select Case strSearchMode.SelectedIndex
Case 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12
Dim Key As String = strSearchKey.Text
Dim S As String = ""
For I As Int32 = lstSongs.SelectedIndex To MainDB.Count - 1
Select Case strSearchMode.SelectedIndex
Case 0
S = MainDB(I).Nome
Case 1
S = MainDB(I).Artista
Case 2
S = MainDB(I).Genere
Case 3
S = MainDB(I).Gruppo
Case 4
S = MainDB(I).Anno
Case 6
S = MainDB(I).Note
Case 7
S = MainDB(I).Album
Case 8
S = MainDB(I).Compositore
Case 9
S = MainDB(I).CopyRight
Case 10
S = MainDB(I).URL
Case 11
S = MainDB(I).Sottotitolo
Case 12
S = MainDB(I).Lingua
End Select
If S.Contains(Key) Then
strSearchResult.Items.Add(lstSongs.Items(I))
SearchResults.Add(I)
End If
prgSearch.Value += 1
Next
Case Else
Dim Key As Int32 = strSearchKey.Text
Dim S As Int32
For I As Int32 = lstSongs.SelectedIndex To MainDB.Count - 1
Select Case strSearchMode.SelectedIndex
Case 5
S = MainDB(I).Valutazione
Case 13
S = MainDB(I).Traccia
End Select
If S = Key Then
strSearchResult.Items.Add(lstSongs.Items(I))
SearchResults.Add(I)
End If
Next
prgSearch.Value += 1
End Select
lblStatus.Text = "Ricerca terminata"
strSearchResult.Visible = True
strSep.Visible = True
strlblSearch.Visible = True
prgSearch.Value = 0
prgSearch.Visible = False
strSearchResult.Items.Add("Nascondi risultati")
End Sub
Private Sub strSearchKey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearchKey.Click
If strSearchKey.Text = "[Chiave di ricerca]" Then
strSearchKey.Text = Nothing
End If
End Sub
Private Sub strSearchResult_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearchResult.SelectedIndexChanged
If strSearchResult.SelectedIndex >= 0 Then
If strSearchResult.SelectedIndex = strSearchResult.Items.Count - 1 Then
strSearchResult.Visible = False
strSep.Visible = False
strlblSearch.Visible = False
Exit Sub
End If
lstSongs.SelectedIndex = SearchResults(strSearchResult.SelectedIndex)
End If
End Sub
Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
Dim A As New frmAbout
A.ShowDialog()
End Sub
Private Sub RiproduciSuccessivoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPlayNext.Click
If CurrentIndex < lstSongs.Items.Count - 1 Then
If Not MainF Is Nothing Then
MainF.Stop()
End If
CurrentIndex += 1
lstSongs.SelectedIndex = CurrentIndex
SetFormat(MultimediaType(MainDB(lstSongs.SelectedIndex).Path))
SetLastListen(lstSongs.SelectedIndex)
CurrentIndex = lstSongs.SelectedIndex
cmdAllScreen.Enabled = False
If CF = MultimediaFile.AudioFile Then
InitAudio(lstSongs.SelectedIndex)
Else
InitVideo(lstSongs.SelectedIndex)
End If
MainF.Play()
cmdStop.Enabled = True
tmrControl.Enabled = True
trkSound.Maximum = MainF.Duration
End If
End Sub
Private Sub RiproduciPrecedenteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPlayBefore.Click
If CurrentIndex > 0 Then
If Not MainF Is Nothing Then
MainF.Stop()
End If
CurrentIndex -= 1
lstSongs.SelectedIndex = CurrentIndex
SetFormat(MultimediaType(MainDB(lstSongs.SelectedIndex).Path))
SetLastListen(lstSongs.SelectedIndex)
CurrentIndex = lstSongs.SelectedIndex
cmdAllScreen.Enabled = False
If CF = MultimediaFile.AudioFile Then
InitAudio(lstSongs.SelectedIndex)
Else
InitVideo(lstSongs.SelectedIndex)
End If
MainF.Play()
cmdStop.Enabled = True
tmrControl.Enabled = True
trkSound.Maximum = MainF.Duration
End If
End Sub
Private Sub RiproduciTuttoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RiproduciTuttoToolStripMenuItem.Click
SetPlayingAll(PBegin)
PlayTheFirstTime(0)
lblStatus.Text = "Riproduzione di tutti i brani"
End Sub
Private Sub tmrPlayAll_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPlayAll.Tick
If MainF.CurrentPosition = MainF.Duration Then
If PlayingAll Then
If CurrentIndex = lstSongs.Items.Count - 1 Then
lblStatus.Text = "Riproduzione terminata"
tmrPlayAll.Enabled = False
PlayingAll = False
Exit Sub
End If
PlayTheFirstTime(CurrentIndex + 1)
End If
If PlayingAllreverse Then
If CurrentIndex = 0 Then
lblStatus.Text = "Riproduzione terminata"
tmrPlayAll.Enabled = False
PlayingAllreverse = False
Exit Sub
End If
PlayTheFirstTime(CurrentIndex - 1)
End If
End If
End Sub
Private Sub InOrdineInversoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InOrdineInversoToolStripMenuItem.Click
SetPlayingAll(PBegin, True)
PlayTheFirstTime(lstSongs.Items.Count - 1)
lblStatus.Text = "Riproduzione di tutti i brani in ordine inverso"
End Sub
Private Sub strPlayRandom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strPlayRandom.Click
Randomize()
Dim R As New Random()
PlayTheFirstTime(R.Next(lstSongs.Items.Count - 1))
End Sub
Private Sub frmSong_ResizeBegin(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ResizeBegin
imgVideo.Visible = False
lstInfo.Visible = True
End Sub
Private Sub ControlloVolumeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ControlloVolumeToolStripMenuItem.Click
Try
Shell("C:\WINDOWS\System32\sndvol32.exe", AppWinStyle.NormalFocus)
Catch FNFE As IO.FileNotFoundException
MsgBox("Probabilmente non si sta lavorando su un sistema operativo Windows o non si dispone del controllo volume di sistema!", MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub strAddWeb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAddWeb.Click
Dim URL As String = InputBox("Incollare qui l'indirizzo:", "Acquisisci file dal web")
Dim A As New frmNewSong(URL, "ADD")
A.ShowDialog()
End Sub
Private Sub strSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSort.Click
Dim List As New ArrayList
lblStatus.Text = "Attendere, ordinamento in corso..."
'Scrive nell'array il nome di tutte le canzoni nell'ordine corrente
For i As Int32 = 0 To lstSongs.Items.Count - 1
List.Add(lstSongs.Items(i))
Next
'Ordina la lista
lstSongs.Sorted = True
'Controlla ogni elemento dell'arraylist, ne preleva il nome, cerca il nome
'nella lista ordinata e colloca al posto del nome nell'arraylist l'indice corrispondente
'nella lista ordinata
Dim S As String = ""
Dim Index As Int32
For i As Int32 = 0 To lstSongs.Items.Count - 1
S = List(i)
Index = lstSongs.Items.IndexOf(S)
List(i) = Index
Next
'Riordina MainDB associando ogni elemento dell'arraylist a un'altra
'arraylist di backup
Dim Backup As New ArrayList
Dim Counter As Int32 = 0
'Crea List.Count elementi in Backup
For i As Int32 = 0 To List.Count - 1
Backup.Add(Nothing)
Next
'Associa all'elemento List(i) di Backup l'elemento i di MainDB: in pratica, ad ogni iterazione
'aggiunge elementi successivi di MainDB in celle di memoria diverse di Backup, descritte dalla
'lista ordinata di indici List
For Each Index In List
Backup(Index) = MainDB(Counter)
Counter += 1
Next
MainDB = Backup
lblStatus.Text = "Ordinamento completato"
End Sub
End Class