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.
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:
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.
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.
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
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.