Use mcisendstring to create players that can play MPEG, Avi, WAV, MP3, etc.

Source: Internet
Author: User

Mcisendstring is an API command used to play multimedia files. It can play MPEG, Avi, WAV, MP3, etc. Here we will introduce 1.
Usage:
1. Open a multimedia file.
First, put a picture control on the dialog, and mcisendstring plays multimedia files on the plane of the picture control,
Set the picture Control ID to idc_static1:
Cstatic * pstatic = (cstatic *) getdlgitem (idc_static1); hwnd H = pstatic-> getsafehwnd ();
Cstring open1;
Char Buf [256];
Open1.format ("Open F: // MPEG // mpeg1.avi type mpegvideo alias movie parent % u style % u y", H, ws_child );
Mcisendstring (open1.getbuffer (open1.getlength (), Buf, sizeof (BUF), null );
In this way, mpeg1.avi In the mpeg directory under drive F is enabled, and the type mpegvideo indicates that the MPEG, Avi, and Other types are enabled.
Type mpegvideo: Open WAV, MP3, etc. Alias movie defines the alias of mpeg1.avi as movie.
You can operate mpeg1.avi by running movie.
2. Play multimedia files.
We have enabled F: "MPEG" mpeg1.avi above. Now let's play it:
Mcisendstring ("play movie", Buf, sizeof (BUF), null );
To play the video in full screen:
Mcisendstring ("play movie fullscreen", Buf, sizeof (BUF), null );
3. pause playback.
Mcisendstring ("Pause movie", Buf, sizeof (BUF), null );
4. Stop playing.
Mcisendstring ("Close movie", Buf, sizeof (BUF), null );
5. Obtain the length of the played file.
Char sposition [256]; long llength;
Mcisendstring ("status movie length", sposition, 255, 0); llength = strtol (sposition, null, 10 );
Llength indicates the length of the played file.
6. Obtain the sound size of the played file.
 
Char chvolume [256]; long lvolume; mcisendstring ("status movie
Volume ", chvolume, 255, 0); lvolume = strtol (chvolume, null, 10); among them, lvolume is the played File
The sound size of the component.
7. Play the video at the specified position.
Cstring Step1; long lposition;
Lposition = 100;
Step1.format ("Seek movie to % lD", lposition );
Mcisendstring (step1.getbuffer (step1.getlength (), Buf, sizeof (BUF), 0 );

Here, lposition is the desired playback position, which can be specified by you.
**************************************** **************************************** *******

As an MP3 player, the program memory occupied by realplay and WMP is too large.
If you only play MP3, we recommend that you use the API function mcisendstring. I will list the details of this function for your reference.
Option explicit
Private declare function mcisendstring lib "winmm. dll" alias "mcisendstringa" (byval lpstrcommand as string, byval
Lpstrreturnstring as string, byval ureturnlength as long, byval hwndcallback as long) as long
Mcisendstring is an API command used to play multimedia files. It can play MPEG, Avi, WAV, MP3, and so on. The following describes
Its Usage:
This function has four parameters:
The first parameter is the command string to be sent. The string structure is [command] [device alias] [command parameters].
The second parameter is the buffer of the returned information, which is a string variable with a specified size.
The third parameter is the buffer size, which is the length of the character variable.
Fourth parameter: callback method, usually set to zero
Return Value: if the function is successfully executed, zero is returned. Otherwise, an error code is returned.

I. Common commands
1. Open (Open). Format: open device name [type device type] [alias]
Dim mname as string
Mname = "F: // MPEG // mpeg1.avi"
Mcisendstring "Open mname type mpegvideo alias movie parent % u style % u y", 0 &, 0, 0
Where:
Open Operation Command
Mname full path file name
Type mpegvideo is used to enable the MPEG, Avi, and Other types. If this sentence is not added, it is used to open WAV, MP3, and so on.
Alias movie defines the operation alias as movie. You only need to specify the alias for subsequent operations.
Parent % u Source
Style % u Style
Notify notification
2. Play. Format: Play device name [from start point] [To End Point]
Mcisendstring "play movie", 0 &, 0, 0
Mcisendstring "play movie fullscreen", 0 &, 0, 0' full screen playback
3. Pause ):
Mcisendstring "Pause movie", 0 &, 0, 0
4. Continue (resume ):
Mcisendstring "resume movie", 0 &, 0, 0
5. Stop ):
Mcisendstring "Stop movie", 0 &, 0, 0
6. Close (colse ):
Mcisendstring "Close movie", 0 &, 0, 0
7. Move forward to the next position:
Mcisendstring "Step movie", 0 &, 0, 0
8. Move back to the previous position:
Mcisendstring "Step movie Reverse", 0 &, 0, 0
9. forward or backward n positions (n <0 indicates backward)
Mcisendstring "Step movie by" & STR (N), 0 &, 0, 0
10. Obtain the current playback position:
Dim st as string * 64
Mcisendstring "status movie position", St, Len (ST), 0
11. Get the total length of the media:
Mcisendstring "status movie length", St, Len (ST), 0
L = Val (ST) 'l is the length of the played File
12. Obtain the current playback status:
Dim st as string * 64
Mcisendstring "status movie mode", St, Len (ST), 0
If left (St, 7) = "STOPPED" then (Processing code) 'playing is complete
13. Loop playback:
Mcisendstring "play movie repeat", 0 &, 0, 0

2. Control the sound size (1-1000 ):
Dim V as long
Mcisendstring "status movie volume", & V, Len (v), and 0' V are the obtained volume values.
V = 50
Mcisendstring "setaudio movie volume to value", 0, 0, 0' V is the set volume value

3. Set the playback position (the time format must be set in advance). Format: Seek device name [to position | to START | to end]
Dim P1 as long, P2 as long
P1 = 100: P2 = 3000
Mcisendstring "Seek movie to", P1, 0, 0' P1 is the current starting position, in milliseconds
Mcisendstring "Seek movie to start", 0 &, 0, 0', locate the start position
Mcisendstring "play movie", 0 &, 0, 0' locate and play back
Or:
Mcisendstring "play movie from P1 to p2", 0 &, 0, 0' P1 is the start position, and P2 is the stop position. Unit: milliseconds
Mcisendstring "Seek movie to end", 0 &, 0, 0' locate to the last position

4. Play a video on a specified control:
Mcisendstring "Open AVI file name parent hwnd style child", 0 &, 0, 0
Hwnd is the control handle.
After executing the preceding command, the video is placed in the upper left corner of the control, and the size of the video is not affected by the size of the control.
The position and size of the video to play. You can run the PUT command before the play command is executed in the following format:
Mcisendstring "put AVI file name window at x y [width height]", 0 &, 0, 0
X and Y are the coordinates in the upper left corner of the video, and width and height are the width and height of the video.

5. You can control the brightness of a video (1-2000)
Dim B as long
Mcisendstring "status movie brightness", B, 0, 0' B is the obtained brightness value.
B = 50
Mcisendstring "setvideo movie brightness to" & B, & 0, 0, 0' B is the set Brightness Value

Vi. Recording settings:
Before recording, use the following statement to initialize
1. Set to 8 bits:
Mcisendstring "set wave bitpersample 8", "", 0, 0
2. Set to 11025Hz
Mcisendstring "set wave samplespersec 11025", "", 0, 0
3. Set to Stereo:
Mcisendstring "set wave Channels 2", "", 0, 0
4. PCM format implementation (incorrect ):
Mcisendstring "set wave format tag PCM", "", 0, 0
5. Start recording:
Mcisendstring "Close movie", 0 &, 0, 0
Mcisendstring "open new type waveaudio alias movie", 0 &, 0, 0
Mcisendstring "record movie", 0 &, 0, 0
6. Save the recording to C:/123.wav.
Mcisendstring "Stop movie", 0 &, 0, 0
Mcisendstring "Save Movie C: // 123.wav", 0 &, 0, 0
Mcisendstring "Close movie", 0 &, 0, 0

7. Optical Drive switch:
Mcisendstring "set cdaudio door open", "", 0, 0' open
Mcisendstring "set cdaudio door close", "", 0, 0' close

8. Others
1. Set various statuses of devices)
Set alias_name [Time Format MS]:
The SET command is used to set various statuses of the device, such as mute, sound, and time format.
2. Get the status of the device)
Status alias_name [length] [mode] [position]:
The status command is used to obtain the status of the device. For example, the length of the media file, the status of the media file, the current position of the media file, and the length of the media file.
The current location of the media file.
Reference code:
Tchar filename [] = "D: // your document // my

Music // famous tea shop ";
Tchar shortname [max_path];
Getinclupathname (filename, shortname, sizeof (shortname)/sizeof (tchar ));
Tchar cmd [max_path + 10];
Wsprintf (CMD, "Play % s", shortname );
Mcisendstring (CMD, "", null, null );
(You can call the first parameter of mcisendstring to pass the "play file full path". It is best to pass the absolute path to "file full path". We do not recommend passing the file name in the value of wanghepeng10.
In addition, if the file path contains spaces, use getmediapathname to convert it to a short path .)

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.