Two pitfalls of mcisendstring

Source: Internet
Author: User

I just corrected my own small alarm code.

Pit1: Scope of the repeat Option

I used to use it well, and then I chose the. Wav file, so there was no sound ......

Well, MCI certainly supports. wav ......

Think about it. I used to select. MP3 as the alarm. Is it related to this?

View the source code.

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

  

In order to wake me up from my sleep (in general, I am sleep very badly ......), I chose the repeat option for loop playback.

Well, yes. I remember where I read it. The repeat option of the play command can only work on mpegvideo files. (The time is so late. I want to go to bed after recording the records, so I will not find the reference source .)

It's easy to open as mpegvideo.

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

  

Pit 2: File Name Length

Okay ...... Come on, give it a try.

D: \ music \ themes \ anison piano ~ Marasy animation songs cover on piano ~ Marasy \ marasy-anison piano ~ Marasy animation songs cover on piano ~. Wav

Hmm? There are no special characters. Why can't I play it? (I didn't write debugging output, so if I think of it as a black box, I can only see the results that cannot be played .) The total length is also significantly smaller than max_path, And the folder name and file name length are also normal.

It is too troublesome to look at the returned string of mcisendstring.

You see, MCI is a long history, so ...... Long history! In this case, a long history can cause an impact. The possibility is that the file name is 8.3 (short file name ).

That's fine. Windows API, getmediapathname (), 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: The above code has a small pitfall. If you do not trim the redundant vbnullchar string, it cannot be played. But I don't think it is necessary to put it in the brackets .)

Go to bed

At least a few samples have been used for testing and all of them have passed. Should I be able to wake up this morning ...... Set the alarm and go to bed.

This article should be a memorandum ...... Don't hold too much hope ......

Finally, it is added that the MCI actually calls the corresponding registered decoder to work. Therefore, if the corresponding decoder is installed, the audio files in the corresponding format can be played. Of course, raw PCM and waveform must be directly resolved using native APIs ...... If the people at Microsoft don't think so, I can't ......

Two pitfalls of mcisendstring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.