In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today Xiaobian to share with you how to use IJKPlayer video player in Android related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you have read this article after harvest, let's learn about it together.
1. Encapsulate the playback kernel
We all know that there are three processes required to play a video 1. create MediaPlayer 2. MediaPlayer prepare 3. MediaPlayer binds to Surface
Xinvideplayer uses VideoManager to control all operations of ijkmediaplayer
Three processes We use HandlerThread + Hander to implement the first process creation may take about 100ms, seriously affecting the UI thread!!!
The first process: create MediaPlayer
new IjkMediaPlayer() Set some player callback methods
//IJK's Medialayer api is similar to the Android system player api//IMediaPlayer.classpublic interface IMediaPlayer{ void setOnPreparedListener (IMediaPlayer.OnPreparedListener var1); //prepareAsync callback method void setOnCompletionListener (IMediaPlayer.OnCompletionListener var1); //playback completion callback method void setOnBufferingUpdateListener (IMediaPlayer.OnBufferingUpdateListener var1);//void setOnSeekCompleteListener when the buffer for playing the network data stream changes (IMediaPlayer.OnSeekCompleteListener var1);//void setOnVideoSizeChangedListener when seek is complete (IMediaPlayer.OnVideoSizeChangedListener var1);//void setOnErrorListener when video size is first known or changed (IMediaPlayer.OnErrorListener var1);//void setOnInfoListener when an error occurs (IMediaPlayer.OnInfoListener var1);//void setOnTimedTextListener(IMediaPlayer.OnTimedTextListener var1) when there is a message or warning; //when media time data needs to be displayed}
Second stage prepare
mediaPlayer.prepareAsync(); waiting for callback IMediaPlayer.OnPreparedListener#onPrepare()
The third stage binds the Surface rendering screen to IJK Media Player
mediaPlayer.setSurface();
2. Player View
Implement basic player methods (IViewPlayer) and playback kernel callback methods (IMediaPlayerListener)
IMediaPlayerListener is implemented by wrapping all interfaces of IMediaPlayer and sending them to the main thread through Handle
//IVideoPlayer.javainterface IVideoPlayer{ void start();//void pause();//void seekTo (long time); //seekto time void release();//close playback void setVideoPath();//set video path void onStartFullScreen ();//full screen playback void onBackFullScreen(); //exit full screen void onResumeVideo();//player background evokes void onPauseVideo();//toggle background int getCurrentState();//current status int getCurrentScreenState(); //current screen status e.g. small screen, large screen, portrait long getTcpSpeed();//get network speed void switchVideoSource (String url,long delay);//toggle clarity and smooth switching}public interface MediaPlayerListenerextends IVideoPlayer{ void onPrepared(); void onAutoCompletion(); void onCompletion(); void onBufferingUpdate (int percent); void onSeekComplete(long currentPosition); void onError(int what, int extra); void onInfo(int what, int extra); void onVideoSizeChanged();}
The above interfaces roughly meet the functional requirements of all players!!
3.MediaController
public interface IVideoController{ //ViewbindPlayer as its name implies (IVideoPlayer player); void onChangeVideoStatus (IVideoPlayer player,int old_status, int new_status); void onChangeScreenStatus (IVideoPlayer player,int old_status, int new_status); boolean onChangedNetWork (int currentNetState); void onVideoProgress (int percent, long curr_position, long duration); void unbindPlayer (IVideoPlayer player); boolean isLock(); void onVideoDefinitionSwitched(); void show(); void hide(); boolean isShowing();
BaseVideoPlayer#setVideoController()
Simple access to the player
videoplayer.setVideoPath(url); videoplayer.start();//Start playback//If background pause is needed, resume playback videoplayer.onVideoResume();videoplayer.onVideoPause();//If background pause is needed, resume playback in full screen. Control the Back button. Question: if (! VideoPlayerUtils.onBackPressed()) { //normal logic returned}...
Internal implementation of the player
Preloading Requirements & Multiplexing Player
Intelligent background & evocation processing
That's all for "How to use IJKPlayer in Android", thanks for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.