Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the video player based on VLC

Shulou Source: shulou.com Published: 2022-06-02 10:05:34 09月11日 Update

In this issue, Xiaobian will bring you about how to understand VLC based video players. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.

Recently, I have been studying the video playback function, and before that, I used VideoView. On the Internet to see a bit, feeling is not very good, support the format is relatively small, and now the network video format of a variety of, feeling with VideoView playback limitations.

Found a more suitable player, Github address https://www.example.com. github.com/xiaomo/AndroidPlayerLibrary This player is based on vlc this software, after importing our demo into Eclipse, you can find such a libvlc folder.

In the Media class we can see whether these are supported formats or more.

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 its own PlayerActivity and PlayerView, implementing 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); llOverlay = findViewById(R.id.ll_overlay); rlOverlayTitle = findViewById(R.id.rl_title); rlLoading = findViewById(R.id.rl_loading); tvBuffer = (TextView) findViewById(R.id.tv_buffer); //Use steps //** * Step: Get mPlayerView object by findViewById or new PlayerView() //mPlayerView= new PlayerView(PlayerActivity.this); mPlayerView = (PlayerView) findViewById(R.id.pv_video); //Step 2: Set parameters in milliseconds mPlayerView.setNetWorkCache(20000); //Step 3: Initialize the player mPlayerView.initPlayer(mUrl); //Step 4: Set up event listening, listening buffer progress, etc. mPlayerView.setOnChangeListener(this); //Step 5: Start playing mPlayerView.start(); //init view tvTitle.setText(mUrl); showLoading(); hideOverlay(); }

About how to use this library

Library is used in two ways:

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

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

Here I choose the second option.

startActivity(new Intent(this, PlayerActivity.class).putExtra("url", items.get(position))); Pass a url to PlayerActivity by clicking on each item in a selection list

Select 1.2 JDK Download.mp4 from the list

There is no problem switching between horizontal and vertical screens.

The above is how to understand VLC based video player shared by Xiaobian for everyone. If there is a similar doubt, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.

Tags: Player video format file selection content parameter feeling realistic analysis support monitoring appropriate large small and medium event example rich content function unit Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Linux Redmi vpn