Android 使用超簡(jiǎn)單的多媒體播放器JiaoZiVideoPlayer

在之前的項(xiàng)目中用到了視頻播放的功能,在網(wǎng)上看了看使用了大家用的比較多的一個(gè)開源項(xiàng)目JiaoZiVideo可以迅速的實(shí)現(xiàn)視頻播放的相關(guān)功能。

JiaoZiVideo的簡(jiǎn)單使用

集成了JiaoZiVideo后僅需這幾行代碼就可以實(shí)現(xiàn)播放視頻

JZVideoPlayerStandard jzVideoPlayerStandard = (JZVideoPlayerStandard) findViewById(R.id.jz_vedio);
//設(shè)置播放視頻鏈接和視頻標(biāo)題
jzVideoPlayerStandard.setUp(VEDIO_URL
                , JZVideoPlayer.SCREEN_WINDOW_NORMAL, "餃子在哪里");
                
//為播放視頻設(shè)置封面圖
jzVideoPlayerStandard.thumbImageView.setImageResource(R.mipmap.ic_launcher);

Jz播放器的簡(jiǎn)單使用,只需要在布局文件中引入該文件您宪,然后為其設(shè)置待播放視頻的鏈接和播放視頻的封面圖即可。其它的播放相關(guān)的無(wú)需我們關(guān)心。

代碼結(jié)構(gòu)分析

image.png

JiaoZiVideo主要特點(diǎn)

  1. 可以完全自定義UI和任何功能
  2. 可以完全自定義UI和任何功能
  3. 一行代碼切換播放引擎蚕键,支持的視頻格式和協(xié)議取決于播放引擎,android.media.MediaPlayer ijkplayer
  4. 完美檢測(cè)列表滑動(dòng)
  5. 可實(shí)現(xiàn)全屏播放衰粹,小窗播放
  6. 能在ListView锣光、ViewPager和ListView、ViewPager和Fragment等多重嵌套模式下全屏工作
  7. 可以在加載铝耻、暫停誊爹、播放等各種狀態(tài)中正常進(jìn)入全屏和退出全屏
  8. 多種視頻適配屏幕的方式,可鋪滿全屏瓢捉,可以全屏剪裁
  9. 重力感應(yīng)自動(dòng)進(jìn)入全屏
  10. 全屏后手勢(shì)修改進(jìn)度和音量
  11. Home鍵退出界面暫停播放频丘,返回界面繼續(xù)播放

JiaoZiVideo的使用指南

1..添加類庫(kù)
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.設(shè)置視頻地址、縮略圖地址泡态、標(biāo)題
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"-->

以上只是簡(jiǎn)單的播放視頻功能搂漠,但是大家的項(xiàng)目需求里應(yīng)該不僅僅只是需要播放視頻就好了,所以下面寫一下還有哪些常規(guī)使用方法

\color{rgb(0,191,255)}{加縮略載圖}

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

\color{rgb(0,191,255)}{自動(dòng)播放}

      自動(dòng)播放有兩種 這里隨便選擇添加一個(gè)某弦,
    1. myJzvdStd.startButton.performClick();
    2. myJzvdStd.startVideo();

\color{rgb(0,191,255)}{跳轉(zhuǎn)制定位置播放}

    //這里只有開始播放時(shí)才生效
    mJzvdStd.seekToInAdvance = 20000;
    //跳轉(zhuǎn)制定位置播放
    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, );
    這里很多人問為什么播不了桐汤,請(qǐng)認(rèn)真怒url,播不了就是url沒怒對(duì)

\color{rgb(0,191,255)}{ 播放assets目錄下的視頻}

           復(fù)制Demo中CustomMediaPlayerAssertFolder類到你的項(xiàng)目下
            ----------------------------------------------------------------------------
            JZDataSource jzDataSource = null;
            try {
                jzDataSource = new JZDataSource(getAssets().openFd("local_video.mp4"));
                jzDataSource.title = "餃子快長(zhǎng)大";
            } 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());//進(jìn)入此頁(yè)面修改MediaInterface靶壮,讓此頁(yè)面的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);  這是不開啟列表劃出小窗 同時(shí)也是畫出屏幕釋放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怔毛,同時(shí)也是不開啟列表劃出顯示小窗
        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)}{ 小屏播放無(wú)聲音,全屏有聲音 }

    創(chuàng)建一個(gè)類繼承JzvdStd并在XML設(shè)置
    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);
            }
        }
     
        /**
         * 進(jìn)入全屏模式的時(shí)候關(guān)閉靜音模式
         */
        @Override
        public void startWindowFullscreen() {
            super.startWindowFullscreen();
            JZMediaManager.instance().jzMediaInterface.setVolume(1f, 1f);
        }
     
        /**
         * 退出全屏模式的時(shí)候開啟靜音模式
         */
        @Override
        public void playOnThisJzvd() {
            super.playOnThisJzvd();
            JZMediaManager.instance().jzMediaInterface.setVolume(0f, 0f);
        }
    }

\color{rgb(0,191,255)}{ 全屏狀態(tài)播放完成亮钦,不退出全屏 }

    創(chuàng)建一個(gè)類繼承JzvdStd并在XML設(shè)置
    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)}{ 全屏模式下顯示分享按鈕 }

    復(fù)制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)}{ 小屏狀態(tài)下不顯示標(biāo)題馆截,全屏模式下顯示標(biāo)題 }

    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)}{ 播放完成不顯示預(yù)覽圖 }

    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鍵退出界面暫停播放,返回界面繼續(xù)播放 }

      @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("標(biāo)清", 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)}{重復(fù)播放}

    創(chuàng)建一個(gè)類集成JzvdStd并在XML設(shè)置
    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循環(huán)標(biāo)志

\color{rgb(0,191,255)}{重力感應(yīng)自動(dòng)進(jìn)入全屏}

        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)}{重力感應(yīng)}

    Jzvd.FULLSCREEN_ORIENTATION=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    兩個(gè)變量控制全屏前后的屏幕方向

\color{rgb(0,191,255)}{ 不保存播放進(jìn)度}

Jzvd.SAVE_PROGRESS = false;

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

Jzvd.WIFI_TIP_DIALOG_SHOWED=true;

\color{rgb(0,191,255)}{清除某個(gè)URL進(jìn)度}

 Jzvd.clearSavedProgress(this, "url");

\color{rgb(0,191,255)}{切換播放內(nèi)核 }

    ijk
        復(fù)制Demo中JZMediaIjkplayer類到你的項(xiàng)目下 
        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
        復(fù)制Demo中JZExoPlayer類到你的項(xiàng)目下 
        implementation 'com.google.android.exoplayer:exoplayer:2.7.1'
        Jzvd.setMediaInterface(new JZExoPlayer());  //exo

\color{rgb(0,191,255)}{用戶埋點(diǎn)統(tǒng)計(jì)}

        Jzvd.setJzUserAction(new MyUserActionStd());
        /**
         * 這只是給埋點(diǎn)統(tǒng)計(jì)用戶數(shù)據(jù)用的蜡娶,不能寫和播放相關(guān)的邏輯,監(jiān)聽事件請(qǐng)參考MyJzvdStd映穗,復(fù)寫函數(shù)取得相應(yīng)事件
         */
        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;
                }
            }
        }

相關(guān)函數(shù)回調(diào)窖张,屏幕狀態(tài),播放器狀態(tài),事件

在繼承JzvdStd之后蚁滋,可以通過(guò)父類的mCurrentState宿接,取得當(dāng)前的播放狀態(tài)赘淮。

  • CURRENT_STATE_IDLE 未知狀態(tài),指控件被new出來(lái)之后什么都沒做
  • CURRENT_STATE_NORMAL 普通狀態(tài)
  • CURRENT_STATE_PREPARING 視頻準(zhǔn)備狀態(tài)
  • CURRENT_STATE_PREPARING_CHANGING_URL 播放中切換url的準(zhǔn)備狀態(tài)
  • CURRENT_STATE_PLAYING 播放中狀態(tài)
  • CURRENT_STATE_PAUSE 暫停狀態(tài)
  • CURRENT_STATE_AUTO_COMPLETE 自動(dòng)播放完成狀態(tài)
  • CURRENT_STATE_ERROR 錯(cuò)誤狀態(tài)

復(fù)寫進(jìn)入播放狀態(tài)的函數(shù)睦霎,取得播放狀態(tài)的回調(diào)

  • onStateNormal 進(jìn)入普通狀態(tài)梢卸,通常指setUp之后
  • onStatePreparing 進(jìn)入準(zhǔn)備中狀態(tài),就是loading狀態(tài)
  • onStatePlaying 進(jìn)入播放狀態(tài)
  • onStatePause 進(jìn)入暫停狀態(tài)
  • onStateError 進(jìn)入錯(cuò)誤狀態(tài)
  • onStateAutoComplete 進(jìn)入自動(dòng)播放完成狀態(tài)

全屏副女、小窗蛤高、非全屏分別是不同的實(shí)例,在繼承JzvdStd后碑幅,通過(guò)mCurrentScreen變量戴陡,取得當(dāng)前屏幕類型

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

事件

  • 復(fù)寫onProgress函數(shù),取得每次播放器設(shè)置底部seekBar的進(jìn)度回調(diào)
  • 調(diào)用changeUrl函數(shù)沟涨,切換url
  • 復(fù)寫onClick函數(shù)恤批,取得各種按鈕的點(diǎn)擊事件
  • 復(fù)寫onTouch函數(shù),取得全屏之后的手勢(shì)操作

JiaoZiVideoPlayer的功能遠(yuǎn)不止上述這些裹赴,最近我也在深入的研究中喜庞,下篇文章會(huì)收集一些大家經(jīng)常遇到的問題寫出來(lái)幫助大家,大家有什么建議或者問題可以再下方留言棋返。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末赋荆,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子懊昨,更是在濱河造成了極大的恐慌,老刑警劉巖春宣,帶你破解...
    沈念sama閱讀 206,378評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件酵颁,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡月帝,警方通過(guò)查閱死者的電腦和手機(jī)躏惋,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,356評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)嚷辅,“玉大人簿姨,你說(shuō)我怎么就攤上這事◆じ悖” “怎么了扁位?”我有些...
    開封第一講書人閱讀 152,702評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)趁俊。 經(jīng)常有香客問我域仇,道長(zhǎng),這世上最難降的妖魔是什么寺擂? 我笑而不...
    開封第一講書人閱讀 55,259評(píng)論 1 279
  • 正文 為了忘掉前任暇务,我火速辦了婚禮泼掠,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘垦细。我一直安慰自己择镇,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,263評(píng)論 5 371
  • 文/花漫 我一把揭開白布括改。 她就那樣靜靜地躺著腻豌,像睡著了一般。 火紅的嫁衣襯著肌膚如雪叹谁。 梳的紋絲不亂的頭發(fā)上饲梭,一...
    開封第一講書人閱讀 49,036評(píng)論 1 285
  • 那天,我揣著相機(jī)與錄音焰檩,去河邊找鬼憔涉。 笑死,一個(gè)胖子當(dāng)著我的面吹牛析苫,可吹牛的內(nèi)容都是我干的兜叨。 我是一名探鬼主播,決...
    沈念sama閱讀 38,349評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼衩侥,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼国旷!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起茫死,我...
    開封第一講書人閱讀 36,979評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤跪但,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后峦萎,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體屡久,經(jīng)...
    沈念sama閱讀 43,469評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,938評(píng)論 2 323
  • 正文 我和宋清朗相戀三年爱榔,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了被环。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,059評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡详幽,死狀恐怖筛欢,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情唇聘,我是刑警寧澤版姑,帶...
    沈念sama閱讀 33,703評(píng)論 4 323
  • 正文 年R本政府宣布,位于F島的核電站迟郎,受9級(jí)特大地震影響漠酿,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜谎亩,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,257評(píng)論 3 307
  • 文/蒙蒙 一炒嘲、第九天 我趴在偏房一處隱蔽的房頂上張望宇姚。 院中可真熱鬧,春花似錦夫凸、人聲如沸浑劳。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,262評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)魔熏。三九已至,卻和暖如春鸽扁,著一層夾襖步出監(jiān)牢的瞬間蒜绽,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工桶现, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留躲雅,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,501評(píng)論 2 354
  • 正文 我出身青樓骡和,卻偏偏與公主長(zhǎng)得像相赁,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子慰于,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,792評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容