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.