Skip to content

IjkPlayer/MediaPlayer+TextureView,完美切换全屏、小窗口的Android视频播放器

Notifications You must be signed in to change notification settings

tianzc/NiceVieoPlayer

 
 

Repository files navigation

NiceVieoPlayer

用IjkPlayer/MediaPlayer + TextureView封装,完美切换全屏、小窗口播放。

Usage

下载niceviewoplayer库,在AndroidSutio中作为Mudule添加依赖。

1.在Activity中使用:

 private void init() {
      mNiceVideoPlayer = (NiceVideoPlayer) findViewById(R.id.nice_video_player);
      mNiceVideoPlayer.setPlayerType(NiceVideoPlayer.PLAYER_TYPE_IJK); // or NiceVideoPlayer.PLAYER_NATIVE
      mNiceVideoPlayer.setUp(mVideoUrl, null);
      NiceVideoPlayerController controller = new NiceVideoPlayerController(this);
      controller.setTitle(mTitle);
      controller.setImage(mImageUrl);
      mNiceVideoPlayer.setController(controller);
  }
  
  // 按返回键
  // 当前是全屏或小窗口,需要先退出全屏或小窗口。
  @Override
  public void onBackPressed() {
      if (NiceVideoPlayerManager.instance().onBackPressd()) {
          return;
      }
      super.onBackPressed();
  }

2.在RecyclerView列表中使用需要监听itemView detach:

mRecyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
    @Override
    public void onChildViewAttachedToWindow(View view) {

    }

    @Override
    public void onChildViewDetachedFromWindow(View view) {
        NiceVideoPlayer niceVideoPlayer = (NiceVideoPlayer) view.findViewById(R.id.nice_video_player);
        if (niceVideoPlayer != null) {
            niceVideoPlayer.release();
        }
    }
});

Proguard

-keep class tv.danmaku.ijk.media.player.**{*;}

Demo

About

IjkPlayer/MediaPlayer+TextureView,完美切换全屏、小窗口的Android视频播放器

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%