Hi,

I have a MP3DataSet that includes .mp3 files, i have a form, which shows all the files in the dataset, on the form i also have the windows media players.

I am trying, when the user clicks on a song in the dataset to play on the WMP, any ideas?

Thanks

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by sknake

Thanks, how would i do that?

thanks again

How is the mp3 stored in your dataset? If you have a byte[] array of the binary data then just write it out disk:

Here is an example. In this case i'm pulling an image down and naming it as an mp3 file, but the concept is what you want:

private void button555_Click(object sender, EventArgs e)
{

const string connStr = "Data Source=apex2006sql;Initial Catalog=ServManLeather;Integrated Security=True;";
const string query = "Select ImgNumber, FacilityImg From FacilityImg Where ImgNumber = 1000";
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.InfoMessage += new SqlInfoMessageEventHandler(conn_InfoMessage);
conn.Open();
using (SqlCommand cmd = new SqlCommand(query, conn))
{
{
using (DataTable dt = new DataTable())
{
//File.WriteAllBytes(@"C:\picture.bmp", (byte[])dt.Rows[0]["FacilityImg"]);
using (MemoryStream ms = new MemoryStream((byte[])dt.Rows[0]["FacilityImg"]))
{
ms.Position = 0;
ms.Seek(0, SeekOrigin.Begin);
string fileName = System.IO.Path.GetTempFileName();
File.WriteAllBytes(fileName, ms.ToArray());
System.IO.File.Move(fileName, System.IO.Path.ChangeExtension(fileName, ".mp3"));
fileName = System.IO.Path.ChangeExtension(fileName, ".mp3");
//mediaPlayer.Play(fileName);
}
}
}
}
}
}

I suppose you could call File.WriteAllBytes(fileName, ms.ToArray()); to save yourself some lines.
[/edit]

Edited by sknake: n/a

thanks for that im using DataSet and a table adapter.

Its not reconising File. do i have to use a namespace at the top to make this work?

I don't understand what you are asking. Upload your project so we can take a look at it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.