Jump to content

[VB.NET] Filebox para listbox


Tiago_22
 Share

Recommended Posts

Boas!

Eu estou a tentar fazer um reprodutor de mp3, mas estou a ter algumas dificuldades...

O meu form tem 2 botoes, uma drivebox, uma dirbox, uma filebox, uma listbox e o reprodutor do win media player.

eu ja consegui reproduzir musica, mas é so uma... ao inicio  😄

pus es te codigo pa reproduzir musa ao inicio:

Private Sub Form_Load()
   WindowsMediaPlayer1.URL = "C:\Documents and Settings\Tiago\Os meus documentos\A minha música\02-Jonh Cena - Right now.mp3"
End Sub

mas agr estou com problemas em adicionar as musicas na filebox para um listbox para depois reproduzir  🙂

e tou a tentar com este codigo no botao adicionar

Private Sub Add_Click()
selectedfile = File1.Path & "\" & File1.FileName
lista.AddItem = File1.FileName
End Sub

e com este no botao adicionar todas

Private Sub AddAll_Click()
Dim i As Integer
    For i = 0 To File1.ListCount - 1
        lista.AddItem Dir1.Path & "\" & File1.List(i), File1.List(i)
    Next
    lista.AddItem = File1.ListCount
End Sub

Se alguem me poder ajudar, agradeço  😉

cumps  😉

Link to comment
Share on other sites

Bem, o que interessa para o teu caso é só isto:

Private Sub Timer18_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer18.Tick
        If MediaPlayer1.FileName = TextBox15.Text Then
            If (MediaPlayer1.Duration - MediaPlayer1.CurrentPosition) = 0 Then
                MediaPlayer1.Stop()
                MediaPlayer1.FileName = TextBox16.Text
                If TextBox16.Text = "" Then
                    MediaPlayer1.Stop()
                Else
                    Try
                        MediaPlayer1.Play()
                    Catch exception As Exception
                        MessageBox.Show("Erro." & vbLf & "O ficheiro seleccionado poderá estar danificado," & vbLf & _
                        "experimente abri-lo com outro porgrama de reprodução.", "mp DiskJockey", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                    Timer18.Enabled = False
                    Timer19.Enabled = True
                End If
            End If
        End If
    End Sub

Que é o que permite abrir a entrada da listbox seguinte, isso tem de estar no timer, e é só mudar onde diz textbox 😉

Link to comment
Share on other sites

Boas!!

Olha uma maneira simples:

poes no form isto

DirListBox

FileListBox

ListBox

MediaPlayer

Botao

E fazes este codigo

Private Sub botao_Click()
wmp.FileName = (List1)
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1
End Sub

Private Sub File1_Click()
List1.AddItem (Dir1 & "\" & File1)
End Sub

Private Sub Form_Load()
Dir1.Path = "C:"
File1.Pattern = "*.mp3"
End Sub

ao carregares no botao toca a musica selecionada na list1

Link to comment
Share on other sites

vbmaster eu dps tambem faço um com o commondialog, pa ver o k rulla mais 🙂

M@KO no teu código as musicas k keremos vao para um listbox e depois a musica da listbox k estiver selecionada toca, mas quando essa musica acaba n devia começar a tocar a musica abaixo dessa na listbox?

alguem me pode ajudar no code para ir reproduzindo as musicas abaixo da musica selecionada  k acabou...

cumps  🙂

Link to comment
Share on other sites

oi! desculpa la a demora mas nao conegui por a reproduzir ao sons seguidos directamente da list1 por isso fiz um array onde gravo as musicas ke kero ouvir

e a list1 serve so pra ver o ke esta a tocar, tas a ver o filme????

com o mesmo form mete este codigo

Dim x, y As Integer
Dim lista(99) As String

Private Sub Command1_Click()
wmp.FileName = (lista(y))
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1
End Sub

Private Sub File1_Click()
If x < 100 Then
    List1.AddItem (Dir1 & "\" & File1)
    lista(x) = (Dir1 & "\" & File1)
    x = x + 1
Else
    MsgBox ("Entao, 99 musicas nao te chega???")
End If
End Sub

Private Sub Form_Load()
x = 0
y = 0
Dir1.Path = "C:\"
File1.Pattern = "*.mp3"
End Sub

Private Sub wmp_EndOfStream(ByVal Result As Long)
    y = y + 1
    wmp.FileName = (lista(y))
End Sub

Esta soluçao do array tireia dakele exemplo que o d_pintassilgo aqui tem ke tu na conseguiste ver o codigo.

Link to comment
Share on other sites

Boas noticias  😁 já descobri como ponho a tocar as musicas seguidas diretamente da list1

o codigo fica muito mais simples 😁

novamente com o mesmo form poe este codigo

Dim x As Integer

Private Sub Command1_Click()
wmp.FileName = (List1.List(x))
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1
End Sub

Private Sub File1_Click()
    List1.AddItem (Dir1 & "\" & File1)
End Sub

Private Sub Form_Load()
x = 0
Dir1.Path = "C:\"
File1.Pattern = "*.mp3"
End Sub

Private Sub wmp_EndOfStream(ByVal Result As Long)
    x = x + 1
    wmp.FileName = (List1.List(x))
End Sub

🙂

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.