1.

Solve : Visual basic 2008 Media Player?

Answer»

Hi there,

Hope someone can help me here.  I'm trying to build my own media player.  I've managed this, however there are some bugs I need to fix.  I'm not quite sure how to do this though. 

I can open a dialogue box which will select multiple files, however it won't insert the multiple files in to the list box.  It will only open the first one selected and insert that one.

Second, Once I have files in my list box I'm unable to delete these from the list box.

I have the binding source filter set to "All Files|*.*"

I've attached a pic of what the design looks like and the code I'm using is as below :

Public Class frmMusicPlayer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        OpenFileDialog1.ShowDialog()

    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

        BindingSource1.Add(OpenFileDialog1.FileName)

    End Sub

    Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click

        Try

            WinPlayer1.URL = ListBox1.SelectedItem.ToString

        Catch ex As Exception

        End Try


    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub

    Private Sub BindingSource1_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingSource1.CurrentChanged

    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click

        End

    End Sub

    Private Sub ImportToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportToolStripMenuItem.Click

        OpenFileDialog1.ShowDialog()

    End Sub

    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click

        Application.Exit()


    End Sub
End Class


Many thanks to all who can help on this one!!

B2





[recovering disk SPACE - old attachment deleted by admin]you should use OpenFileDialog.FileNames instead of .FileName when allowing the selection of multiple files.


Personally what I do when using the OpenFileDialog is, since it's Modal, have it in it's own method- that is ,encapsulate all the necessary logic in one place. In your case, it would be the ImportToolStripMenuItem_Click() event.

The way you have it now, you are simply responding to the OK event, and effectually "separating" the actual click event from what actually happens. What you could do is something like this (untested):
Code: [Select]Private Sub ImportToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportToolStripMenuItem.Click
        Dim iterateValue as String
        Dim ofd as OpenFileDialog= new OpenFileDialog()
        ofd.Filter="All Files|*.*"
        ofd.MultiSelect=True
        If ofd.ShowDialog=DialogResult.OK Then
           For Each iterateValue in ofd.FileNames
               'ListBox1.Items.Add(iterateValue)
               BindingSource1.Add(iteratevalue)
           
           Next

        End If
End Sub

That's g enerally the way I use the OpenFileDialog- as an object, rather then as a control. (probably because using the control feels far too much like a throwback to Visual Basic 2 ). Set the properties right then and there, show the dialog, and then test if they pressed OK with the return value and proceed ACCORDINGLY by adding the selected files to the bindingsource (or the listbox, which I have commented out).

hey mate,

how about you post your entire source code so that i can give u a better hand on this project cause i am also sick of all the dodgy media players out there.Hey BC,

Thanks for the help, I've not had TIME to try it.  I'll have a test at it tonight though.  Sorry for the late reply, I've just been really busy.

I'll LET you know how I get on!

Hey Muso... That was the full source code.

B2  Hi,
You can create a WPF user control and place it in a .aspx form and Also if you use WPF XML for the user interface, and using aspx to handle back-end get what you need to switch to it from the aspx  WinForm.If you found this help, do not be afraid to add to my agent. There are only 10 types of people in this world. Those who understand binary.Hi there,

Thanks again BC!!!  It worked, thank you so much.  However I'm not able to remove any items from the listbox.  Any ideas...

Thank you to all others who replied too!


B2 Quote from: Base2 on April 20, 2011, 08:07:01 PM


Thanks again BC!!!  It worked, thank you so much.  However I'm not able to remove any items from the listbox.  Any ideas...


if you are using the BindingSource, remove the items from the BindingSource. Quote from: BC_Programmer on April 20, 2011, 09:45:31 PM
if you are using the BindingSource, remove the items from the BindingSource.

How do i do this??  On the list box in design view when I select the ListBox I can click the arrow to bring up the ListBox tasks.  I then click on the CheckBox to use data bound items, then under Data Binding Mode I have the Data Source set in the drop down box as BindingSource1.  So I'm not actually sure how to remove the items from the actual BindingSource itself.
Quote from: Base2 on April 21, 2011, 03:55:45 AM
How do i do this??  On the list box in design view when I select the ListBox I can click the arrow to bring up the ListBox tasks.  I then click on the CheckBox to use data bound items, then under Data Binding Mode I have the Data Source set in the drop down box as BindingSource1.  So I'm not actually sure how to remove the items from the actual BindingSource itself.

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.remove%28v=VS.90%29.aspx


Discussion

No Comment Found