Playing Audio file Problem prestored in database

  • Thread starter Thread starter malikasad
  • Start date Start date
M

malikasad

Guest
Hi Friends,

Please I am encountering problem the following code is working fine when play one audio file, I want to play three audio files

by sequence and I will get it audio files from database, but its only plays last file "token_4.m4a" and not playing the first one please help me thank you


private void btnPlay_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = GetFromDataBase(cmbPlayList.SelectedItem.ToString());
axWindowsMediaPlayer1.URL = GetFromDataBase("token_2.m4a");


axWindowsMediaPlayer1.URL = GetFromDataBase("token_4.m4a");
axWindowsMediaPlayer1.settings.autoStart = true;
}





private string GetFromDataBase(string fileName)
{
try
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
String Query1 = "SELECT FileData FROM [Test].[dbo].[MyPlay] where FileName = '" + fileName + "'";
SqlDataAdapter adapter = new SqlDataAdapter(Query1, ConnectionString);
DataSet Ds = new DataSet();
adapter.Fill(Ds, "MyPlay");
if (Ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("No data Found");
return string.Empty;
}
return ConvertByteDataToFile(fileName, GetUnCompressedData((byte[])Ds.Tables[0].Rows[0]["FileData"]));
}
catch (Exception)
{
throw;
}
return string.Empty;
}

private string ConvertByteDataToFile(string targetFileName, byte[] value)
{
// ReSharper disable EmptyGeneralCatchClause
var str = string.Empty;
try
{
try
{
var path = Path.GetTempPath();
str = path + "\\" + targetFileName;
if (File.Exists(str))
File.Delete(str);
}
catch (Exception) { }

var file = (new BinaryWriter(new FileStream(str, FileMode.OpenOrCreate, FileAccess.Write)));
file.Write(value);
file.Close();
return str;
}
catch (Exception) { }
// ReSharper restore EmptyGeneralCatchClause
return string.Empty;
}

private static byte[] ConvertFileToByteData(string sourceFileName)
{
BinaryReader binaryReader = null;
if (!File.Exists(sourceFileName))
return null;

try
{
binaryReader = new BinaryReader(new FileStream(sourceFileName, FileMode.Open, FileAccess.Read));
return binaryReader.ReadBytes(ConvertToInt32(binaryReader.BaseStream.Length));
}
finally
{
if (null != binaryReader) binaryReader.Close();
}
}



asad

Continue reading...
 
Back
Top