Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Dundas Dashboard
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Visual C# » Poorman's iPod MP3 Player in C# and .NET

Poorman's iPod MP3 Player in C# and .NET

This article is an update to an article written by George Steeves on how to create an MP3 player using C# and .NET using the moon valley mp3p.ocx control.

Author Rank:
Technologies: .NET 1.0/1.1, ActiveX, Windows Forms,Visual C# .NET
Total downloads : 1813
Total page views :  41290
Rating :
 2.33/5
This article has been rated :  3 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
PoormansIPod.ZIP
 
Become a Sponsor


Related EbooksTop Videos


PoormansIpod.jpg

Figure 1 - Music Player

Introduction

This article is based upon one written on C# Corner by George Steeves on creating a Simple MP3 player.  This article upgrades the player to the .NET 2.0 Framework,  and adds some features to the player, such as the ability to view a song list inside a folder.  It also allows you to play, stop and pause the song.  The download also includes a necessary file (xaudio.dll )  which is required by the mp3p.ocx file developed by moon valley.

Installation

A setup project is included with the download as well as the actual installation of the mp3 player.  Run the installation first so that it registers the activex control and installs the necessary dlls.  You can test out the mp3 player after installing by going to the desktop or the start menu.

The Code

The Poorman's iPod player uses .NET to wrap the mp3p.ocx ActiveX control.  The control has some basic music file capabilities such as the ability to play, pause, or stop your song.  To use the control, you initially need to open the mp3 file into the control.  At this point, you can control the state of the song.  Below is the code for opening a song from the playlist:

Listing 1 - Opening a song into the mp3p.ocx control

/// <summary>
///
Opens a selected song into the mp3 activex control
/// </summary>
private void OpenSelectedSong()
 {

 // make sure the previous output is closed
   axMp3P1.OutputClose();
  //  get the path of the selected mp3 file and open it
 
if (lbSongs.SelectedIndex >= 0)
  {
    
string songPath = String.Format("{0}\\{1}.mp3", _currentPath, lbSongs.SelectedItem.ToString());
     axMp3P1.InputOpen(songPath);
  }
}

The program allows you to browse for a particular song on your file system.  Initially the program puts you in the "My Music" folder (which is under "My Documents").  If you tend to keep all your music here, then it will be easier to access them.  If you don't keep your music in this folder, you can change the line of code below located inside the constructor of the form

Listing 2 - Setting the starting place of the Folder Browser to the My Music Folder

folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyMusic;

Browsing for the song folder is accomplished through the ShowDialog method of the FolderBrowserDialog as shown in listing 3.  The btnBrowse_click method brings up the folder browser, and upon clicking ok, sets the selected music folder directory in which to look for the songs to play.  Then the method loops through each mp3 file in the selected folder and adds it to the list box.

Listing 3 - Browsing for a song folder

private void btnBrowse_Click(object sender, EventArgs e)
 {
  
// open the folder browser
   
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
     {
        
// find out which directory was chosen
         _currentPath = folderBrowserDialog1.SelectedPath;
        
DirectoryInfo dir = new DirectoryInfo(_currentPath);
         lbSongs.Items.Clear();
// go through each mp3 file in the directory
// and add it to the list box
 
    foreach (FileInfo nextFile in dir.GetFiles("*.mp3"))
        {
               lbSongs.Items.Add(nextFile.Name.Remove(nextFile.Name.LastIndexOf(
'.')));  // also remove the mp3 extension
         }
  
// clear the paused flag
         _pausePressed =
false;

    } 
// end if DialogResult is OK
}

Playing, Pausing, and Stopping the Player

The mp3p.ocx control has methods to play, stop, and pause the player.   To play, simply call Play() as shown in listing 4.  Similarly you can call Pause, to pause the player, and Stop, to stop the player.

Listing 4 - Play Button Event Handler

/// <summary>
///
Plays the current selected song
/// </summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private void btnStart_Click(object sender, EventArgs e)
 {
  
if (_pausePressed == false)
   {
      OpenSelectedSong();
   }

  axMp3P1.Play();
_pausePressed =
false;
}

Conclusion

If you are wondering how to get a hold of mp3 files,  you can either sign up for Napster, or copy the tracks off your existing CDs.  The way I get the tracks off my current CD's into MP3 format is through an add-in to the Windows Media Player that lets me rip tracks into MP3 format. (The latest Windows Media Player may already have mp3 ripping capability without the add-in).  Anyway, enjoy playing your music.  If you have a computer at work, you can use this player with your headphones to enhance your working experience.  Happy Listening!


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Mike Gold
Michael Gold is President of Microgold Software Inc., makers of the WithClass UML Tool. His company is a Microsoft VBA Partner and Borland Partner. Mike is a Microsoft MVP and founding member of C# Corner. He has a BSEE and MEng EE from Cornell University and has consulted for Chase Manhattan Bank, JP Morgan, Merrill Lynch, and Charles Schwab. Currently he is a senior developer at Finisar Corp. He has been involved in several .NET book projects, and is currently working on a book for using .NET with embedded systems. He can be reached at mike@c-sharpcorner.com
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
PoormansIPod.ZIP
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments
iPor by Scott On January 23, 2007
Pretty slick, certainly offers a painless way to mess with mp3 files. Thanks
Reply | Email | Delete | Modify | 
Ipod developed please give by Ram On February 6, 2008
This code I am trying I am unable to get the result so..plz kindly send the code in c# exact
Reply | Email | Delete | Modify | 
ipod by gagan On November 1, 2008
thanks 4 this mp3 player i m very thankful to u
Reply | Email | Delete | Modify | 
question by Armen On December 12, 2008
thanks for good product. I have 2 questions 1. can i use that player in web application?(can browsers play mp3) 2. what about libraries used in project? need any license to use it? many thanks
Reply | Email | Delete | Modify | 
Error,help me??? by Pham On April 19, 2009
The project after build have 3 errors about: The type or namespace name 'AxMP3PLib' could not be found (are you missing a using directive or an assembly reference? Why??Help me
Reply | Email | Delete | Modify | 
Re: Error,help me??? by pmilin On May 8, 2009
Sounds like you need to register the activeX component. Did you run the setup?
Reply | Email | Delete | Modify | 
very cool by danny On June 14, 2009
This is very nice, thanks.
I've changed it a little, added better UI and a drag and drop capability and now i'm using this as my new lightweight mp3 player :D

Danny, Locksmith Los Angeles
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved