| | |
| | | package com.bsk.zhangbo.demoforbsk.ui.fragment; |
| | | |
| | | import android.content.res.AssetManager; |
| | | import android.graphics.Rect; |
| | | import android.os.Bundle; |
| | | import android.support.v4.view.ViewPager; |
| | | import android.support.v7.widget.GridLayoutManager; |
| | | import android.support.v7.widget.LinearLayoutManager; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.util.Log; |
| | | import android.view.Surface; |
| | | import android.view.SurfaceHolder; |
| | | import android.view.SurfaceView; |
| | | import android.view.View; |
| | | import android.widget.RadioButton; |
| | | import android.widget.RadioGroup; |
| | |
| | | * Created by zhangbo on 2017/2/15. |
| | | */ |
| | | |
| | | public class OneFragment extends BaseFragment{ |
| | | public class OneFragment extends BaseFragment { |
| | | |
| | | private RadioGroup mRadioGroup; |
| | | private RadioButton mRadioButton1,mRadioButton2; |
| | | private View mRadioLine1,mRadioLine2; |
| | | private RadioButton mRadioButton1, mRadioButton2; |
| | | private View mRadioLine1, mRadioLine2; |
| | | private OneBottomRecylerViewAdapter mAdapter; |
| | | private List mList; |
| | | private EasyRecyclerView mRecyclerViewRegister,mRecyclerViewUser; |
| | | private EasyRecyclerView mRecyclerViewRegister, mRecyclerViewUser; |
| | | |
| | | |
| | | //播放 |
| | | |
| | | |
| | | // SurfaceHolderVideoSink mSurfaceHolder1VideoSink; |
| | | // VideoSink mSelectedVideoSink; |
| | | // VideoSink mNativeCodecPlayerVideoSink; |
| | | // SurfaceView mSurfaceView1; |
| | | // SurfaceHolder mSurfaceHolder1; |
| | | // boolean mCreated = false; |
| | | // boolean mIsPlaying = false; |
| | | // String mSourceString = "clips/testfile.mp4"; |
| | | |
| | | /** |
| | | * Native methods, implemented in jni folder |
| | | */ |
| | | // public static native void createEngine(); |
| | | // |
| | | // public static native boolean createStreamingMediaPlayer(AssetManager assetMgr, String filename); |
| | | // |
| | | // public static native void setPlayingStreamingMediaPlayer(boolean isPlaying); |
| | | // |
| | | // public static native void shutdown(); |
| | | // |
| | | // public static native void setSurface(Surface surface); |
| | | // |
| | | // public static native void rewindStreamingMediaPlayer(); |
| | | |
| | | /** Load jni .so on initialization */ |
| | | static { |
| | | System.loadLibrary("native-codec-jni"); |
| | | } |
| | | |
| | | |
| | | public static OneFragment newInstance() { |
| | | return new OneFragment(); |
| | | } |
| | | |
| | | @Override |
| | | protected int getLayoutId() { |
| | | return R.layout.fragment_one; |
| | |
| | | mRecyclerViewUser = (EasyRecyclerView) view.findViewById(R.id.recyclerview_user); |
| | | mRadioButton1.setChecked(true); |
| | | mRecyclerViewRegister.addItemDecoration(new SpaceItemDecoration()); |
| | | GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),2); |
| | | GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2); |
| | | gridLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); |
| | | mRecyclerViewRegister.setLayoutManager(gridLayoutManager); |
| | | mAdapter = new OneBottomRecylerViewAdapter(getActivity()); |
| | | |
| | | |
| | | // set up the Surface 1 video sink |
| | | // mSurfaceView1 = (SurfaceView) view.findViewById(R.id.surfaceview1); |
| | | // mSurfaceHolder1 = mSurfaceView1.getHolder(); |
| | | // |
| | | // mSurfaceHolder1.addCallback(new SurfaceHolder.Callback() { |
| | | // |
| | | // @Override |
| | | // public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| | | // Log.v("", "surfaceChanged format=" + format + ", width=" + width + ", height=" |
| | | // + height); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void surfaceCreated(SurfaceHolder holder) { |
| | | // Log.v("", "surfaceCreated"); |
| | | // setSurface(holder.getSurface()); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void surfaceDestroyed(SurfaceHolder holder) { |
| | | // Log.v("", "surfaceDestroyed"); |
| | | // } |
| | | // |
| | | // }); |
| | | } |
| | | |
| | | @Override |
| | |
| | | mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
| | | @Override |
| | | public void onCheckedChanged(RadioGroup group, int checkedId) { |
| | | switch (checkedId){ |
| | | switch (checkedId) { |
| | | case R.id.radio1: |
| | | mRadioLine1.setVisibility(View.VISIBLE); |
| | | mRadioLine2.setVisibility(View.INVISIBLE); |
| | |
| | | |
| | | @Override |
| | | protected void initData() { |
| | | // switchSurface(); |
| | | mList = new ArrayList(); |
| | | for (int i=0;i<25;i++){ |
| | | for (int i = 0; i < 25; i++) { |
| | | mList.add(""); |
| | | } |
| | | mAdapter.setList(mList); |
| | | mRecyclerViewRegister.setAdapter(mAdapter); |
| | | |
| | | |
| | | // mSurfaceHolder1VideoSink = new SurfaceHolderVideoSink(mSurfaceHolder1); |
| | | // mSelectedVideoSink = mSurfaceHolder1VideoSink; |
| | | // mSelectedVideoSink.useAsSinkForNative(); |
| | | // mNativeCodecPlayerVideoSink = mSelectedVideoSink; |
| | | // |
| | | // mCreated = createStreamingMediaPlayer(getResources().getAssets(), |
| | | // mSourceString); |
| | | // mIsPlaying = !mIsPlaying; |
| | | // setPlayingStreamingMediaPlayer(mIsPlaying); |
| | | |
| | | } |
| | | |
| | | private class SpaceItemDecoration extends RecyclerView.ItemDecoration { |
| | | @Override |
| | | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { |
| | |
| | | // outRect.bottom = WindowsUtil.dip2px(getActivity(), 7); |
| | | outRect.right = WindowsUtil.dip2px(getActivity(), 15); |
| | | |
| | | if (parent.getChildLayoutPosition(view) == 0 || parent.getChildLayoutPosition(view) == 1){ |
| | | outRect.left = WindowsUtil.dip2px(getActivity(),14); |
| | | if (parent.getChildLayoutPosition(view) == 0 || parent.getChildLayoutPosition(view) == 1) { |
| | | outRect.left = WindowsUtil.dip2px(getActivity(), 14); |
| | | } |
| | | if (parent.getChildLayoutPosition(view) % 2 == 0) { |
| | | outRect.bottom = WindowsUtil.dip2px(getActivity(), 7); |
| | |
| | | // } |
| | | } |
| | | } |
| | | |
| | | |
| | | // void switchSurface() { |
| | | // if (mCreated && mNativeCodecPlayerVideoSink != mSelectedVideoSink) { |
| | | // // shutdown and recreate on other surface |
| | | // Log.i("@@@", "shutting down player"); |
| | | // shutdown(); |
| | | // mCreated = false; |
| | | // mSelectedVideoSink.useAsSinkForNative(); |
| | | // mNativeCodecPlayerVideoSink = mSelectedVideoSink; |
| | | // if (mSourceString != null) { |
| | | // Log.i("@@@", "recreating player"); |
| | | // mCreated = createStreamingMediaPlayer(getResources().getAssets(), mSourceString); |
| | | // mIsPlaying = false; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // /** |
| | | // * Called when the activity is about to be paused. |
| | | // */ |
| | | // @Override |
| | | // public void onPause() { |
| | | // mIsPlaying = false; |
| | | // setPlayingStreamingMediaPlayer(false); |
| | | // super.onPause(); |
| | | // } |
| | | // |
| | | // /** |
| | | // * Called when the activity is about to be destroyed. |
| | | // */ |
| | | // @Override |
| | | // public void onDestroy() { |
| | | // shutdown(); |
| | | // mCreated = false; |
| | | // super.onDestroy(); |
| | | // } |
| | | // |
| | | // |
| | | // // VideoSink abstracts out the difference between Surface and SurfaceTexture |
| | | // // aka SurfaceHolder and GLSurfaceView |
| | | // static abstract class VideoSink { |
| | | // |
| | | // abstract void setFixedSize(int width, int height); |
| | | // |
| | | // abstract void useAsSinkForNative(); |
| | | // |
| | | // } |
| | | // |
| | | // static class SurfaceHolderVideoSink extends VideoSink { |
| | | // |
| | | // private final SurfaceHolder mSurfaceHolder; |
| | | // |
| | | // SurfaceHolderVideoSink(SurfaceHolder surfaceHolder) { |
| | | // mSurfaceHolder = surfaceHolder; |
| | | // } |
| | | // |
| | | // @Override |
| | | // void setFixedSize(int width, int height) { |
| | | // mSurfaceHolder.setFixedSize(width, height); |
| | | // } |
| | | // |
| | | // @Override |
| | | // void useAsSinkForNative() { |
| | | // Surface s = mSurfaceHolder.getSurface(); |
| | | // Log.i("@@@", "setting surface " + s); |
| | | // setSurface(s); |
| | | // } |
| | | // |
| | | // } |
| | | } |