mciSendString two pits

Just a small correction alarm clock with its own code.

REPEAT scope options: Pit 1

The original used properly, then select the .wav file, but still no voice ......

Oh, MCI certainly supports .wav, ah ......

Think about it, I had previously been selected as .mp3 alarm, and this matter?

View source.

strSend = "PLAY " & STRING_SOUND_ALIAS & " REPEAT"
Call mciSendString(strSend, rbuf, 0, 0)

  

To me awakened (general ...... I slept very dead) from sleep, I chose REPEAT option to loop.

Ah, there is. Remember where you read about, PLAY command REPEAT option can only act on MPEGVideo types of files. (Time is so late, I want to finish recording directly to sleep, do not look for the source of the quote.)

It is very simple, when opened as MPEGVideo open just fine.

strSend = "OPEN " & Chr$(34) & FileName & Chr$(34) & " ALIAS " & STRING_SOUND_ALIAS & " TYPE MPEGVIDEO"
Call mciSendString(strSend, rbuf, 0, 0)

  

Pit 2: file name length

...... Well it should be, try.

D:\Music\Themes\Anison Piano ~marasy animation songs cover on piano~ marasy\marasy - Anison Piano ~marasy animation songs cover on piano~.wav

Ok? No special characters ah, why you still can not play it? (I did not write debug output, so if viewed as a black box, I only see the results can not be played.) The total length was significantly less than MAX_PATH , folder name and file name length is also normal.

See mciSendString () returns the string too much trouble, reasoning it.

You see, MCI is a long history of something, then ...... long history! A long history of something, in this case could affect, the strong possibility that the 8.3 file name (short file name).

It is also easy to handle. API Windows, the GetShortPathName () , do not reinvent the wheel.

strShortFilename = String$(MAX_PATH, vbNullChar)
Call GetShortPathName(FileName, strShortFilename, MAX_PATH)
strShortFilename = Strip(strShortFilename)
strSend = "OPEN " & Chr$(34) & strShortFilename & Chr$(34) & " ALIAS " & STRING_SOUND_ALIAS & " TYPE MPEGVIDEO"
Call mciSendString(strSend, rbuf, 0, 0)

  

(Note that the above code there is a pit. Without vbNullChar string "trimmed" to remove redundancy, it also can not be played. But I think it is not necessary singled out, put it on the brackets. )

go to sleep

At least with just a few sample to test, we have passed. Should be able to wake up this morning ...... then set the alarm to sleep.

This article is on when the memo Well ...... Tell me do not count on it ......

Finally supplement, MCI is actually calls the corresponding registered decoder to work, so in fact if the appropriate decoder installed, you can play audio files in the appropriate format. Of course, raw PCM waveform and sure to use native API that directly address the right ...... if Microsoft group of people do not think I have no idea ......

Reproduced in: https: //www.cnblogs.com/GridScience/p/3870946.html

Guess you like

Origin blog.csdn.net/weixin_34007291/article/details/93320227