admin
2020-10-15 cd89367a01870afb5c1e818895abb03ffea42d88
library-mine/src/com/lcjian/library/video/VideoPlayerController.java
@@ -58,6 +58,7 @@
    private String videoName;
    private String videoUrl;
    private boolean collected;//是否收藏
    private String mResourceName;
    private Timer timer;
@@ -98,6 +99,8 @@
    //正在播放的位置
    private int mPlayingPosition;
    private int mShowType;//1-长条 2-小方格
    private AQuery aq;
@@ -187,15 +190,17 @@
     *
     * @param episodeList
     * @param videoName
     * @param videoUrl
     * @param playingPosition
     * @return
     */
    public VideoPlayerController setVideoInfo(List<VideoEpisode> episodeList, String videoName, String videoUrl, int playingPosition) {
        this.videoName = videoName;
        this.videoUrl = videoUrl;
    public VideoPlayerController setVideoInfo(List<VideoEpisode> episodeList, int playingPosition, int showType, String resourceName) {
        VideoEpisode currentVideoEpisode = episodeList.get(playingPosition);
        this.videoName = currentVideoEpisode.getName();
        this.videoUrl = currentVideoEpisode.getVideoUrl();
        this.episodeList = episodeList;
        this.mPlayingPosition = playingPosition;
        this.mShowType = showType;
        this.mResourceName = resourceName;
        return this;
    }
@@ -262,6 +267,7 @@
                                    VideoPlayerController.this.continuePlay();
                                    //不需要提醒
                                    needNotifyMobileData = false;
                                    setPlayImage();
                                }
                                @Override
@@ -271,6 +277,8 @@
                            }).build(mActivity);
                        if (!networkNotiftDialog.isShowing())
                            networkNotiftDialog.show();
                    } else {
                        continuePlay();
                    }
                    break;
                case ConnectivityManager.TYPE_WIFI:
@@ -286,7 +294,30 @@
            pausePlay();
        }
        //设置播放按钮的状态按钮的
        setPlayImage();
    }
    private void setPlayImage() {
        if (iv_play != null)
            iv_play.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (mediaPlayer == null) {
                        return;
                    }
                    VideoResourceUtil.setPlayImage(iv_play, mediaPlayer.isPlaying(), isLand);
                    if (mediaPlayer.isPlaying()) {
                        aq.id(R.id.iv_play_center).visibility(View.GONE);
                    } else {
                        if (!isLand) {
                            aq.id(R.id.iv_play_center).visibility(View.VISIBLE);
                        }
                    }
                }
            }, 100);
    }
    /**
     * 设置电量变化
@@ -362,7 +393,10 @@
        public void onProgressChanged(SeekBar seekBar, int precent, boolean b) {
            if (isTouch) {
                //计算  拖拉后的  时间长度:
                int positionLong = mediaPlayer.getDuration() * seekBar.getProgress() / 1000;
                int process = mediaPlayer.getDuration();
                float f = seekBar.getProgress() / 1000.0f;
                int positionLong = (int) (process * f);
                Log.i(TAG, "position:" + positionLong);
                mediaPlayer.seekTo(positionLong);
            }
@@ -395,6 +429,7 @@
        setLayout();
        tv_title.setText(videoName);
        tv_link.setText(videoUrl);
        tv_resource.setText("来源:" + mResourceName);
        setCollect(this.collected);
        showLoading();
@@ -437,7 +472,7 @@
            @Override
            public void onClick(View v) {
                //当前集
                episodeDialog = new VideoEpisodeDialog.Builder().setEpisodes(episodeList, mPlayingPosition, 1).setDialogClick(new VideoEpisodeDialog.IDialogClick() {
                episodeDialog = new VideoEpisodeDialog.Builder().setEpisodes(episodeList, mPlayingPosition, mShowType).setDialogClick(new VideoEpisodeDialog.IDialogClick() {
                    @Override
                    public void selectEpisode(int p, VideoEpisode ve) {
                        if (videoPlayerListener != null)
@@ -464,11 +499,10 @@
                if (mediaPlayer != null) {
                    if (mediaPlayer.isPlaying()) {
                        mediaPlayer.pause();
                        VideoResourceUtil.setPlayImage(iv_play, true, isLand);
                    } else {
                        mediaPlayer.start();
                        VideoResourceUtil.setPlayImage(iv_play, false, isLand);
                    }
                    setPlayerState();
                }
            }
        });
@@ -621,6 +655,7 @@
    }
    private void setLayout() {
        Log.i(TAG, "setLayout");
        if (isLand) {
            findViewById(R.id.fl_state).setVisibility(View.VISIBLE);
//            if (iv_collection.getVisibility() == View.GONE)
@@ -684,8 +719,13 @@
            if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                int currentPosition = getSeconds(mediaPlayer.getCurrentPosition());
                tv_progress.setText(TimeUtil.getTimeDesc(currentPosition));
                seekBar.setProgress(Math.round(mediaPlayer.getCurrentPosition() * 1000 / mediaPlayer.getDuration()));
                setPlayerState();
                seekBar.setProgress(Math.round(mediaPlayer.getCurrentPosition() * 1000.0f / mediaPlayer.getDuration()));
                Log.i(TAG, Math.abs(mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition()) + "");
                if (Math.abs(mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition()) < 1000) {//播放完成
                    tv_progress.removeCallbacks(playerProcessRunnable);
                    iv_next.performClick();
                    return;
                }
            }
            tv_progress.postDelayed(playerProcessRunnable, 1000);
        }
@@ -729,15 +769,7 @@
    private void setPlayerState() {
        if (mediaPlayer != null) {
            if (mediaPlayer.isPlaying()) {
                VideoResourceUtil.setPlayImage(iv_play, false, isLand);
                aq.id(R.id.iv_play_center).visibility(View.GONE);
            } else {
                VideoResourceUtil.setPlayImage(iv_play, true, isLand);
                if (!isLand) {
                    aq.id(R.id.iv_play_center).visibility(View.VISIBLE);
                }
            }
            setPlayImage();
        }
    }
@@ -817,6 +849,14 @@
        aq.id(R.id.fl_loading).visibility(View.GONE);
    }
    public void onResume() {
        setLayout();
    }
    public void onPause() {
        setLayout();
    }
    /**
     * 释放资源
     */