locked
Exception from HRESULT: 0x80040266 with RenderFile(Strfilename) on Windows 7 RRS feed

  • คำถาม

  • 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);

    }

     

    20 สิงหาคม 2554 12:56

คำตอบ

ตอบทั้งหมด

  • Looks to me you want a mp3 player.

    Probably you might want to take a look on this.

    http://ultidevwebbasedmp3pl.codeplex.com/

    chanmm


    chanmm
    21 สิงหาคม 2554 2:47
  • Thank you for your response. I'm using a windows Form  and not ASP.Net where there would be no visual interface. The listed of songs names would come from the database which the user would select a set of songs from a different windows form. The playsong form would just play the songs and the screen would be blank. The user is allowed to select .wav and .mp3 files.when I'm trying to play I'm getting the error shown below.

    I have found from internet that this error is likely 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 but I donot know anything about COM component so I cannot rectify this error. If possible can you help me with some code.

    21 สิงหาคม 2554 8:25
  • Code won't do it.  You need filters that will connect.  Use Graphedt.exe to setup and verify your graph.  Ask DirectShow questions on the DirectShow forum.
    21 สิงหาคม 2554 8:36
  • thank you.How to use filters?can u help me with some code and how to get and use the Graphedt.exe to setup? I want to play audio files asynchronously.
    21 สิงหาคม 2554 8:52
  • To play audio files asynchronously use SoundPlayer.Play.
    21 สิงหาคม 2554 8:54
  • 1. I'm using vs.net2008 for the development.
    2. I'm using QuartzType.dll as a reference which I got it from C:\windows\System32
    3. I'm using sql server2005 as database.
    4. I'm using a windows Form  and not ASP.Net where there would be no visual interface.
    5. I want to play audio files asynchronously which have extension of .wav and .mp3
    6. The user would select the audio set which would consists of audio sound files from a different window forms.
    7. When executed it is throwing Exception from HRESULT: 0x80040266.
    8. I searched and found out which 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 IMemInputPinI'm
    9. I have no clue and donot know about COM error
    10.how to resolve this issue and how to rectify this error.Is there any code which would help me to solve this error.
    11.The code which I have written below and the error which I'm getting is below.


    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);

    }

     

     

    21 สิงหาคม 2554 11:22
  • You need filters that will connect. Use Graphedt.exe to setup and verify your graph. Ask DirectShow questions on the DirectShow forum.
    21 สิงหาคม 2554 12:28
  • Thank you.I have even raised a question in DirectX forum,unfortunately no reply and my deadline is very near so I require to resolve this issue urgently.I understood your point but how to use filters as I donot have any clue both in Graphedt.exe or in code.is there any tutorial where I can learn and use or you have any code which would help me to fix this issue which I can use it in my code to resolve the error.


    21 สิงหาคม 2554 14:12
  • This is the best treatise on DirectShow that I know of:  Stephen Toub - Fun With DVR-MS
    • เสนอเป็นคำตอบโดย Jackie-Sun 24 สิงหาคม 2554 6:10
    • ทำเครื่องหมายเป็นคำตอบโดย Jackie-Sun 29 สิงหาคม 2554 2:39
    21 สิงหาคม 2554 14:28
  • I know this is a dead one, but I got into the same issue and solved it by disabling the "Prefer 32 bit" option in project settings.
    2 ตุลาคม 2562 23:21