Quantcast
Channel: Visual Basic Tips and Tricks
Viewing all articles
Browse latest Browse all 2212

Riprpodurre MP3 con WMP ridotto a icona

$
0
0
Con il codice seguentelancio la riproduzione di un MP3 a caso con Windows Media Player. Ma vorrei che la finestra di WMP rimanesse minimizzata (ridotta a icona), ma nonostante l'istruzione apposita (windowstyle) , cio non avviene e appare la finestra di windows media player. Qualcuno sa perche o dove sbaglio?

Private Sub RiproduciMP3()

        Dim Canzoni As List(Of String) = New List(Of String)
        For Each foundFile As String In My.Computer.FileSystem.GetFiles(
            Application.StartupPath & "\Musica", FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
            Canzoni.Add(foundFile)
        Next
'
        Dim r As New Random
        Dim max As Integer
        max = Canzoni.Count
        Dim numcas As Integer = r.Next(0, max)
        Dim Canzone As String = """"& Canzoni.Item(numcas).ToString & """"

        Dim a As Boolean = RunCommand("C:\Programmi\Windows Media Player\wmplayer.exe", Canzone, 0)

 End Sub

    Private Function RunCommand(ByVal szCmd As String, ByVal szArgs As String, ByVal wait As Integer) As Boolean

        If szCmd Is Nothing Then
            Return False
        End If
        Dim myproc As New System.Diagnostics.Process()

        myproc.EnableRaisingEvents = False
        myproc.StartInfo.FileName = szCmd
        myproc.StartInfo.Arguments = szArgs
        myproc.StartInfo.UseShellExecute = False
        myproc.StartInfo.CreateNoWindow = True
      
 myproc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized

        If myproc.Start() Then

            'Uso di WaitForExit permette

            'di aspettare l'esecuzione del comando prima di continuare
            If wait = 1 Then
                myproc.WaitForExit()
            Else
                myproc.Close()
                myproc.Dispose()
            End If

            myproc.Close()
            myproc.Dispose()

            Return True

        Else

            MessageBox.Show("ERRORE")
            Return False
        End If

    End Function

Viewing all articles
Browse latest Browse all 2212