CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    Mar 2012
    Posts
    99

    serialization question

    I am making a media player using a windows form application project in mircosoft visual studio. So far I am able to display songs in a listbox,play, pause etc and now I want to be able to make playlists for the songs. I have two forms - one with buttons to play, pause stop all the songs, and display the songs and the second is for making the playlists. In the playlist form there is two listboxs - one with a list of the songs in the playlist and the second for the songs you add to the playlist. theres is also an add button and remove button and a textbox to put the name of the playlist in. And finally a create button. So I need a bit of help creating the playlist. heres the code I have so far for the create button:
    Code:
    private void button1_Click(object sender, EventArgs e) //create playlist
            {
                Playlist temp = new Playlist(textBoxPlaylist.Text); 
                foreach(string name in PlaylistTracks.Items)
                {
                    temp.addSong(name);
               
                }
    
            }
    so far nothing happens when I click the button. I need the playlist to save the songs in the listbox and the name in the textbox. I also have a listbox in the first form that I want to populate with the names of the playlists that have been created. Not sure what code to use to do that.
    Hope I explained all this enough
    Last edited by beginner91; March 24th, 2012 at 02:52 PM.

  2. #2
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    i have attached a screen shot of the playlist form. Hope it helps explain my problem
    Attached Files Attached Files

  3. #3
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    Quote Originally Posted by beginner91 View Post
    i have attached a screen shot of the playlist form. Hope it helps explain my problem
    It is better to submit image files as jpegs or gifs, as not everyone can read docX files. For the benefit of those of us who either don't have an up-to-date Word, or don't know that docX files are effectively zip files , here is the relevant image:
    Attached Images Attached Images  

  4. #4
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: serialization question

    or don't know that docX files are effectively zip file
    ...?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    Quote Originally Posted by BioPhysEngr View Post
    ...?
    It's true - change the extension to .zip and you can open it using unzip or some such application. That's how I extracted the image.

  6. #6
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: serialization question

    Good to know. Thanks!
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #7
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    now that the image is sorted can someone help with my problem?

  8. #8
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    Re: serialization question

    As far as I know there's no VS standard library containing Playlist. Mind givings us what you do in your add() method ?

  9. #9
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    ok here is all the code for you get a better idea of what i'm trying to do
    Code:
    namespace Playing_MP3_songs
    {
        public partial class CreatePlaylistForm : Form
        {
            [DllImport("winmm.dll")]
            private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
            bool paused = false;
            ArrayList myPlaylistsCollection = new ArrayList();
    
            public CreatePlaylistForm()
            {
                InitializeComponent();
                // DirectoryInfo dinfo = new DirectoryInfo(@"C:\Users\Public\Music\Sample Music");
                DirectoryInfo dinfo = new DirectoryInfo(@"C:\music");
                FileInfo[] Files = dinfo.GetFiles("*.mp3");
                foreach (FileInfo file in Files)
                {
                    LibraryTracks.Items.Add(file.Name);
                } 
            }
    
            private void button2_Click(object sender, EventArgs e) //add track
            {
                foreach(string name in PlaylistTracks.Items )
                {
                    if (LibraryTracks.SelectedItem.ToString() == name)
                    {
                        MessageBox.Show("Song already in playlist");
                        return;
                    }
                 
                }
               PlaylistTracks.Items.Add(LibraryTracks.SelectedItem);
            }
    
            private void button3_Click(object sender, EventArgs e) //remove track
            {
               
               PlaylistTracks.Items.Remove(PlaylistTracks.SelectedItem);
          
            }
    
            private void button1_Click(object sender, EventArgs e) //create playlist
            {
                Playlist temp = new Playlist(textBoxPlaylist.Text);
                foreach(string name in PlaylistTracks.Items)
                {
                    temp.addSong(name);
               
                }
    
            }
    
        }
    }
    and looking at the image of what form the first listbox is populated from a folder called music. The second listbox is for the playlist. The add/remove buttons add or remove the songs to the second listbox. I want the create button to save the selection of songs in the second listbox and the name in the textbox.
    I then have another form where I want the names of the playlists to be displayed in

  10. #10
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    Look at this code:
    Code:
            private void button1_Click(object sender, EventArgs e) //create playlist
            {
                Playlist temp = new Playlist(textBoxPlaylist.Text);
                foreach(string name in PlaylistTracks.Items)
                {
                    temp.addSong(name);
               
                }
    
            }
    You are creating a new Playlist and populating it correctly, but it is lost when the click handler finishes. You need to save it in a variable (i.e. a collection of playlists) outside this function.

  11. #11
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    ok thanks but how would I do that?

  12. #12
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: serialization question

    Quote Originally Posted by beginner91 View Post
    ok thanks but how would I do that?
    Instead of having the Playlist temp a local variable inside the button click handler, make it a class field or property (so it has class scope).

    Do you know how to declare a class field? E.g.
    Code:
    private PlayList _playList;

  13. #13
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    i ready made a class for playlist
    Code:
    namespace Playing_MP3_songs
    {
        class Playlist
        {
            private string name;
            ArrayList list;
    
            public Playlist(string name)
            {
                this.name = name;
                list = new ArrayList();
            }
            public void addSong(string fileName)
            {
                list.Add(fileName);
            
            }
          }
    
    
         
    }
    Playlist is referring to this class
    Last edited by beginner91; March 26th, 2012 at 02:18 PM.

  14. #14
    Join Date
    Jan 2009
    Posts
    596

    Re: serialization question

    You have this data member in your class:
    Code:
    ArrayList myPlaylistsCollection = new ArrayList();
    Shouldn't the playlists go in there

  15. #15
    Join Date
    Mar 2012
    Posts
    99

    Re: serialization question

    yes you are right. so how do i put the playlists in there?

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
  •  





Click Here to Expand Forum to Full Width

Featured