The configuration of VLC SDK in VS2010 and simple use example

Source: Internet
Author: User

1. Download vlc-2.2.0-win32.7z from http://www.videolan.org/vlc/download-windows.html and unzip;

2. Create a new vlctest console project;

3. Add the/vlc-2.2.0-win32/vlc-2.2.0/sdk/include to the project properties,-->general-C + + Additional Include directories;

4. Copy the Libvlc.lib, Libvlc.dll, Libvlccore.lib, Libvlccore.dll and plugins directories in the/vlc-2.2.0-win32/vlc-2.2.0/to the project execution directory;

5. The code for each file in the Vlctest project is:

StdAfx.h:

#pragma once#include "targetver.h" #include <stdio.h> #include <time.h> #include <windows.h> #include <vlc/vlc.h>

Stdafx.cpp:

#include "stdafx.h" #ifdef _debug#pragma comment (lib, "... /.. /.. /lib/dbg/x86_vc10/libvlc.lib ") #pragma comment (lib,". /.. /.. /lib/dbg/x86_vc10/libvlccore.lib ") #else #pragma comment (lib," ... /.. /.. /lib/rel/x86_vc10/libvlc.lib ") #pragma comment (lib,". /.. /.. /lib/rel/x86_vc10/libvlccore.lib ") #endif

VLCtest.cpp:

#include "stdafx.h" #include <iostream>using namespace std;void test1 () {libvlc_instance_t* vlc_ins = null;libvlc_ media_player_t* Vlc_player = null;libvlc_media_t* Vlc_media = Null;const char* vlc_args[] = {"-I", "dummy", "--ignore-con  Fig ","--extraintf=logger ","--verbose=2 "}; To create a VLC instance, the release version here will crashvlc_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 via file path Vlc_media = Libvlc_media_new_path (Vlc_ins, "F:\\photo\\wp_20140405_002.mp4"), if (vlc_media! = NULL) {//Parse Media instance Libvlc_media_parse (vlc_media);//Gets the playback length of the media file, returns mslibvlc_time_t duration = Libvlc_media_get_duration (vlc_media);// Here is the capture media containing multiple video and audio tracks as well as 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 problems, 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 is a Windows system, it is necessary 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);//This is just to print some information out, 20 seconds after exiting time_t last_time = time ( NULL), while ((Time (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 state of the media//libvlc_state_t media_state = Libvlc_media_get_state (Vlc_media);//printf ("\nmedia State:%d\n", (int) (media_state));} Libvlc_media_player_stop (Vlc_player);//Stop Libvlc_media_release (Vlc_media);//Release}libvlc_media_player_release (vlc_ player);//Release}libvlc_release (vlc_ins);//Release}}void test2 () {libvlc_instance_t* inst;libvlc_media_player_t* mp;libvlc_ media_t* m;//init VLC modules, should be do only onceinst = libvlc_new (0, NULL);//create a new Itemm = Libvlc_media_new_ Path (Inst, "F:\\photo\\wp_20140405_002.mp4");//create a media player playing environmentmp = Libvlc_media_plaYer_new_from_media (m); Libvlc_media_parse (m); libvlc_time_t duration = Libvlc_media_get_duration (m);//no need to keep  The media nowlibvlc_media_release (m); #if 0//this is a non working code then show how to hooks into a window,//if we have a Window around//libvlc_drawable_t drawable = xdrawable;//or on windowsvoid *drawable = &g_hwnd;libvlc_media_player_ Set_hwnd (MP, drawable), #endif//Play the Media_playerlibvlc_media_player_play (MP); Sleep ((DWORD) duration); Let it play a bit//stop playinglibvlc_media_player_stop (MP);//Free The Media_playerlibvlc_media_player_release (MP); Libvlc_release (inst);} int main (int argc, char* argv[]) {//test1 (); Test2 ();cout<< "ok!" <<endl;return 0;}

6. after testing, test1 () and Test2 () in the debug mode can be normal operation, under release will be crash, are executed to the Libvlc_new function there is a problem, the specific reasons are unclear, the latter will be further analyzed.

The above test code comes from:

1. http://blog.sina.com.cn/s/blog_62949ff40101edml.html

2. http://www.360doc.com/content/14/0309/10/2036337_358957305.shtml


The configuration of VLC SDK in VS2010 and simple use example

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.