Developing a video player based on VLC SDK

Source: Internet
Author: User

In the Windows system if the development of universal player, generally is the basic DirectShow to develop, development is also very simple, but a lot of shortcomings, whether a file format can play depends entirely on whether you installed the correct parser and decoder, even if there is a universal solution installation package will also have a lot of problems, But since a lot of open source software, such as the famous FFMPEG,VLC and so on, everything has become simple, based on FFmpeg SDK development is not much introduced, this article mainly introduces the VLC SDK to develop their own player, everything is so simple.

1. First download VLC player, http://www.videolan.org/vlc/, install the Development Library (SDK) 2. VC 6.0/2003/2005/2008/2010 IDE can develop its own test program 3. Create a console program, of course, create a window program is better, because just to focus on how to use the VLC SDK, so it doesn't matter 4. Set up VLC's include and LIB paths in the project, General VLC SDK path is C: \ Program Files\videolan\vlc\sdk5. Copy the Libvlc.dll, Libvlccore.dll,plugins directory to the project debug directory, if the release needs to be copied to the release directory, the directory structure:

After that is the full code:  #include <stdio.h> #include <tchar.h> #include <time.h> #include <windows.h>   #include <vlc/vlc.h> #pragma comment (lib, "Libvlc.lib") #pragma comment (lib, "Libvlccore.lib")  int Main (int argc, char* argv[]) {libvlc_instance_t *     vlc_ins    = null;libvlc_media_player_t * VLC_PLA Yer = null;libvlc_media_t *        vlc_media  = null; const char * vlc_args[] = {"-I", " Dummy ","--ignore-config ","--extraintf=logger ","--verbose=2 ", };   //creates a VLC instance vlc_ins = libvlc_new (sizeof (Vlc_args)/sizeof (Vlc_args[0]), Vlc_args); if (vlc_ins! = NULL) {// Create a VLC Player Vlc_player = libvlc_media_player_new (Vlc_ins), if (vlc_player! = NULL) {//Create a media instance through a file path, here is my test file Vlc_media = Libvlc_media_new_path (Vlc_ins, "D:\\clips\\org.mp4"), if (vlc_media! = NULL) {//Parse Media instance Libvlc_media_parse (Vlc_media) ;//Get the playback length of the media file,   return mslibvlc_time_t duration = libvlc_media_get_duration (vlc_media);  //here is to get the media containing multiple viewFrequency and audio tracks and other types of track information libvlc_media_track_info_t *media_tracks = Null;int Trackcount = Libvlc_media_get_tracks_info (vlc_ Media, &media_tracks);//Here is the release of memory, but I test the time there will be a problem, have not carefully studied why//free (media_tracks);  //crash? //Set the open media file to the player Libvlc_media_player_set_media (Vlc_player, Vlc_media);  //because it's a Windows system, So need to set an HWND to the player as a window, here directly using the Desktop window, here is only the test Libvlc_media_player_set_hwnd (Vlc_player,:: GetDesktopWindow ());// Start playing video Libvlc_media_player_play (Vlc_player);  //here only to print some information out, after 20 seconds exit time_t Last_time = time (NULL); (NULL) < (Last_time +)) {Sleep (10);//get current playback position libvlc_time_t Play_time = libvlc_media_player_get_time (Vlc_player) ;p rintf ("Playing time:%lld ms\r", (__int64) (play_time));  //get the status of media//libvlc_state_t media_state = Libvlc_media_ Get_state (Vlc_media);//printf ("\nmedia State:%d\n", (int) (media_state));} Stop Libvlc_media_player_stop (Vlc_player);//Release libvlc_media_release (Vlc_media);} Release Libvlc_media_player_release (Vlc_player);}
Release Libvlc_release (vlc_ins);} return 0;}  Compile and run, you can see the video playing on the desktop, with the VLC SDK to do their own player is so simple. VLC SDK how to know VLC has been playing the end, anxious.

I have embedded the VLC SDK into MFC to play the video, but want to know the status of the video playback, is to know when the end.

------Solution--------------------------------------------------------
There's a libvlc_media_player_get_state. A function that gets the playback state, if returned libvlc_ended, indicates that the video has finished playing.

Developing a video player based on VLC SDK

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.