Coder Social home page Coder Social logo

hijkplayerview's Introduction

引入

  • 1.0 将下面代码添加到项目的根目录的build.gradle:
allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}
  • 2.0 将下面代码添加到app目录的build.gradle:
dependencies { 
    compile 'com.github.huangbryant210707:HIjkPlayerView:1.0.0' 
}

使用

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mPlayerView = (HIjkPlayerView) findViewById(R.id.player_view);

    //视频未播放时的封面图片
    Glide.with(this).load(IMAGE_URL).fitCenter().into(mPlayerView.mPlayerThumb);
    mPlayerView.init()
            .setTitle("title") //视频的的标题 
            .setSkipTip(1000*60*1) 
            .enableDanmaku()
            //.setDanmakuSource(getResources().openRawResource(R.raw.bili))
            .setVideoSource(null, VIDEO_URL, VIDEO_HD_URL, null, null)
            .setMediaQuality(HIjkPlayerView.MEDIA_QUALITY_HIGH);

    mIvSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mPlayerView.sendDanmaku(mEditText.getText().toString(), false);
            mEditText.setText("");
            _closeSoftInput();
        }
    });
    mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean isFocus) {
            if (isFocus) {
                mPlayerView.editVideo();
            }
            mIsFocus = isFocus;
        }
       
    });
}

@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();
}



@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    View view = getCurrentFocus();
    if (_isHideSoftInput(view, (int) ev.getX(), (int) ev.getY())) {
        _closeSoftInput();
        return true;
    }
    return super.dispatchTouchEvent(ev);
}

private void _closeSoftInput() {
    mEditText.clearFocus();
    SoftInputUtils.closeSoftInput(this);
    mPlayerView.recoverFromEditVideo();
}

private boolean _isHideSoftInput(View view, int x, int y) {
    if (view == null || !(view instanceof EditText) || !mIsFocus) {
        return false;
    }
    return x < mEtLayout.getLeft() ||
            x > mEtLayout.getRight() ||
            y < mEtLayout.getTop();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.