U
Uddipto Banerji
Guest
I have to play targetMusic,Buffermusic and background music at the same time with the file extension like.wav and mp3. The files are played asynchronously.Now I'm getting the error when Exception from HRESULT: 0x80040266 and when I digged deep I found that it may be due to VFW_E_NO_TRANSPORT 0x80040266 which means Pins cannot connect because they don't support the same transport.For example, the upstream filter might require the IAsyncReader interface, while the downstream filter requires IMemInputPin
I'm a newbabie to COM handling so can anyone help me in this aspect to resolve this issue and play the audio files.
private void PlayBackGround()
{
string directoryString;
string filename;
//Array Audarray;
mc = null;
if (mc == null)
{
// This audio is being played for the first time.
// Get access to the IMediaControl interface.
graphManager = new QuartzTypeLib.FilgraphManager();
mc = (QuartzTypeLib.IMediaControl)graphManager;
// Load the file.
directoryString = Directory.GetCurrentDirectory();
directoryString = directoryString.Substring(0, directoryString.IndexOf("bin")) + "Audio_UploadedFiles";
filename = System.IO.Path.GetFileName(directoryString);
string str = directoryString + @"\" + _BackgroundAudioFile;
try
{
mc.RenderFile(str);//"\\test.mp3");
mc.Run();
}
catch (System.IO.FileNotFoundException err)
{
MessageBox.Show("File not found.");
return;
}
}
// Start playing the audio asynchronously.
try
{
//mc.Run();
}
catch (System.Runtime.InteropServices.COMException err)
{
// Indicates a problem interpreting the file.
MessageBox.Show("COM error." + err);
}
}
private void PlayTargetHitMusic()
{
string directoryString;
string filename;
//Array Audarray;
tc = null;
if (tc == null)
{
// This audio is being played for the first time.
// Get access to the IMediaControl interface.
graphManager = new QuartzTypeLib.FilgraphManager();
tc = (QuartzTypeLib.IMediaControl)graphManager;
// Load the file.
directoryString = Directory.GetCurrentDirectory();
directoryString = directoryString.Substring(0, directoryString.IndexOf("bin")) + "Audio_UploadedFiles";
filename = System.IO.Path.GetFileName(directoryString);
try
{
string AudioTargetFile = directoryString + "\\" + AudioTarget[new Random().Next(0, AudioTarget.Length - 1)].ToString();
//tc.RenderFile(directoryString + @"\\" + _strTarget[new Random().Next(0, _strTarget.Length - 1)].ToString());//"\\test.mp3");
tc.RenderFile(AudioTargetFile);//"\\test.mp3");
tc.Run();
}
catch (System.IO.FileNotFoundException err)
{
MessageBox.Show("File not found.");
return;
}
}
// Start playing the audio asynchronously.
try
{
//tc.Run();
}
catch (System.Runtime.InteropServices.COMException err)
{
// Indicates a problem interpreting the file.
MessageBox.Show("COM error.");
}
}
private void PlayBufferHitMusic()
{
string directoryString;
string filename;
//Array Audarray;
bc = null;
if (bc == null)
{
// This audio is being played for the first time.
// Get access to the IMediaControl interface.
graphManager = new QuartzTypeLib.FilgraphManager();
bc = (QuartzTypeLib.IMediaControl)graphManager;
// Load the file.
directoryString = Directory.GetCurrentDirectory();
directoryString = directoryString.Substring(0, directoryString.IndexOf("bin")) + "Audio_UploadedFiles";
filename = System.IO.Path.GetFileName(directoryString);
try
{
string AudioBufferFile = directoryString + "\\" + AudioBuffer[new Random().Next(0, AudioBuffer.Length - 1)].ToString();
//bc.RenderFile(directoryString + @"\\" + _strCompleteText[new Random().Next(0, _strCompleteText.Length - 1)].ToString());//"\\test.mp3");
bc.RenderFile(AudioBufferFile);//"\\test.mp3");
bc.Run();
}
catch (System.IO.FileNotFoundException err)
{
MessageBox.Show("File not found.");
return;
}
}
// Start playing the audio asynchronously.
try
{
//tc.Run();
}
catch (System.Runtime.InteropServices.COMException err)
{
// Indicates a problem interpreting the file.
MessageBox.Show("COM error.");
}
}
And to play asynchronously the code below:
protected override void WndProc(ref Message m)
{
audio = (QuartzTypeLib.IBasicAudio)graphManager;
position = (QuartzTypeLib.IMediaPosition)graphManager;
mEventEx = (QuartzTypeLib.IMediaEventEx)graphManager;
// Check if it's a notification message from the Quartz component.
if (m.Msg == WM_GRAPHNOTIFY)
{
int lEventCode;
int lParam1, lParam2;
try
{
// Retrieve the message.
mEventEx.GetEvent(out lEventCode, out lParam1,
out lParam2, 0);
mEventEx.FreeEventParams(lEventCode, lParam1, lParam2);
// Check if it's the end-of-file message.
if (lEventCode == EC_COMPLETE)
{
// Restart the playback.
mc.Stop();
bc.Stop();
tc.Stop();
position = (QuartzTypeLib.IMediaPosition)graphManager;
position.CurrentPosition = 0;
// mc.Run();
//MeasureProgress();
}
}
catch (Exception)
{
// Never throw an exception from WndProc().
// You may want to log it, however.
}
}
// Pass the message along to .NET.
base.WndProc(ref m);
}
Continue reading...
I'm a newbabie to COM handling so can anyone help me in this aspect to resolve this issue and play the audio files.
private void PlayBackGround()
{
string directoryString;
string filename;
//Array Audarray;
mc = null;
if (mc == null)
{
// This audio is being played for the first time.
// Get access to the IMediaControl interface.
graphManager = new QuartzTypeLib.FilgraphManager();
mc = (QuartzTypeLib.IMediaControl)graphManager;
// Load the file.
directoryString = Directory.GetCurrentDirectory();
directoryString = directoryString.Substring(0, directoryString.IndexOf("bin")) + "Audio_UploadedFiles";
filename = System.IO.Path.GetFileName(directoryString);
string str = directoryString + @"\" + _BackgroundAudioFile;
try
{
mc.RenderFile(str);//"\\test.mp3");
mc.Run();
}
catch (System.IO.FileNotFoundException err)
{
MessageBox.Show("File not found.");
return;
}
}
// Start playing the audio asynchronously.
try
{
//mc.Run();
}
catch (System.Runtime.InteropServices.COMException err)
{
// Indicates a problem interpreting the file.
MessageBox.Show("COM error." + err);
}
}
private void PlayTargetHitMusic()
{
string directoryString;
string filename;
//Array Audarray;
tc = null;
if (tc == null)
{
// This audio is being played for the first time.
// Get access to the IMediaControl interface.
graphManager = new QuartzTypeLib.FilgraphManager();
tc = (QuartzTypeLib.IMediaControl)graphManager;
// Load the file.
directoryString = Directory.GetCurrentDirectory();
directoryString = directoryString.Substring(0, directoryString.IndexOf("bin")) + "Audio_UploadedFiles";
filename = System.IO.Path.GetFileName(directoryString);
try
{
string AudioTargetFile = directoryString + "\\" + AudioTarget[new Random().Next(0, AudioTarget.Length - 1)].ToString();
//tc.RenderFile(directoryString + @"\\" + _strTarget[new Random().Next(0, _strTarget.Length - 1)].ToString());//"\\test.mp3");
tc.RenderFile(AudioTargetFile);//"\\test.mp3");
tc.Run();
}
catch (System.IO.FileNotFoundException err)
{
MessageBox.Show("File not found.");
return;
}
}
// Start playing the audio asynchronously.
try
{
//tc.Run();
}
catch (System.Runtime.InteropServices.COMException err)
{
// Indicates a problem interpreting the file.
MessageBox.Show("COM error.");
}
}
private void PlayBufferHitMusic()
{
string directoryString;
string filename;
//Array Audarray;
bc = null;
if (bc == null)
{
// This audio is being played for the first time.
// Get access to the IMediaControl interface.
graphManager = new QuartzTypeLib.FilgraphManager();
bc = (QuartzTypeLib.IMediaControl)graphManager;
// Load the file.
directoryString = Directory.GetCurrentDirectory();
directoryString = directoryString.Substring(0, directoryString.IndexOf("bin")) + "Audio_UploadedFiles";
filename = System.IO.Path.GetFileName(directoryString);
try
{
string AudioBufferFile = directoryString + "\\" + AudioBuffer[new Random().Next(0, AudioBuffer.Length - 1)].ToString();
//bc.RenderFile(directoryString + @"\\" + _strCompleteText[new Random().Next(0, _strCompleteText.Length - 1)].ToString());//"\\test.mp3");
bc.RenderFile(AudioBufferFile);//"\\test.mp3");
bc.Run();
}
catch (System.IO.FileNotFoundException err)
{
MessageBox.Show("File not found.");
return;
}
}
// Start playing the audio asynchronously.
try
{
//tc.Run();
}
catch (System.Runtime.InteropServices.COMException err)
{
// Indicates a problem interpreting the file.
MessageBox.Show("COM error.");
}
}
And to play asynchronously the code below:
protected override void WndProc(ref Message m)
{
audio = (QuartzTypeLib.IBasicAudio)graphManager;
position = (QuartzTypeLib.IMediaPosition)graphManager;
mEventEx = (QuartzTypeLib.IMediaEventEx)graphManager;
// Check if it's a notification message from the Quartz component.
if (m.Msg == WM_GRAPHNOTIFY)
{
int lEventCode;
int lParam1, lParam2;
try
{
// Retrieve the message.
mEventEx.GetEvent(out lEventCode, out lParam1,
out lParam2, 0);
mEventEx.FreeEventParams(lEventCode, lParam1, lParam2);
// Check if it's the end-of-file message.
if (lEventCode == EC_COMPLETE)
{
// Restart the playback.
mc.Stop();
bc.Stop();
tc.Stop();
position = (QuartzTypeLib.IMediaPosition)graphManager;
position.CurrentPosition = 0;
// mc.Run();
//MeasureProgress();
}
}
catch (Exception)
{
// Never throw an exception from WndProc().
// You may want to log it, however.
}
}
// Pass the message along to .NET.
base.WndProc(ref m);
}
Continue reading...