Android 使用超简单的多媒体播放器JiaoZiVideoPlayer

在之前的项目中用到了视频播放的功能,在网上看了看使用了大家用的比较多的一个开源项目JiaoZiVideo可以迅速的实现视频播放的相关功能。

JiaoZiVideo的简单使用

集成了JiaoZiVideo后仅需这几行代码就可以实现播放视频

JZVideoPlayerStandard jzVideoPlayerStandard = (JZVideoPlayerStandard) findViewById(R.id.jz_vedio);
//设置播放视频链接和视频标题
jzVideoPlayerStandard.setUp(VEDIO_URL
                , JZVideoPlayer.SCREEN_WINDOW_NORMAL, "饺子在哪里");
                
//为播放视频设置封面图
jzVideoPlayerStandard.thumbImageView.setImageResource(R.mipmap.ic_launcher);

Jz播放器的简单使用,只需要在布局文件中引入该文件,然后为其设置待播放视频的链接和播放视频的封面图即可。其它的播放相关的无需我们关心。

代码结构分析

image.png

JiaoZiVideo主要特点

  1. 可以完全自定义UI和任何功能
  2. 可以完全自定义UI和任何功能
  3. 一行代码切换播放引擎,支持的视频格式和协议取决于播放引擎,android.media.MediaPlayer ijkplayer
  4. 完美检测列表滑动
  5. 可实现全屏播放,小窗播放
  6. 能在ListView、ViewPager和ListView、ViewPager和Fragment等多重嵌套模式下全屏工作
  7. 可以在加载、暂停、播放等各种状态中正常进入全屏和退出全屏
  8. 多种视频适配屏幕的方式,可铺满全屏,可以全屏剪裁
  9. 重力感应自动进入全屏
  10. 全屏后手势修改进度和音量
  11. Home键退出界面暂停播放,返回界面继续播放

JiaoZiVideo的使用指南

1..添加类库
implementation 'cn.jzvd:jiaozivideoplayer:7.0.3'
2.添加布局
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="200dp">
    <cn.jzvd.demo.CustomJzvd.MyJzvdStd
        android:id="@+id/jz_video"
        android:layout_width="match_parent"
        android:layout_height="200dp" />
</LinearLayout>
3.设置视频地址、缩略图地址、标题
MyJzvdStd jzvdStd = (MyJzvdStd) findViewById(R.id.jz_video);
jzvdStd.setUp("http://jzvd.nathen.cn/c6e3dc12a1154626b3476d9bf3bd7266/6b56c5f0dc31428083757a45764763b0-5287d2089db37e62345123a1be272f8b.mp4"
                            , "饺子闭眼睛");
jzvdStd.thumbImageView.setImage("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640");
4.在Activity中
@Override
public void onBackPressed() {
    if (Jzvd.backPress()) {
        return;
    }
    super.onBackPressed();
}
@Override
protected void onPause() {
    super.onPause();
    Jzvd.releaseAllVideos();
}
5.在AndroidManifest.xml中
<activity
    android:name=".MainActivity"
    android:configChanges="orientation|screenSize|keyboardHidden"
    android:screenOrientation="portrait" /> <!-- or android:screenOrientation="landscape"-->

以上只是简单的播放视频功能,但是大家的项目需求里应该不仅仅只是需要播放视频就好了,所以下面写一下还有哪些常规使用方法

\color{rgb(0,191,255)}{加缩略载图}

Glide.with(this).load(Url).into(myJzvdStd.thumbImageView);   //推荐使用Glide

\color{rgb(0,191,255)}{自动播放}

      自动播放有两种 这里随便选择添加一个,
    1. myJzvdStd.startButton.performClick();
    2. myJzvdStd.startVideo();

\color{rgb(0,191,255)}{跳转制定位置播放}

    //这里只有开始播放时才生效
    mJzvdStd.seekToInAdvance = 20000;
    //跳转制定位置播放
    JZMediaManager.seekTo(30000);

   2.播放sd卡下视频

    public void cpAssertVideoToLocalPath() {
            try {
                InputStream myInput;
                OutputStream myOutput = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/local_video.mp4");
                myInput = this.getAssets().open("local_video.mp4");
                byte[] buffer = new byte[1024];
                int length = myInput.read(buffer);
                while (length > 0) {
                    myOutput.write(buffer, 0, length);
                    length = myInput.read(buffer);
                }
     
                myOutput.flush();
                myInput.close();
                myOutput.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    myJzvdStd.setUp(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/local_video.mp4", "饺子不信",Jzvd.SCREEN_WINDOW_NORMAL, );
    这里很多人问为什么播不了,请认真怒url,播不了就是url没怒对

\color{rgb(0,191,255)}{ 播放assets目录下的视频}

           复制Demo中CustomMediaPlayerAssertFolder类到你的项目下
            ----------------------------------------------------------------------------
            JZDataSource jzDataSource = null;
            try {
                jzDataSource = new JZDataSource(getAssets().openFd("local_video.mp4"));
                jzDataSource.title = "饺子快长大";
            } catch (IOException e) {
                e.printStackTrace();
            }
            jzvdStd.setUp(jzDataSource, JzvdStd.SCREEN_WINDOW_NORMAL);
            Glide.with(this)
                    .load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png")
                    .into(jzvdStd.thumbImageView);
     
            Jzvd.setMediaInterface(new CustomMediaPlayerAssertFolder());//进入此页面修改MediaInterface,让此页面的jzvd正常工作

\color{rgb(0,191,255)}{ 直接全屏播放}

JzvdStd.startFullscreen(this, JzvdStd.class, VideoConstant.videoUrlList[6], "饺子辛苦了");

\color{rgb(0,191,255)}{ 开启小窗播放}

mJzvdStd.startWindowTiny();

\color{rgb(0,191,255)}{ 列表Item划出开启小窗播放 }

    1.Listview
       listView.setOnScrollListener(new AbsListView.OnScrollListener() {
                @Override
                public void onScrollStateChanged(AbsListView view, int scrollState) { 
     
                }
                @Override
                public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                    Jzvd.onScrollAutoTiny(view, firstVisibleItem, visibleItemCount, totalItemCount);
                  // Jzvd.onScrollReleaseAllVideos(view, firstVisibleItem, visibleItemCount, totalItemCount);  这是不开启列表划出小窗 同时也是画出屏幕释放JZ 划出暂停
                }
            });
    2. RecyclerView  划出列表开启小窗
       recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
                @Override
                public void onChildViewAttachedToWindow(View view) {
                    Jzvd.onChildViewAttachedToWindow(view, R.id.videoplayer);
                }
     
                @Override
                public void onChildViewDetachedFromWindow(View view) {
                    Jzvd.onChildViewDetachedFromWindow(view);
                }
            });
    2.1 RecyclerView划出屏幕释放JZ,同时也是不开启列表划出显示小窗
        recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
                @Override
                public void onChildViewAttachedToWindow(View view) {
     
                }
     
                @Override
                public void onChildViewDetachedFromWindow(View view) {
                    Jzvd jzvd = view.findViewById(R.id.videoplayer);
                    if (jzvd != null && jzvd.jzDataSource.containsTheUrl(JZMediaManager.getCurrentUrl())) {
                        Jzvd currentJzvd = JzvdMgr.getCurrentJzvd();
                        if (currentJzvd != null && currentJzvd.currentScreen != Jzvd.SCREEN_WINDOW_FULLSCREEN) {
                            Jzvd.releaseAllVideos();
                        }
                    }
                }
            });

\color{rgb(0,191,255)}{ 小屏播放无声音,全屏有声音 }

    创建一个类继承JzvdStd并在XML设置
    public class JzvdStdVolumeAfterFullscreen extends JzvdStd {
        public JzvdStdVolumeAfterFullscreen(Context context) {
            super(context);
        }
     
        public JzvdStdVolumeAfterFullscreen(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
     
        @Override
        public void onPrepared() {
            super.onPrepared();
            if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
                JZMediaManager.instance().jzMediaInterface.setVolume(1f, 1f);
            } else {
                JZMediaManager.instance().jzMediaInterface.setVolume(0f, 0f);
            }
        }
     
        /**
         * 进入全屏模式的时候关闭静音模式
         */
        @Override
        public void startWindowFullscreen() {
            super.startWindowFullscreen();
            JZMediaManager.instance().jzMediaInterface.setVolume(1f, 1f);
        }
     
        /**
         * 退出全屏模式的时候开启静音模式
         */
        @Override
        public void playOnThisJzvd() {
            super.playOnThisJzvd();
            JZMediaManager.instance().jzMediaInterface.setVolume(0f, 0f);
        }
    }

\color{rgb(0,191,255)}{ 全屏状态播放完成,不退出全屏 }

    创建一个类继承JzvdStd并在XML设置
    public class JzvdStdAutoCompleteAfterFullscreen extends JzvdStd {
        public JzvdStdAutoCompleteAfterFullscreen(Context context) {
            super(context);
        }
     
        public JzvdStdAutoCompleteAfterFullscreen(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
     
        @Override
        public void startVideo() {
            if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
                Log.d(TAG, "startVideo [" + this.hashCode() + "] ");
                initTextureView();
                addTextureView();
                AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
                mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
                JZUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
     
                JZMediaManager.setDataSource(jzDataSource);
                JZMediaManager.instance().positionInList = positionInList;
                onStatePreparing();
            } else {
                super.startVideo();
            }
        }
     
        @Override
        public void onAutoCompletion() {
            if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
                onStateAutoComplete();
            } else {
                super.onAutoCompletion();
            }
     
        }
    }

\color{rgb(0,191,255)}{ 全屏模式下显示分享按钮 }

    复制DEMO下的layout文件在 layout_top 布局下 添加你的分享按钮
    public class JzvdStdShowShareButtonAfterFullscreen extends JzvdStd {
     
        public ImageView shareButton;
     
        public JzvdStdShowShareButtonAfterFullscreen(Context context) {
            super(context);
        }
     
        public JzvdStdShowShareButtonAfterFullscreen(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
     
        @Override
        public void init(Context context) {
            super.init(context);
            shareButton = findViewById(R.id.share);
            shareButton.setOnClickListener(this);
     
        }
     
        @Override
        public int getLayoutId() {
            return R.layout.layout_standard_with_share_button;
        }
     
        @Override
        public void onClick(View v) {
            super.onClick(v);
            if (v.getId() == R.id.share) {
                Toast.makeText(getContext(), "Whatever the icon means", Toast.LENGTH_SHORT).show();
            }
        }
     
        @Override
        public void setUp(JZDataSource jzDataSource, int screen) {
            super.setUp(jzDataSource, screen);
            if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
                shareButton.setVisibility(View.VISIBLE);
            } else {
                shareButton.setVisibility(View.INVISIBLE);
            }
        }
    }

\color{rgb(0,191,255)}{ 小屏状态下不显示标题,全屏模式下显示标题 }

    public class JzvdStdShowTitleAfterFullscreen extends JzvdStd {
        public JzvdStdShowTitleAfterFullscreen(Context context) {
            super(context);
        }
     
        public JzvdStdShowTitleAfterFullscreen(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
     
        @Override
        public void setUp(JZDataSource jzDataSource, int screen) {
            super.setUp(jzDataSource, screen);
            if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
                titleTextView.setVisibility(View.VISIBLE);
            } else {
                titleTextView.setVisibility(View.INVISIBLE);
            }
        }
    }

\color{rgb(0,191,255)}{ 播放MP3 }

    public class JzvdStdMp3 extends JzvdStd {
     
        public JzvdStdMp3(Context context) {
            super(context);
        }
     
        public JzvdStdMp3(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
     
        @Override
        public int getLayoutId() {
            return R.layout.jz_layout_standard_mp3;
        }
     
        @Override
        public void onClick(View v) {
            if (v.getId() == cn.jzvd.R.id.thumb &&
                    (currentState == CURRENT_STATE_PLAYING ||
                            currentState == CURRENT_STATE_PAUSE)) {
                onClickUiToggle();
            } else if (v.getId() == R.id.fullscreen) {
     
            } else {
                super.onClick(v);
            }
        }
     
        //changeUiTo 真能能修改ui的方法
        @Override
        public void changeUiToNormal() {
            super.changeUiToNormal();
        }
     
        @Override
        public void changeUiToPreparing() {
            super.changeUiToPreparing();
        }
     
        @Override
        public void changeUiToPlayingShow() {
            super.changeUiToPlayingShow();
            thumbImageView.setVisibility(View.VISIBLE);
     
        }
     
        @Override
        public void changeUiToPlayingClear() {
            super.changeUiToPlayingClear();
            thumbImageView.setVisibility(View.VISIBLE);
     
        }
     
        @Override
        public void changeUiToPauseShow() {
            super.changeUiToPauseShow();
            thumbImageView.setVisibility(View.VISIBLE);
     
        }
     
        @Override
        public void changeUiToPauseClear() {
            super.changeUiToPauseClear();
            thumbImageView.setVisibility(View.VISIBLE);
     
        }
     
        @Override
        public void changeUiToComplete() {
            super.changeUiToComplete();
        }
     
        @Override
        public void changeUiToError() {
            super.changeUiToError();
        }
    }
     
            jzvdStdMp3 = findViewById(R.id.jz_videoplayer_mp3);
            jzvdStdMp3.setUp(URL, "饺子摇摆", Jzvd.SCREEN_WINDOW_NORMAL);
            Glide.with(this)
                    .load(VideoConstant.videoThumbs[0][1])
                    .into(jzvdStdMp3.thumbImageView);

\color{rgb(0,191,255)}{ 播放完成不显示预览图 }

    public class JzvdStdShowTextureViewAfterAutoComplete extends JzvdStd {
        public JzvdStdShowTextureViewAfterAutoComplete(Context context) {
            super(context);
        }
     
        public JzvdStdShowTextureViewAfterAutoComplete(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
     
        @Override
        public void onAutoCompletion() {
            super.onAutoCompletion();
            thumbImageView.setVisibility(View.GONE);
        }
     
    }

\color{rgb(0,191,255)}{ Home键退出界面暂停播放,返回界面继续播放 }

      @Override
        protected void onResume() {
            super.onResume();
            //home back
            JzvdStd.goOnPlayOnResume();
        }
     
        @Override
        protected void onPause() {
            super.onPause();
       //     Jzvd.clearSavedProgress(this, null);
            //home back
            JzvdStd.goOnPlayOnPause();
        }

\color{rgb(0,191,255)}{ 边播边缓存和清晰度切换 }

    1. 集成videocache implementation 'com.danikula:videocache:2.7.0',并初始化
    public class ApplicationDemo extends Application {
     
        @Override
        public void onCreate() {
            super.onCreate();
    //        LeakCanary.install(this);
        }
     
        private HttpProxyCacheServer proxy;
     
        public static HttpProxyCacheServer getProxy(Context context) {
            ApplicationDemo app = (ApplicationDemo) context.getApplicationContext();
            return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
        }
     
        private HttpProxyCacheServer newProxy() {
            return new HttpProxyCacheServer(this);
        }
    }
    2.引用
            LinkedHashMap map = new LinkedHashMap();
     
            String proxyUrl = ApplicationDemo.getProxy(this).getProxyUrl(VideoConstant.videoUrls[0][9]);
     
            map.put("高清", proxyUrl);
            map.put("标清", VideoConstant.videoUrls[0][6]);
            map.put("普清", VideoConstant.videoUrlList[0]);
            JZDataSource jzDataSource = new JZDataSource(map, "饺子不信");
            jzDataSource.looping = true;
            jzDataSource.currentUrlIndex = 2;
            jzDataSource.headerMap.put("key", "value");//header
            mJzvdStd.setUp(jzDataSource
                    , JzvdStd.SCREEN_WINDOW_NORMAL);
            Glide.with(this).load(VideoConstant.videoThumbList[0]).into(mJzvdStd.thumbImageView);

\color{rgb(0,191,255)}{重复播放}

    创建一个类集成JzvdStd并在XML设置
    public class JZVideoPlayerStandardLoopVideo extends JzvdStd{
        public JZVideoPlayerStandardLoopVideo (Context context) {
            super(context);
        }
     
        public JZVideoPlayerStandardLoopVideo (Context context, AttributeSet attrs) {
            super(context, attrs);
        }
     
        @Override
        public void onAutoCompletion() {
            super.onAutoCompletion();
            startVideo();
        }
    }
    还有一种方法就是上面清晰度切换loop循环标志

\color{rgb(0,191,255)}{重力感应自动进入全屏}

        SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        Jzvd.JZAutoFullscreenListener mSensorEventListener = new Jzvd.JZAutoFullscreenListener();
        @Override
        protected void onResume() {
            super.onResume();
            Sensor accelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
            mSensorManager.registerListener(mSensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);
        }
     
        @Override
        protected void onPause() {
            super.onPause();
            mSensorManager.unregisterListener(mSensorEventListener);
       }
     

\color{rgb(0,191,255)}{重力感应}

    Jzvd.FULLSCREEN_ORIENTATION=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    两个变量控制全屏前后的屏幕方向

\color{rgb(0,191,255)}{ 不保存播放进度}

Jzvd.SAVE_PROGRESS = false;

\color{rgb(0,191,255)}{ 取消播放时在非WIFIDialog提示}

Jzvd.WIFI_TIP_DIALOG_SHOWED=true;

\color{rgb(0,191,255)}{清除某个URL进度}

 Jzvd.clearSavedProgress(this, "url");

\color{rgb(0,191,255)}{切换播放内核 }

    ijk
        复制Demo中JZMediaIjkplayer类到你的项目下 
        implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.4'
        implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
        Jzvd.setMediaInterface(new JZMediaIjkplayer());  //  ijkMediaPlayer
    Mediaplayer
        Jzvd.setMediaInterface(new JZMediaSystem());  // 
    exo
        复制Demo中JZExoPlayer类到你的项目下 
        implementation 'com.google.android.exoplayer:exoplayer:2.7.1'
        Jzvd.setMediaInterface(new JZExoPlayer());  //exo

\color{rgb(0,191,255)}{用户埋点统计}

        Jzvd.setJzUserAction(new MyUserActionStd());
        /**
         * 这只是给埋点统计用户数据用的,不能写和播放相关的逻辑,监听事件请参考MyJzvdStd,复写函数取得相应事件
         */
        class MyUserActionStd implements JZUserActionStd {
     
            @Override
            public void onEvent(int type, Object url, int screen, Object... objects) {
                switch (type) {
                    case JZUserAction.ON_CLICK_START_ICON:
                        Log.i("USER_EVENT", "ON_CLICK_START_ICON" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_CLICK_START_ERROR:
                        Log.i("USER_EVENT", "ON_CLICK_START_ERROR" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_CLICK_START_AUTO_COMPLETE:
                        Log.i("USER_EVENT", "ON_CLICK_START_AUTO_COMPLETE" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_CLICK_PAUSE:
                        Log.i("USER_EVENT", "ON_CLICK_PAUSE" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_CLICK_RESUME:
                        Log.i("USER_EVENT", "ON_CLICK_RESUME" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_SEEK_POSITION:
                        Log.i("USER_EVENT", "ON_SEEK_POSITION" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_AUTO_COMPLETE:
                        Log.i("USER_EVENT", "ON_AUTO_COMPLETE" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_ENTER_FULLSCREEN:
                        Log.i("USER_EVENT", "ON_ENTER_FULLSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_QUIT_FULLSCREEN:
                        Log.i("USER_EVENT", "ON_QUIT_FULLSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_ENTER_TINYSCREEN:
                        Log.i("USER_EVENT", "ON_ENTER_TINYSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_QUIT_TINYSCREEN:
                        Log.i("USER_EVENT", "ON_QUIT_TINYSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_TOUCH_SCREEN_SEEK_VOLUME:
                        Log.i("USER_EVENT", "ON_TOUCH_SCREEN_SEEK_VOLUME" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserAction.ON_TOUCH_SCREEN_SEEK_POSITION:
                        Log.i("USER_EVENT", "ON_TOUCH_SCREEN_SEEK_POSITION" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
     
                    case JZUserActionStd.ON_CLICK_START_THUMB:
                        Log.i("USER_EVENT", "ON_CLICK_START_THUMB" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    case JZUserActionStd.ON_CLICK_BLANK:
                        Log.i("USER_EVENT", "ON_CLICK_BLANK" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
                        break;
                    default:
                        Log.i("USER_EVENT", "unknow");
                        break;
                }
            }
        }

相关函数回调,屏幕状态,播放器状态,事件

在继承JzvdStd之后,可以通过父类的mCurrentState,取得当前的播放状态。

  • CURRENT_STATE_IDLE 未知状态,指控件被new出来之后什么都没做
  • CURRENT_STATE_NORMAL 普通状态
  • CURRENT_STATE_PREPARING 视频准备状态
  • CURRENT_STATE_PREPARING_CHANGING_URL 播放中切换url的准备状态
  • CURRENT_STATE_PLAYING 播放中状态
  • CURRENT_STATE_PAUSE 暂停状态
  • CURRENT_STATE_AUTO_COMPLETE 自动播放完成状态
  • CURRENT_STATE_ERROR 错误状态

复写进入播放状态的函数,取得播放状态的回调

  • onStateNormal 进入普通状态,通常指setUp之后
  • onStatePreparing 进入准备中状态,就是loading状态
  • onStatePlaying 进入播放状态
  • onStatePause 进入暂停状态
  • onStateError 进入错误状态
  • onStateAutoComplete 进入自动播放完成状态

全屏、小窗、非全屏分别是不同的实例,在继承JzvdStd后,通过mCurrentScreen变量,取得当前屏幕类型

  • SCREEN_WINDOW_NORMAL 普通窗口(进入全屏之前的)
  • SCREEN_WINDOW_LIST 列表窗口(进入全屏之前)
  • SCREEN_WINDOW_FULLSCREEN 全屏
  • SCREEN_WINDOW_TINY 小窗

事件

  • 复写onProgress函数,取得每次播放器设置底部seekBar的进度回调
  • 调用changeUrl函数,切换url
  • 复写onClick函数,取得各种按钮的点击事件
  • 复写onTouch函数,取得全屏之后的手势操作

JiaoZiVideoPlayer的功能远不止上述这些,最近我也在深入的研究中,下篇文章会收集一些大家经常遇到的问题写出来帮助大家,大家有什么建议或者问题可以再下方留言。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,179评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,229评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,032评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,533评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,531评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,539评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,916评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,574评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,813评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,568评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,654评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,354评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,937评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,918评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,152评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,852评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,378评论 2 342

推荐阅读更多精彩内容