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.
- String[] video_extensions = {
- ".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".drc", ".dv",
- ".f4v", ".flv", ".gvi", ".gxf", ".ismv", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts",
- ".m4v", ".mkv", ".mov", ".mp2", ".mp2v", ".mp4", ".mp4v", ".mpe", ".mpeg",
- ".mpeg1", ".mpeg2", ".mpeg4", ".mpg", ".mpv2", ".mts", ".mtv", ".mxf", ".mxg",
- ".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb",
- ".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc" };
-
- String[] audio_extensions = {
- ".3ga", ".a52", ".aac", ".ac3", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".amr",
- ".aob", ".ape", ".awb", ".caf", ".dts", ".flac", ".it", ".m4a", ".m4b", ".m4p",
- ".mid", ".mka", ".mlp", ".mod", ".mpa", ".mp1", ".mp2", ".mp3", ".mpc", ".mpga",
- ".oga", ".ogg", ".oma", ".opus", ".ra", ".ram", ".rmi", ".s3m", ".spx", ".tta",
- ".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.
- Protected void onCreate (Bundle savedInstanceState ){
- Super. onCreate (savedInstanceState );
- MUrl = getIntent (). getStringExtra ("url ");
- If (TextUtils. isEmpty (mUrl )){
- Toast. makeText (this, "error: no url in intent! ", Toast. LENGTH_SHORT). show ();
- Return;
- }
- RequestWindowFeature (Window. FEATURE_NO_TITLE );
- GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN, WindowManager. LayoutParams. FLAG_FULLSCREEN );
-
- SetContentView (R. layout. activity_player );
-
- MHandler = new Handler (this );
-
- TvTitle = (TextView) findViewById (R. id. TV _title );
- TvTime = (TextView) findViewById (R. id. TV _time );
- TvLength = (TextView) findViewById (R. id. TV _length );
- SbVideo = (SeekBar) findViewById (R. id. sb_video );
- SbVideo. setOnSeekBarChangeListener (this );
- IbLock = (ImageButton) findViewById (R. id. ib_lock );
- IbLock. setOnClickListener (this );
- IbBackward = (ImageButton) findViewById (R. id. ib_backward );
- IbBackward. setOnClickListener (this );
- IbPlay = (ImageButton) findViewById (R. id. ib_play );
- IbPlay. setOnClickListener (this );
- IbFarward = (ImageButton) findViewById (R. id. ib_forward );
- IbFarward. setOnClickListener (this );
- IbSize = (ImageButton) findViewById (R. id. ib_size );
- IbSize. setOnClickListener (this );
-
- Loverlay = findViewById (R. id. ll_overlay );
- RlOverlayTitle = findViewById (R. id. rl_title );
-
- RlLoading = findViewById (R. id. rl_loading );
- TvBuffer = (TextView) findViewById (R. id. TV _buffer );
- // Procedure
- // Step 1: Use findViewById or new PlayerView () to obtain the mPlayerView object
- // MPlayerView = new PlayerView (PlayerActivity. this );
- MPlayerView = (PlayerView) findViewById (R. id. pv_video );
-
- // Step 2: Set the parameter in milliseconds
- MPlayerView. setNetWorkCache (20000 );
-
- // Step 3: Initialize the player
- MPlayerView. initPlayer (mUrl );
-
- // Step 4: Set event listening and monitor the buffer progress.
- MPlayerView. setOnChangeListener (this );
-
- // Step 5: start playing
- MPlayerView. start ();
-
- // Init view
- TvTitle. setText (mUrl );
- ShowLoading ();
- HideOverlay ();
-
- }
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.
- 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.