I am using MCI controls to play media files within some software. For the most part, it works OK but sometimes things go poorly (e.g. when the media file is corrupt).

How can I either put the code into a try/catch (i.e. what exception do I look for?) or how can I check the file before running the code? When it hits the MCIWndCreate... line it causes an MCI Error popup window that requires user interaction. I would like for it stop trying to play the file (without any user interaction) and run another piece of code if the file is not playable.

HWND m_Video;
CString m_Path = "C:\\Path\\bad.mp3";
m_Video = NULL;

if(m_Video == NULL)
    m_Video = MCIWndCreate(this->GetSafeHwnd(), AfxGetInstanceHandle(), WS_CHILD | WS_VISIBLE|MCIWNDF_NOMENU,m_Path);
else
    MCIWndHome(m_Video);
int len = MCIWndGetLength(m_Video);
//code to modify len if needed is normally here
MCIWndPlayTo(m_Video, len);

Edit: FWIW, it looks like the error that is being thrown is MCIERR_INVALID_FILE.

Oops, I guess the timeout for editing the post has been reached. I wanted to add that the NOERRORDLG flag suppresses the error popup and allows the code to continue execution, however, it apparently counts the function as a success as the value returned to m_video is non-zero. Without that, I'm not sure how to tell that there was a problem and know to run the code that should run when there is a problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.