VLC-based video player

VLC-based video player

I've been researching the video playback function recently. I used VideoView before. I looked it up online and it didn't seem very good. It supported relatively few formats. Nowadays, there are various formats of online videos. I felt that using VideoView to play them was very limited.

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

In the Media class, we can find that there are quite a lot of 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 by itself, 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. llOverlay = 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. //Usage steps  
  37. //***Step: Get the mPlayerView object through findViewById or new PlayerView()  
  38. //mPlayerView= new PlayerView(PlayerActivity.this);  
  39. mPlayerView = (PlayerView) findViewById(R.id.pv_video);
  40.  
  41. //Step 2: Set parameters in milliseconds  
  42. mPlayerView.setNetWorkCache( 20000 );
  43.  
  44. //Step 3: Initialize the player  
  45. mPlayerView.initPlayer(mUrl);
  46.  
  47. //Step 4: Set up event monitoring, monitor buffer progress, etc.  
  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 library

The library can be used in two ways:

*** Type, directly create a new PlayerView or embed the view in the xml of the layout file.

The second method is to jump to a pre-written playback page PlayerActivity (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)));

Through a selection list, click each item and pass a URL to PlayerActivity

Select 1.2JDK download.mp4 from the list

There is no problem switching between horizontal and vertical screens.

<<:  The third lecture on application performance management of Tingyun shared practical experience

>>:  What improvements did I make when I was refining an old project from a few years ago?

Recommend

This organism's genome is a 'mountain of DNA garbage', and it's growing

South American lungfish (Image credit: Katherine ...

iOS development: Inducing users to comment on your app

"Since my own app has few downloads and comm...

How to operate a good community? Share 2 tips!

What I want to share today is how to do a good jo...

Review of H5 fission growth case, 20,000 followers increased in 22 hours!

Every time there is a holiday, every time a star ...

How to improve conversion rate? Here are 9 suggestions for you!

A design change can increase website click-throug...

Insects are out in the summer, please be careful!

In the morning, walk through the foggy Chaotianme...