[RESOLVED] problem with music playlist
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: [RESOLVED] problem with music playlist

  1. #1
    Join Date
    Mar 2011
    Posts
    153

    [RESOLVED] problem with music playlist

    Here is the relevant code.

    Code:
        Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLAdd.Click
            OpenFileDialog2.ShowDialog()
            Playlist.Items.Add(OpenFileDialog2.FileName)
        End Sub
    
        Private Sub Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLRemove.Click
            Playlist.Items.Remove(Playlist.SelectedItem)
        End Sub
    
        Private Sub PLSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLSave.Click
            IO.Directory.CreateDirectory("C:\Selector\Playlists")
            Dim w As New IO.StreamWriter("C:\Selector\Playlists\test.txt")
            Dim i As Integer
            For i = 0 To Playlist.Items.Count - 1
                w.WriteLine(Playlist.Items.Item(i))
            Next
            w.Close()
        End Sub
    
        Private Sub PLLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLLoad.Click
            Dim r As New IO.StreamReader("C:\Selector\Playlists\test.txt")
            While (r.Peek() > -1)
                Playlist.Items.Add(r.ReadLine)
            End While
            r.Close()
        End Sub
    
        Private Sub PLPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLPlay.Click
            Process.Start(Playlist.SelectedItem)
        End Sub
    I want to allow the user to name their own file for the playlist instead of it being "test.txt".

    I want a way to avoid duplicate song files.

    I want a way to shorten the file name to exclude the file path. (I'll probably have that figured out on my own)

    I want to overwrite one playlist with a loaded one.

    Finally, How can I make this symbol, ►, in vb.net? (for my play button)
    Last edited by 957; March 22nd, 2011 at 07:50 AM. Reason: grammar

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: problem with music playlist

    You could put an IF STATEMENT inside here, to pop up a message box for each song. Better idea would be to let user save a DIFFERENT name, and keep the filename separate for future use.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: problem with music playlist

    Look at SaveFileDialog. The user can also create directories if needed.

    OpenFileDialog.SafeFileName is the file name without the path. I would do what dglienna said and save both.

    Dupes? that's up to you. Probably check after the user selects a new file.

    Check out SaveFileDialog.OverwritePrompt

  4. #4
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    Do I have to import anything to use overwriteprompt?

    My code has changed so that there is no longer a file saved to the computer.

    Code:
    Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLAdd.Click
            OpenFileDialog2.ShowDialog()
            Playlist.Items.Add(OpenFileDialog2.FileName)
        End Sub
    
        Private Sub Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLRemove.Click
            Playlist.Items.Remove(Playlist.SelectedItem)
        End Sub
    
        Private Sub PLSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLSave.Click
            Playlists.Items.Add(Playlist.Items)
        End Sub
    
        Private Sub PLLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLLoad.Click
            Playlist.Items.Add(Playlists.Items)
        End Sub
    
        Private Sub PLPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLPlay.Click
            If OpenFileDialog2.FileName = "" Then
                Exit Sub
            Else
                Process.Start(Playlist.SelectedItem)
            End If
        End Sub
    When I use this code to save a playlist to the second listbox as a single item that can be loaded as the original multiple items to the first listbox, all I get in the second listbox is the word, "(Collection)". Also, from this approach how could I allow the user to name their own playlist?

  5. #5
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: problem with music playlist

    How is the user going to "save" their playlist if you don't write it to a file? If there not saving it to a file why would they have to name it? If you use SaveFileDialog it will allow the user to name the file. You will probably want to dictate the extension (like ".PL")

  6. #6
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    how do I dictate an extension?

  7. #7
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    nvmd that last one

  8. #8
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    They have to name it if they want multiple playlists and be able to identify the contents of each one by it's name.

  9. #9
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    the main problem is transferring multiple items from one listbox to the other as only one item under a user-designated title like, "Avenged Sevenfold Songs"

  10. #10
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    ok nvmd I solved all of that and I will post the code after someone tells me how to put this character onto a button, "►"

  11. #11
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: problem with music playlist

    Found this by searching:

    Code:
     If isPlay = True Then
            If isPaused = False Then
                btnPlay.Image = Image.FromFile("iconPause.png")
                isPaused = True
                isPlay = False
            End If
            GoTo Endline
        End If
    
        If isPlay = False Then
            If isPaused = True Then
    
                btnPlay.Image = Image.FromFile("iconPlay.png")
                isPaused = False
                isPlay = True
            End If
        End If
    http://stackoverflow.com/questions/1...d-pause-button
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    is there anyway to get it without and icon and only text?

  13. #13
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: problem with music playlist

    Set the text to ""
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  14. #14
    Join Date
    Mar 2011
    Posts
    153

    Re: problem with music playlist

    ok here is what I did

    Code:
    Private Sub PLMusicSN_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLMusicSN.SelectedIndexChanged
            PLMusicFP.SelectedIndex = PLMusicSN.SelectedIndex
        End Sub
    
        Private Sub PLMAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLMAdd.Click
            OpenFileDialog2.ShowDialog()
            PLMusicFP.Items.Add(OpenFileDialog2.FileName)
            PLMusicSN.Items.Add(OpenFileDialog2.SafeFileName)
        End Sub
    
        Private Sub PLMRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLMRemove.Click
            PLMusicFP.Items.Remove(PLMusicFP.SelectedItem)
            PLMusicSN.Items.Remove(PLMusicSN.SelectedItem)
        End Sub
    
        Private Sub PLMSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLMSave.Click
            IO.Directory.CreateDirectory("C:\Selector\Playlists")
            Dim wFP As New IO.StreamWriter("C:\Selector\Playlists\MusicFP.pl")
            Dim i As Integer
            For i = 0 To PLMusicFP.Items.Count - 1
                wFP.WriteLine(PLMusicFP.Items.Item(i))
            Next
    
            Dim wSN As New IO.StreamWriter("C:\Selector\Playlists\MusicSN.pl")
            For i = 0 To PLMusicSN.Items.Count - 1
                wSN.WriteLine(PLMusicSN.Items.Item(i))
            Next
            wFP.Close()
            wSN.Close()
            My.Settings.PLMDir = Me.PLMDirL.Text
            My.Settings.Save()
        End Sub
    
        Private Sub PLMPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLMPlay.Click
            PLMusicSN.SelectedItem = PLMusicFP.SelectedItem
            If OpenFileDialog2.FileName = "" Then
                Exit Sub
            Else
                Process.Start(PLMusicFP.SelectedItem)
            End If
        End Sub
    
        Private Sub PLVideoSN_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLMusicSN.SelectedIndexChanged
            PLVideoFP.SelectedIndex = PLVideoSN.SelectedIndex
        End Sub
    
        Private Sub PLVAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLVAdd.Click
            OpenFileDialog2.ShowDialog()
            PLVideoFP.Items.Add(OpenFileDialog2.FileName)
            PLVideoSN.Items.Add(OpenFileDialog2.SafeFileName)
        End Sub
    
        Private Sub PLVRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLVRemove.Click
            PLVideoFP.Items.Remove(PLVideoFP.SelectedItem)
            PLVideoSN.Items.Remove(PLVideoSN.SelectedItem)
        End Sub
    
        Private Sub PLVSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLVSave.Click
            IO.Directory.CreateDirectory("C:\Selector\Playlists")
            Dim wFP As New IO.StreamWriter("C:\Selector\Playlists\VideoFP.pl")
            Dim i As Integer
            For i = 0 To PLVideoFP.Items.Count - 1
                wFP.WriteLine(PLVideoFP.Items.Item(i))
            Next
    
            Dim wSN As New IO.StreamWriter("C:\Selector\Playlists\VideoSN.pl")
            For i = 0 To PLVideoSN.Items.Count - 1
                wSN.WriteLine(PLVideoSN.Items.Item(i))
            Next
            wFP.Close()
            wSN.Close()
            My.Settings.PLVDir = Me.PLVDirL.Text
            My.Settings.Save()
        End Sub
    
        Private Sub PLVPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLVPlay.Click
            PLVideoSN.SelectedItem = PLVideoFP.SelectedItem
            If OpenFileDialog2.FileName = "" Then
                Exit Sub
            Else
                Process.Start(PLVideoFP.SelectedItem)
            End If
        End Sub
    and in forms load

    Code:
    Me.PLMDirL.Text = My.Settings.PLMDir
            Me.PLVDirL.Text = My.Settings.PLVDir
    
            If PLMDirL.Text = "0" Then
                IO.Directory.CreateDirectory("C:\Selector\Playlists\")
                System.IO.File.Create("c:\Selector\Playlists\MusicFP.pl")
                System.IO.File.Create("c:\Selector\Playlists\MusicSN.pl")
                PLMDirL.Text = 1
            Else
                Dim rMFP As New IO.StreamReader("C:\Selector\Playlists\MusicFP.pl")
                While (rMFP.Peek() > -1)
                    PLMusicFP.Items.Add(rMFP.ReadLine)
                End While
                rMFP.Close()
                Dim rMSN As New IO.StreamReader("C:\Selector\Playlists\MusicSN.pl")
                While (rMSN.Peek() > -1)
                    PLMusicSN.Items.Add(rMSN.ReadLine)
                End While
                rMSN.Close()
    
                Dim rVFP As New IO.StreamReader("C:\Selector\Playlists\VideoFP.pl")
                While (rVFP.Peek() > -1)
                    PLVideoFP.Items.Add(rVFP.ReadLine)
                End While
                rVFP.Close()
                Dim rVSN As New IO.StreamReader("C:\Selector\Playlists\VideoSN.pl")
                While (rVSN.Peek() > -1)
                    PLVideoSN.Items.Add(rVSN.ReadLine)
                End While
                rVSN.Close()
            End If
    
            If PLVDirL.Text = "0" Then
                IO.Directory.CreateDirectory("C:\Selector\Playlists\")
                System.IO.File.Create("c:\Selector\Playlists\VideoFP.pl")
                System.IO.File.Create("c:\Selector\Playlists\VideoSN.pl")
                PLVDirL.Text = 1
            Else
                Dim rVFP As New IO.StreamReader("C:\Selector\Playlists\VideoFP.pl")
                While (rVFP.Peek() > -1)
                    PLVideoFP.Items.Add(rVFP.ReadLine)
                End While
                rVFP.Close()
                Dim rVSN As New IO.StreamReader("C:\Selector\Playlists\VideoSN.pl")
                While (rVSN.Peek() > -1)
                    PLVideoSN.Items.Add(rVSN.ReadLine)
                End While
                rVSN.Close()
            End If

  15. #15
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: [RESOLVED] problem with music playlist

    Should have used SELECT CASE for peek, to save 90% of the code
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center