Hello, I'm using code as shown below to play the first duration milliseconds of a media file

MCIWndHome(m_Audio);	
MCIWndPlayTo(m_Audio, duration);

This works fine to only play the first duration milliseconds when the length of the audio file is greater than duration, but if the audio is longer than that I get the error "The specified parameter is out of range for the specified command."
The documentation says:

The MCIWndPlayTo macro plays the content of an MCI device from the current position to the specified ending location or until another command stops playback. If the specified ending location is beyond the end of the content, playback stops at the end of the content.

So I figured I could put whatever I want in for the ending location and it would always either stop at the specified end location or at the end of the media, whichever comes first. Instead I get the error and it doesn't play at all.

What am I doing wrong? Why wouldn't this work?

Any idea why this code doesn't appear to be performing as described in the documentation?

If anyone else has this problem, below is the workaround that I've put in for now that seems to do the trick, although it's still not clear to me why it doesn't work the original way.

int len = MCIWndGetLength(m_Audio);	
if(len > max_duration) len = max_duration;
MCIWndPlayTo(m_Audio, len);

Instead of screwing around with finding the length, comparing it with the maximum duration I want and playing to whichever is shorter, I'd still like to know why it doesn't do this:

If the specified ending location is beyond the end of the content, playback stops at the end of the content.

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.