VLC-Based Video Player

Source: Internet
Author: User

VLC-Based Video Player

I recently studied the video playback function, which was previously used by VideoView. After reading the video on the internet, I feel that it is not very good, and the supported formats are relatively small. Now there are various formats of online videos, and I feel that it is very limited to play with VideoView.

Found a suitable player, Github address for https://github.com/xiaomo/AndroidPlayerLibrary. This player is based on the vlc software. After importing our demo to Eclipse, We can find such a libvlc folder.

In the Media class, we can find that there are many supported formats.

 
 
  1. String[] video_extensions = { 
  2.                 ".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".drc", ".dv", 
  3.                 ".f4v", ".flv", ".gvi", ".gxf", ".ismv", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts", 
  4.                 ".m4v", ".mkv", ".mov", ".mp2", ".mp2v", ".mp4", ".mp4v", ".mpe", ".mpeg", 
  5.                 ".mpeg1", ".mpeg2", ".mpeg4", ".mpg", ".mpv2", ".mts", ".mtv", ".mxf", ".mxg", 
  6.                 ".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb", 
  7.                 ".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc" }; 
  8.  
  9. String[] audio_extensions = { 
  10.                 ".3ga", ".a52", ".aac", ".ac3", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".amr", 
  11.                 ".aob", ".ape", ".awb", ".caf", ".dts", ".flac", ".it", ".m4a", ".m4b", ".m4p", 
  12.                 ".mid", ".mka", ".mlp", ".mod", ".mpa", ".mp1", ".mp2", ".mp3", ".mpc", ".mpga", 
  13.                 ".oga", ".ogg", ".oma", ".opus", ".ra", ".ram", ".rmi", ".s3m", ".spx", ".tta", 
  14.                 ".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" }; 

In this example, it writes a PlayerActivity and PlayerView, and implements the IVideoPlayer interface in libvlc in PlayerView.

Implement the PlayerView class in PlayerActivity to control the interface and process.

 
 
  1. Protected void onCreate (Bundle savedInstanceState ){
  2. Super. onCreate (savedInstanceState );
  3. MUrl = getIntent (). getStringExtra ("url ");
  4. If (TextUtils. isEmpty (mUrl )){
  5. Toast. makeText (this, "error: no url in intent! ", Toast. LENGTH_SHORT). show ();
  6. Return;
  7. }
  8. RequestWindowFeature (Window. FEATURE_NO_TITLE );
  9. GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN, WindowManager. LayoutParams. FLAG_FULLSCREEN );
  10.  
  11. SetContentView (R. layout. activity_player );
  12.  
  13. MHandler = new Handler (this );
  14.  
  15. TvTitle = (TextView) findViewById (R. id. TV _title );
  16. TvTime = (TextView) findViewById (R. id. TV _time );
  17. TvLength = (TextView) findViewById (R. id. TV _length );
  18. SbVideo = (SeekBar) findViewById (R. id. sb_video );
  19. SbVideo. setOnSeekBarChangeListener (this );
  20. IbLock = (ImageButton) findViewById (R. id. ib_lock );
  21. IbLock. setOnClickListener (this );
  22. IbBackward = (ImageButton) findViewById (R. id. ib_backward );
  23. IbBackward. setOnClickListener (this );
  24. IbPlay = (ImageButton) findViewById (R. id. ib_play );
  25. IbPlay. setOnClickListener (this );
  26. IbFarward = (ImageButton) findViewById (R. id. ib_forward );
  27. IbFarward. setOnClickListener (this );
  28. IbSize = (ImageButton) findViewById (R. id. ib_size );
  29. IbSize. setOnClickListener (this );
  30.  
  31. Loverlay = findViewById (R. id. ll_overlay );
  32. RlOverlayTitle = findViewById (R. id. rl_title );
  33.  
  34. RlLoading = findViewById (R. id. rl_loading );
  35. TvBuffer = (TextView) findViewById (R. id. TV _buffer );
  36. // Procedure
  37. // Step 1: Use findViewById or new PlayerView () to obtain the mPlayerView object
  38. // MPlayerView = new PlayerView (PlayerActivity. this );
  39. MPlayerView = (PlayerView) findViewById (R. id. pv_video );
  40.  
  41. // Step 2: Set the parameter in milliseconds
  42. MPlayerView. setNetWorkCache (20000 );
  43.  
  44. // Step 3: Initialize the player
  45. MPlayerView. initPlayer (mUrl );
  46.  
  47. // Step 4: Set event listening and monitor the buffer progress.
  48. MPlayerView. setOnChangeListener (this );
  49.  
  50. // Step 5: start playing
  51. MPlayerView. start ();
  52.  
  53. // Init view
  54. TvTitle. setText (mUrl );
  55. ShowLoading ();
  56. HideOverlay ();
  57.  
  58. }

How to use this class library

Library:

First, directly add a new PlayerView or embed the view in the xml of the layout file.

Second, jump to a prepared PlayerActivity page (local file parameter format: file: // sacard/test. rmvb .)

Here I chose the second method.

 
 
  1. startActivity(new Intent(this, PlayerActivity.class).putExtra("url", items.get(position))); 

Click each item in the form of a selection list and pass a url to PlayerActivity.

Select 1.2jdkdownload .mp4

There is no problem with switching between landscape and landscape screens.

Related Article

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.