IT Community - Software Programming, Web Development and Technical Support

Play MP3 file using C#

This is a discussion on Play MP3 file using C# within the C# Programming forums, part of the Software Development category; Play MP3 files using C#. Goals: This project is used to play the mp3 files using c#. Steps: 1) Create ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-20-2007, 12:08 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Play MP3 file using C#

Play MP3 files using C#.
Goals:

This project is used to play the mp3 files using c#.


Steps:

1) Create a c# windows application.

2) create two textboxes and two button controls.

3) copy the following code.

private string PlayCommand;
private bool isOpen;

[DllImport("winmm.dll")]
private static extern long mciSendString(
string strCommand,
StringBuilder strReturn,
int iReturnLength,
IntPtr oCallback);



private void btnselectfile_Click(object sender, EventArgs e)
{

this.openFileDialog1.Filter = "MP3(*.mp3)|*.mp3| Widows File (*.wmv)|*.wmv";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtmediafile.Text = this.openFileDialog1.FileName.ToString();
OpenMediaFile(txtmediafile.Text.ToString());

//File
string strFilePro = openFileDialog1.FileName;
FileInfo oFileInfo = new FileInfo(strFilePro);

//Find file size
txtfilesize.Text = oFileInfo.Length.ToString();

//File Created date
DateTime dtCreationTime = oFileInfo.CreationTime;
txtfilecrdate.Text = dtCreationTime.ToString();
}
}

public void ClosePlayer()
{
PlayCommand = "Close MediaFile";
mciSendString(PlayCommand, null, 0, IntPtr.Zero);
isOpen = false;
}


public void OpenMediaFile(string strFileName)
{
PlayCommand = "Open \"" + strFileName + "\" alias MediaFile";
mciSendString(PlayCommand, null, 0, IntPtr.Zero);
isOpen = true;
}


public void PlayMediaFile(bool loop)
{
if (isOpen)
{
PlayCommand = "Play MediaFile";
if (loop)
PlayCommand += " REPEAT";
mciSendString(PlayCommand, null, 0, IntPtr.Zero);
}
}

private void btnclose_Click(object sender, EventArgs e)
{
ClosePlayer();
}

private void btnplaysong_Click(object sender, EventArgs e)
{
PlayMediaFile(isOpen);
}

4) run the application.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/c-programming/2271-play-mp3-file-using-c.html
Posted By For Type Date
Play MP3 file using C# | Web Hosting This thread Refback 12-17-2007 12:50 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which kind of games do you prefer to play? arjkhanna Game Development 14 08-15-2008 10:07 PM
play mp3 file using java application? saravanan Java Programming 1 03-26-2008 02:15 AM
Trouble getting movieclips to play at random aramesh Flash Actionscript Programming 5 02-19-2008 06:48 AM
Can I play a sound onMouseOver? itbarota HTML, CSS and Javascript Coding Techniques 1 09-13-2007 04:12 AM
How to play multiple .flv files using the RTMP connection. oxygen Flash Actionscript Programming 1 07-24-2007 05:28 AM


All times are GMT -7. The time now is 10:25 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0