Jump to content
  • Advertisement
Sign in to follow this  
lonewolff

Directshow problem

This topic is 1232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys,
 
I have come across a small problem with my DirectShow code.
 
I want to play audio only from a video file (without any video image playing) and I have the following code which works fine with AVI files.
 

char* szFilename=filename;

HRESULT hr;
hr=CoInitialize(NULL);
if(FAILED(hr))		// Error in CoInitialize;
	return 1;

// create filter graph and get interfaces
hr=CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void**)&it->pGraph);
if(FAILED(hr))		// Error in creating graph
	return 2;
	
hr=it->pGraph->QueryInterface(IID_IMediaControl,(void**)&it->pControl);
if(FAILED(hr))		// Error in querying media control
	return 3;

hr=it->pGraph->QueryInterface(IID_IMediaEvent,(void**)&it->pEvent);
if(FAILED(hr))		// Error in querying media event
	return 4;

hr=it->pGraph->QueryInterface(IID_IMediaSeeking,(void**)&it->pSeeking);
if(FAILED(hr))		// Error in querying seeking interface
	return 5;

// Converts the path to wide characters
WCHAR wFilePath[MAX_PATH];
char tempFilePath[MAX_PATH];
strcpy(tempFilePath,filename);
strcat(tempFilePath,"\0");

int len=(int)strlen(tempFilePath);
int needed=MultiByteToWideChar(0,0,tempFilePath,len+1,wFilePath,len+1);

hr=it->pGraph->RenderFile(wFilePath,NULL);
if(FAILED(hr))		// Problem with opening video file
	return 13;
 

hr=it->pGraph->QueryInterface(IID_IVideoWindow,(void**)&it->pWindow);
if(FAILED(hr))		// Error getting video window interface
	return 14;

hr=it->pGraph->QueryInterface(IID_IBasicAudio,(void**)&it->pAudio);
if(FAILED(hr)) 
	return 15;

it->pWindow->put_AutoShow(OAFALSE);

The problem is, when I try to load video files that are any type other than AVI (eg mov, mp4, etc...) the code fails at the "return 13" potion of my code.

 

All of the video files I am trying to load work fine in media player, so installed codecs shouldn't be an issue.

 

Any help would be greatly appreciated!

 

Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement

Just check the value of the HRESULT returned from RenderFile.

 

You shouldn't convert DirectShow's error results (which tell you why DirectShow failed) into your own error values (which tell you absolutely nothing), and then just ignore DirectShow's values.

 


All of the video files I am trying to load work fine in media player, so installed codecs shouldn't be an issue.

 

If you're on Windows Vista or newer, I believe Media Player now uses Media Foundation Transforms instead of DirectShow codecs.

Edited by tonemgub

Share this post


Link to post
Share on other sites
Thanks for the reply.

I have been looking into Media a Foundation for a few days now and it looks like the way to go.

I know I lose the ability to run on XP, but it is a pretty old OS now. So, as much as I like backward compatibility, it is probably time to let XP support go.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!