The simplest LIBVLC-based example: The simplest LIBVLC-based video player

Source: Internet
Author: User

http://blog.csdn.net/leixiaohua1020/article/details/42363079The simplest LIBVLC-based example: The simplest LIBVLC-based video playerTags: LIBVLCVLC player development2015-01-08 22:33 18091 people read review (+) collection report Classification:VLC (2)My Open Source project ($)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directory (?) [+]

=====================================================

The simplest LIBVLC-based example article list:

The simplest LIBVLC-based example: The simplest LIBVLC-based video player

The simplest LIBVLC-based example: The simplest LIBVLC-based video player (graphical interface version)

The simplest LIBVLC-based example: The simplest LIBVLC-based ejector

=====================================================

This document documents the simplest example of video player development using LIBVLC. VLC Media Player is an excellent player, but because of the difficulty of compiling the source code, it has not researched its development technology in depth. Having touched some of the VLC development stuff, I summarized the LIBVLC Development sample program.

How to obtain the library files required for the SDKVLC development of VLC There are 2 ways to get it:
1. Self-compiling
2. Copy it directly from the installation directory


The first method is much more difficult. In particular, compiling VLC under Windows is a tricky thing to do. In general, you can choose the second method to get the files needed for VLC development.
The location of the files needed to develop VLC:
1. Dynamic link library *.dll: Libvlc.dll,libvlccore.dll in the installation directory and all files in the plugins directory.
PS:VLC supports very many plugin. So the volume of the plugins directory is really very large.
2. Static link library *.lib: installation directory/sdk/lib
3. header file *.h: installation directory/sdk/include

After you create a VC project, copy the above three categories of files to the new project directory, and configure their paths, you can use LIBVLC for development.

The simplest LIBVLC-based video player

It is very easy to develop a player using LIBVLC. The simplest LIBVLC-based video player flowchart is shown.

The flowchart contains 3 structures:
libvlc_instance_t: Represents an instance of a LIBVLC.
Libvlc_media_t: Represents a media that can be played.
libvlc_media_player_t: Represents a VLC media player (a video player plays a video). Note that VLC is not just for media playback.
Create or above 3 structures through the following 6 functions:
libvlc_new (): Create libvlc_instance_t.
Libvlc_media_new_path (): Create libvlc_media_t.
Libvlc_media_player_new_from_media (): Create libvlc_media_player_t.
Libvlc_media_player_release (): Release libvlc_media_player_t
Libvlc_media_release (): Release libvlc_media_t.
Libvlc_release (): Release libvlc_instance_t.
You can control the playback or pause of the media by using the following function, which requires libvlc_media_player_t as a parameter. For the purpose of simplification, only the play and stop functions are used:
Libvlc_media_player_play (): Play.
Libvlc_media_player_pause (): Paused.
Libvlc_media_player_stop (): Stop.
In addition to the above 3 functions, there are functions such as libvlc_media_player_set_position (), which are not recorded here.

Several considerations libvlc_media_t creation of libvlc_media_t There are two methods: Libvlc_media_new_path () and Libvlc_media_new_location (). Briefly describe the difference between these two functions: Libvlc_media_new_location () is used to open the Protocol, and Libvlc_media_new_path () is used to open the file. Thus passed to Libvlc_media_new_path () is the normal file path (absolute path such as D:\xxx.flv, or relative path such as xxx.flv), and passed to Libvlc_media_new_location () is the protocol address (for example, "udp://...", "http://"). But one thing to note here is that the "file" in VLC also belongs to a generalized "protocol". Therefore, you can also open the file with Libvlc_media_new_location (), but you must precede the file path with the tag "file:///" of the file protocol. For example, to open the video under "F:\movie\cuc_ieschool.flv", the actual code used is as follows.
[CPP]View PlainCopy  
    1. Libvlc_media_new_location (Inst, "file:///f:\\movie\\cuc_ieschool.flv");
In addition, VLC supports a lot of "magic" protocols, such as entering the "screen://" protocol to screen recording, the code is as follows.
[CPP]View PlainCopy 
    1. Libvlc_media_new_location (Inst, "screen://");

Embed the LIBVLC pop-up window into the program here I have only practiced windows to embed the LIBVLC pop-up window into the program. Pass the handle of the window or control to the Libvlc_media_player_set_hwnd () function.
One thing to note here is that if you embed the LIBVLC pop-up window in the program, the "fullscreen" feature is not available.

Questions about LIBVLC loading can be LIBVLC through Libvlc_media_player_get_length (), Libvlc_video_get_width (), Libvlc_video_get_height () Such functions get the length, width, and high information of the video. But there is a strange phenomenon: if the above 3 functions are called immediately after Libvlc_media_player_play () is called, the value returned is 0, and the function is called only after "waiting" for a period of time (for example, call Sleep ()) to get the correct value. For this phenomenon, I think it might be that the LIBVLC load is complete before you can get the correct values from the above functions (I guess, not yet).

Code

[CPP]View PlainCopy 
  1. /**
  2. * The simplest LIBVLC-based player
  3. * Simplest LIBVLC Player
  4. *
  5. * Lei Hua Lei Xiaohua
  6. * [Email protected]
  7. * Communication University/Digital TV Technology
  8. * Communication University of China/digital TV Technology
  9. * http://blog.csdn.net/leixiaohua1020
  10. *
  11. * This program is one of the simplest video player based on LIBVLC.
  12. * Suitable for beginners to learn LIBVLC.
  13. *
  14. * This example are the simplest Video Player based on LIBVLC.
  15. * Suitable for the beginner of LIBVLC.
  16. */
  17. #include <Windows.h>
  18. #include "vlc/vlc.h"
  19. int main (int argc, char* argv[])
  20. {
  21. libvlc_instance_t * INST;
  22. libvlc_media_player_t *mp;
  23. libvlc_media_t *m;
  24. libvlc_time_t length;
  25. int width;
  26. int height;
  27. int wait_time=5000;
  28. //libvlc_time_t length;
  29. / * Load the VLC engine * /
  30. Inst = libvlc_new (0, NULL);
  31. //create a new item
  32. //method 1:
  33. //m = libvlc_media_new_location (Inst, "file:///f:\\movie\\cuc_ieschool.flv");
  34. //screen Capture
  35. //m = libvlc_media_new_location (Inst, "screen://");
  36. //method 2:
  37. m = Libvlc_media_new_path (Inst, "cuc_ieschool.flv");
  38. / * Create a Media Player playing environement * /
  39. MP = Libvlc_media_player_new_from_media (m);
  40. / * No need to keep the media now * /
  41. Libvlc_media_release (m);
  42. //Play the Media_player
  43. Libvlc_media_player_play (MP);
  44. //wait until the tracks is created
  45. _sleep (wait_time);
  46. Length = Libvlc_media_player_get_length (MP);
  47. width = Libvlc_video_get_width (MP);
  48. Height = Libvlc_video_get_height (MP);
  49. printf ("Stream Duration:%ds\n", length/1000);
  50. printf ("Resolution:%d x%d\n", width,height);
  51. //let It play
  52. _sleep (Length-wait_time);
  53. //Stop playing
  54. Libvlc_media_player_stop (MP);
  55. // Free the Media_player
  56. Libvlc_media_player_release (MP);
  57. Libvlc_release (inst);
  58. return 0;
  59. }


Run results

After the program runs, a window pops up to play the "cuc_ieschool.flv" file.

Download

Simplest LIBVLC Example

Project Home

sourceforge:https://sourceforge.net/projects/simplestlibvlcexample/

Github:https://github.com/leixiaohua1020/simplest_libvlc_example

Open source China: http://git.oschina.net/leixiaohua1020/simplest_libvlc_example

cdsn:http://download.csdn.net/detail/leixiaohua1020/8342413


This project is comprised of some sample programs based on LIBVLC. The following sub-programs are included altogether.
Playergui: The simplest LIBVLC-based player-graphical interface version.
Simplest_libvlc_example: The simplest LIBVLC-based player.
Simplest_libvlc_streamer: The simplest LIBVLC-based push-to-flow device.

The simplest LIBVLC-based example: The simplest LIBVLC-based video player

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.