Mplayer has been packaged with MFC for player use. However, VLC is a little dominant in playing network video streams. I studied it.
The compilation process is troublesome, and there are many examples on the Internet. Here we only talk about how to call libvlc. DLL without compiling. (To quickly compile, you can download some of the compiled binary files provided by the official website ).
For convenience, install VLC directly, copy libvlccore. dll and libvlc. dll, and all DLL files under plugins.
Then, use the tool provided by Ms to export lib from DLL, or directly use dll2lib (For details, refer to Google)
Download the VLC source code and find the include folder from it, all of which are copied to the project directory.
Then, use vc2005 to create a new MFC dialog box project (vc6 can also be used, but some macro definitions need to be modified, and 2005 will be used for convenience ).
The above in stdafx. H is as follows:
# Include "VLC/VLC. H"
# Include "VLC/libvlc. H"
# Pragma comment (Lib, "libvlc. lib ")
# Pragma comment (Lib, "libvlccore. lib ")
(You have included the include directory in the project> Properties> C ++> General, so you can directly include "VLC..." above ...")
The project may prompt that there is nothing to define. You just need to manually add it to view the situation on your own. Because the source code is updated every day, the situation is not the same.
Then run the official example:
Int main1 (char * file)
{
Const char * const vlc_args [] = {
"-I", "Dummy",/* don't use any interface */
"-- Ignore-config",/* don't use VLC's config */
"-- Vout DirectX ",
"-- Plugin-Path =/set/Your/path/to/libvlc/module/If/you/ARE/on/Windows/or/MacOSX "};
Libvlc_exception_t ex;
Libvlc_instance_t * inst;
Libvlc_media_player_t * MP;
Libvlc_media_t * m;
Libvlc_exception_init (& Ex );
/* Init VLC modules, shocould be done only once */
Inst = libvlc_new (sizeof (vlc_args)/sizeof (vlc_args [0]), vlc_args, & Ex );
Raise (& Ex );
/* Create a new item */
M = libvlc_media_new (Inst, file, & Ex );
Raise (& Ex );
/* XXX: Demo art and meta information fetching */
/* Create a media player playing environement */
MP = libvlc_media_player_new_from_media (M, & Ex );
Raise (& Ex );
/* No need to keep the media now */
Libvlc_media_release (m );
# If 0
/* This is a non working code that show how to hooks into a window,
* If we have a window around und */
Libvlc_drawable_t drawable = xdrawable;
/* Or on Windows */
Libvlc_drawable_t drawable = hwnd;
Libvlc_media_player_set_drawable (MP, drawable, & Ex );
Raise (& Ex );
# Endif
/* Play the media_player */
Libvlc_media_player_play (MP, & Ex );
Raise (& Ex );
Sleep (10);/* Let it play a bit */
/* Stop playing */
Libvlc_media_player_stop (MP, & Ex );
/* Free the media_player */
Libvlc_media_player_release (MP );
Libvlc_release (insT );
Raise (& Ex );
Return 0;
}
Change the value of -- Plugin-path and libvlc_media_new as needed.
Add the file selection in the dialog box, and then call main1 (char *).
Compile and run. A new window is displayed, indicating that the selected media file is successfully called.
Like mplayer, VLC supports separate window embedding in the specified window:
Create a static object in the dialog box, for example, idc_static_video.
Then, replace the following # If 0 statements:
Libvlc_drawable_t drawable = (libvlc_drawable_t) (getdlgitem (idc_static_play)-> getsafehwnd ());
Libvlc_media_player_set_drawable (MP, drawable, & Ex );
Raise (& Ex );
Change # If 0 to # If 1, compile and run it, and the video is displayed in the specified window.
Basically, the prototype of a player comes out, and some additional controls, such as pause and stop:
Libvlc_media_player_pause (MP, & Ex );
Libvlc_media_player_stop (MP, & Ex );
Fast forward, fast return, seek, etc.
Libvlc_media_player_set_rate ()
Libvlc_media_player_get_state
Libvlc_toggle_fullscreen
Libvlc_video_set_aspect_ratio
Libvlc_media_player_get_position
Libvlc_media_player_set_position
Libvlc_media_player_get_time
Use the following series of functions.
Like mplayer, VLC also has some advanced usage, such as adding a video filter. After you have completed the basic player, you can study this.
The most powerful function of VLC is the playing of video streams on the network. If you play a local file, it is better to study the advanced functions of mplayer.
In addition, the above only demonstrates the use of the SDK. There are still many problems in this way. The message loop in the SDK affects the UI calls outside, so you should add the thread or peekmessage to process it yourself.