Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Sleeper Music Player

4.00/5 (6 votes)
18 Oct 2009CPOL3 min read 31.6K   1.8K  
A playlist player for Windows that ends at a user specified time

Introduction

I liked to listen to music when I went to bed, but getting up (and waking up) to turn it off again was a nightmare! I had a few options:

  1. Make a small enough playlist every time relative to how late it was
  2. Get a program that would turn off my PC after a while, but this usually led to me waking up due to the abrupt end and sudden Windows music!

So that's how this project came about.

Background

In this project, I use Visual Studio 2008 prof (a small gift from uni:D) but I intend on making a 2005 edition, and it should definitely work with the Express Editions. The language is C# although if you ask nicely, I may write a copy in VB though I would prefer not to as I haven't done that in ages!

It is complete with a solution file and folders needed to get this to work, including a compiled example or two.

It uses all the basic components available to any basic developer using the Visual Studio IDEs. and Windows XP. I have SP3 installed on my machines but I'm sure it will work fine on earlier versions of XP. As for Vista & ME etc., I cannot say, because I don't have them, so if someone could try it out and get an email to me, that would be great!
The bulk of this code is auto-generated by the IDE, I did the bits in between.

I used wmplib, Windows Forms {listbox, buttons, labels, textboxes, etc.} and some interesting shutdown code that I got from this very website.

The Program

  • Plays a precreated playlist to a specified time, then plays that track until the end and shuts down the PC if needed or merely ends the program
  • Controls the volume for the app only
  • Allows the user to control file played, and volume
  • Allows the user to end the playing straight after the current song
  • Supports internet streams
  • Several UI bug fixes
  • Updated to 1.0.2.0
  • More in the TODO.txt file
  • New repo added for easier code management

Using the Code

It should be straight-forward(tm) but I never know. I have tried to give good variable names. If you look at the TODO.txt, it shows you whereabouts I am at the moment.
Example of a button call follows things to note.

Godmode is a debugging mode that probably won't be removed, if you write "Godmode" (no quotes) into the address of the playlist in settings, then you get to see the "god chat".

C#
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
   {
        if (Godmode)
        {
            listBox2.Items.Add("settings opened");
        }
        //button3_Click(null, null);
        Settings settings = new Settings();
        settings.ShowDialog();
        if (label1.Text != Settings1.Default.URL)
        {
            if (Godmode)
            {
                listBox2.Items.Add("playlist url changed");
            }
            listBox1.Items.Clear();
            stopButton_Click(null, null);
            startButton_Click(null, null);
            label1.Text = Settings1.Default.URL;
        }
        if (Godmode)
        {
            this.Width = formwidth + listBox2.Width + 10;
            listBox2.Visible = true;
        }
        else
        {
            this.Width = formwidth;
            listBox2.Visible = false;
        }
        if (Godmode)
        {
            if (Player.settings.volume != Settings1.Default.Volume)
            {
                listBox2.Items.Add("volume changed from " + 
			Player.settings.volume + " to " + Settings1.Default.Volume);
            }
        }
        Player.settings.volume = Settings1.Default.Volume;
   }     

Points of Interest

I learned that:

  1. Combo boxes are great, but not here.
  2. The datetime box is stupid, moves days itself but not hours!
  3. Listboxes are useful but can be tricky.
  4. Wmplib is kinda out of date, but works I guess...
  5. The wmplaylist format is simple, but I ain't very good at XML.
  6. Coding for fun can be useful.

History

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)