The video player is based on Bilibili’s open source project iJkPlayer, which builds a playback interface based on a Github demo. If you have studied the demo code before, the library should be very simple. Ijkplayer is the most popular open source video player on Github. There are a lot of references to ijkPlayer on github.

I scraped a lot of ICONS from Bilibili client to use, hope not to cause bad influence, I also count as a fan of B station – -. The following is a list of the main functions currently integrated:

  1. Immersive full screen playback, hidden status bar and virtual keys, if any, there are some things to pay attention to when using them.
  2. The function of the barrage, including the launching of the barrage and the basic style Settings of the barrage: size, color and type (top, bottom and rolling barrage), the effect is the same as Bilibili;
  3. Portrait and landscape switch, in fact, small screen and full screen switch, provides gravity sensor to switch portrait and landscape function;
  4. Touch screen control, vertical direction left control brightness, right control sound, horizontal control playback progress;
  5. Three-finger rotation and zooming. When three fingers touch the screen, the video interface can be rotated and zoomed. The effect is the same as that of Bilibili.
  6. Video source switching: 5 video sources including smooth, clear, HD, ULTRA CLEAR and 1080p can be set;
  7. Video width to height ratio setting, including 16:9, 4:3, video embedded filling interface and filling screen;
  8. Jump function of recording last playback progress;
  9. Other functions such as screenshots, battery power display, time display, steady playback, running title and lock screen processing;

Screenshot











Gifs are slow, so send two GIFs.

Usage

Add dependencies:

// Add the following to the project root: build.gradle: AllProjects {repositories {... Maven {url 'https://jitpack.io'}}} dependencies { compile 'com.github.Rukey7:IjkPlayerView:{lastest-version}' }Copy the code

Configuration AndroidManifest. XML:

Copy the code

Layout:

Copy the code


The code calls as follows:

public class IjkPlayerActivity extends AppCompatActivity { private IjkPlayerView mPlayerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ijk_player); setSupportActionBar(mToolbar); Glide.with(this).load(IMAGE_URL).fitCenter().into(mplayerView.mplayerThumb); Glide.with(this).load(IMAGE_URL).fitCenter().into(mplayerView.mplayerThumb); .setTitle(" This is a title ") // Set the title, Full screen display.setSkipTip (1000*60*1) // Set jump tools.enableorientation () // Enable gravity rolve.setVideopath (VIDEO_URL) // Set video Url, SetVideoSource (null, VIDEO_URL, VIDEO_URL, null) // Set the video Url, Multiple video sources use this.setMediaquality (ijkplayerView.media_quality_high) // specify the initial video source.enableDanmaku () // Enable the danmaku function .setDanmakusource (getResources().openRawResource(R.raw.comments)) // To add ammunition resources, you must call.start() after enableDanmaku(); } @override protected void onResume() {super.onresume (); mPlayerView.onResume(); } @Override protected void onPause() { super.onPause(); mPlayerView.onPause(); } @Override protected void onDestroy() { super.onDestroy(); mPlayerView.onDestroy(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mPlayerView.configurationChanged(newConfig); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mPlayerView.handleVolumeKey(keyCode)) { return true; } return super.onKeyDown(keyCode, event); } @Override public void onBackPressed() { if (mPlayerView.onBackPressed()) { return; } super.onBackPressed(); }}Copy the code

If you want to use fixed full screen mode, you can change it as follows:

public class IjkFullscreenActivity extends AppCompatActivity { IjkPlayerView mPlayerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPlayerView = new IjkPlayerView(this); setContentView(mPlayerView); Glide.with(this).load(IMAGE_URL).fitCenter().into(mPlayerView.mPlayerThumb); Mplayerview.init ().setTitle(" This is a title ").alwaysFullScreen() // Fix the full screen.setVideopath (VIDEO_URL) // Set the video Url, Single video sources can use this.start(); } / /... }Copy the code

Other

Some actions that affect immersive full-screen playback:

1. Do not use Android: fitsSystemWindows = “true”, also don’t use SystemBarTint status bar to staining.

2. Make sure the player is at the top of the ToolBar outside;

Other notes: 1. I am currently testing my own mobile phone honor 6, and I may not be able to deal with many abnormalities. If you have any problems, please tell me and discuss with me. 2. There is no live broadcast function. If we want to make it, I think we have to re-build a different interface. 3. In fact, many configuration functions have not been added, such as video and danmu Settings, please refer to the Bilibili client, I don’t want to add these things for the moment;

Github

Project address: IjkPlayerView

Finally said a bit, I think the player as library as an example to reference than direct use value, before I also see a lot of players of this kind of open source, if it is as real projects to use the words I don’t feel very appropriate, including the library, too, because of customizability are not friendly, unable to meet the various needs in the project. If you find that the results are generally as good as you expect, I suggest you take down the source code and make some custom features yourself. Feels like a library is more conscious (· ∀ ·).