Thursday, July 30, 2009

C#..........10points?

hello!


I need some C# sources or tutorials for create a mp3 player with Visual Studio C#.


Do you know a/some web site/s for resolve my problem?


Thanks





ps = Excuse me, but I'm italian and I don't speak English very well!

C#..........10points?
using System;


using System.Drawing;


using System.Windows.Forms;


using System.Runtime.InteropServices;


using System.Text;





namespace CsharpMp3


{


public class Form1 : System.Windows.Forms.Form


{


private System.Windows.Forms.Button btnOpen;


private System.Windows.Forms.Button btnPlay;


private System.Windows.Forms.Label lblCurrnt;


private System.ComponentModel.IContainer components;





private OpenFileDialog file = new OpenFileDialog();





private string CommandString;


private System.Windows.Forms.Timer timer1;


private int seconds;


private int minutes;





StringBuilder buffer = new StringBuilder(128);





[DllImport("winmm.dll")]


private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);





public Form1()


{


InitializeComponent();


}





protected override void Dispose( bool disposing )


{


if( disposing )


{


if (components != null)


{


components.Dispose();


}


}


base.Dispose( disposing );


}





#region Windows Form Designer generated code


/// %26lt;summary%26gt;


/// Required method for Designer support - do not modify


/// the contents of this method with the code editor.


/// %26lt;/summary%26gt;


private void InitializeComponent()


{


this.components = new System.ComponentModel.Container();


this.btnOpen = new System.Windows.Forms.Button();


this.btnPlay = new System.Windows.Forms.Button();


this.lblCurrnt = new System.Windows.Forms.Label();


this.timer1 = new System.Windows.Forms.Timer(this.componen...


this.SuspendLayout();


//


// btnOpen


//


this.btnOpen.Location = new System.Drawing.Point(56, 16);


this.btnOpen.Name = "btnOpen";


this.btnOpen.Size = new System.Drawing.Size(72, 24);


this.btnOpen.TabIndex = 0;


this.btnOpen.Text = "Open";


this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);


//


// btnPlay


//


this.btnPlay.Location = new System.Drawing.Point(168, 16);


this.btnPlay.Name = "btnPlay";


this.btnPlay.Size = new System.Drawing.Size(72, 24);


this.btnPlay.TabIndex = 1;


this.btnPlay.Text = "Play";


this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);


//


// lblCurrnt


//


this.lblCurrnt.BorderStyle = System.Windows.Forms.BorderStyle.FixedSi...


this.lblCurrnt.Location = new System.Drawing.Point(96, 48);


this.lblCurrnt.Name = "lblCurrnt";


this.lblCurrnt.Size = new System.Drawing.Size(96, 24);


this.lblCurrnt.TabIndex = 2;


this.lblCurrnt.TextAlign = System.Drawing.ContentAlignment.MiddleCe...


//


// timer1


//


this.timer1.Tick += new System.EventHandler(this.timer1_Tick);


//


// Form1


//


this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);


this.ClientSize = new System.Drawing.Size(292, 86);


this.Controls.AddRange(new System.Windows.Forms.Control[] {


this.lblCurrnt,


this.btnPlay,


this.btnOpen});


this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fix...


this.Name = "Form1";


this.Text = "Csharp Mp3 Player";


this.ResumeLayout(false);





}


#endregion





[STAThread]


static void Main()


{


Application.Run(new Form1());


}





private void btnOpen_Click(object sender, System.EventArgs e)


{


file.Filter = "Mp3 files |*.mp3";


if(file.ShowDialog() == DialogResult.OK)


{


CommandString = "close Mp3File";


mciSendString(CommandString,null,0,0);





timer1.Enabled = false;





CommandString = "open " + "\"" + file.FileName + "\"" + " type MPEGVideo alias Mp3File";


mciSendString(CommandString,null,0,0);


}


}





private void btnPlay_Click(object sender, System.EventArgs e)


{


if(file.FileName == "")


{


file.Filter = "Mp3 files |*.mp3";


if(file.ShowDialog() == DialogResult.OK)


{


CommandString = "open " + "\"" + file.FileName + "\"" + " type MPEGVideo alias Mp3File";


mciSendString(CommandString,null,0,0);





CommandString = "play Mp3File";


mciSendString(CommandString,null,0,0);





timer1.Enabled = true;


}


}





else


{


CommandString = "play Mp3File";


mciSendString(CommandString,null,0,0);





timer1.Enabled = true;


}





}





private void timer1_Tick(object sender, System.EventArgs e)


{


CommandString = "Status Mp3File position";


mciSendString(CommandString, buffer, 128, 0);


seconds = int.Parse(buffer.ToString());


seconds = seconds / 1000;





minutes = seconds / 60;


seconds = seconds % 60;


lblCurrnt.Text = minutes.ToString("00") + ":" + seconds.ToString("00");


}


}


}
Reply:A *really* helpful MSDN forums post indicated some solid material on approaches %26amp; additional sourcecode:





http://forums.microsoft.com/MSDN/ShowPos...





Hope this is helpful!





ROSS


DCX3


No comments:

Post a Comment