SampleCoverVideo.java 5.3 KB
Newer Older
S
shuyu 已提交
1 2 3
package com.example.gsyvideoplayer.video;

import android.content.Context;
G
guoshuyu 已提交
4
import android.graphics.Point;
S
shuyu 已提交
5
import android.util.AttributeSet;
G
guoshuyu 已提交
6 7
import android.view.Surface;
import android.view.View;
S
shuyu 已提交
8
import android.widget.ImageView;
G
guoshuyu 已提交
9
import android.widget.SeekBar;
S
shuyu 已提交
10

11 12
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
S
shuyu 已提交
13
import com.example.gsyvideoplayer.R;
G
guoshuyu 已提交
14
import com.shuyu.gsyvideoplayer.utils.Debuger;
S
shuyu 已提交
15 16 17
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer;

G
guoshuyu 已提交
18 19
import moe.codeest.enviews.ENDownloadView;

S
shuyu 已提交
20 21 22 23 24 25 26 27 28
/**
 * 带封面
 * Created by guoshuyu on 2017/9/3.
 */

public class SampleCoverVideo extends StandardGSYVideoPlayer {

    ImageView mCoverImage;

G
guoshuyu 已提交
29
    String mCoverOriginUrl;
S
shuyu 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

    int mDefaultRes;

    public SampleCoverVideo(Context context, Boolean fullFlag) {
        super(context, fullFlag);
    }

    public SampleCoverVideo(Context context) {
        super(context);
    }

    public SampleCoverVideo(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void init(Context context) {
        super.init(context);
        mCoverImage = (ImageView) findViewById(R.id.thumbImage);
G
guoshuyu 已提交
49 50 51 52 53

        if (mThumbImageViewLayout != null &&
                (mCurrentState == -1 || mCurrentState == CURRENT_STATE_NORMAL || mCurrentState == CURRENT_STATE_ERROR)) {
            mThumbImageViewLayout.setVisibility(VISIBLE);
        }
S
shuyu 已提交
54 55 56 57 58 59 60 61
    }

    @Override
    public int getLayoutId() {
        return R.layout.video_layout_cover;
    }

    public void loadCoverImage(String url, int res) {
G
guoshuyu 已提交
62
        mCoverOriginUrl = url;
S
shuyu 已提交
63
        mDefaultRes = res;
64 65 66 67 68 69 70 71 72
        Glide.with(getContext().getApplicationContext())
                .setDefaultRequestOptions(
                        new RequestOptions()
                                .frame(1000000)
                                .centerCrop()
                                .error(res)
                                .placeholder(res))
                .load(url)
                .into(mCoverImage);
S
shuyu 已提交
73 74 75 76 77 78
    }

    @Override
    public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean actionBar, boolean statusBar) {
        GSYBaseVideoPlayer gsyBaseVideoPlayer = super.startWindowFullscreen(context, actionBar, statusBar);
        SampleCoverVideo sampleCoverVideo = (SampleCoverVideo) gsyBaseVideoPlayer;
G
guoshuyu 已提交
79
        sampleCoverVideo.loadCoverImage(mCoverOriginUrl, mDefaultRes);
S
shuyu 已提交
80 81
        return gsyBaseVideoPlayer;
    }
G
guoshuyu 已提交
82 83 84 85 86


    @Override
    public GSYBaseVideoPlayer showSmallVideo(Point size, boolean actionBar, boolean statusBar) {
        //下面这里替换成你自己的强制转化
G
guoshuyu 已提交
87
        SampleCoverVideo sampleCoverVideo = (SampleCoverVideo) super.showSmallVideo(size, actionBar, statusBar);
G
guoshuyu 已提交
88 89 90 91 92
        sampleCoverVideo.mStartButton.setVisibility(GONE);
        sampleCoverVideo.mStartButton = null;
        return sampleCoverVideo;
    }

G
guoshuyu 已提交
93 94 95
    /**
     * 下方两个重载方法,在播放开始前不屏蔽封面
     */
G
guoshuyu 已提交
96
    @Override
G
guoshuyu 已提交
97 98
    public void onSurfaceUpdated(Surface surface) {
        super.onSurfaceUpdated(surface);
G
guoshuyu 已提交
99
        if (mThumbImageViewLayout != null && mThumbImageViewLayout.getVisibility() == VISIBLE) {
G
guoshuyu 已提交
100
            mThumbImageViewLayout.setVisibility(INVISIBLE);
G
guoshuyu 已提交
101
        }
G
guoshuyu 已提交
102
    }
G
guoshuyu 已提交
103

G
guoshuyu 已提交
104 105 106 107
    @Override
    protected void setViewShowState(View view, int visibility) {
        if (view == mThumbImageViewLayout && visibility != VISIBLE) {
            return;
G
guoshuyu 已提交
108
        }
G
guoshuyu 已提交
109
        super.setViewShowState(view, visibility);
G
guoshuyu 已提交
110 111
    }

G
guoshuyu 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

    /**
     * 下方重载方法,在播放开始不显示底部进度和按键
     */

    protected boolean byStartedClick;

    @Override
    protected void onClickUiToggle() {
        if (mIfCurrentIsFullscreen && mLockCurScreen && mNeedLockFull) {
            setViewShowState(mLockScreen, VISIBLE);
            return;
        }
        byStartedClick = true;
        super.onClickUiToggle();

    }

    @Override
    protected void changeUiToNormal() {
        super.changeUiToNormal();
        byStartedClick = false;
    }

G
guoshuyu 已提交
136
    @Override
G
guoshuyu 已提交
137 138
    protected void changeUiToPreparingShow() {
        super.changeUiToPreparingShow();
G
guoshuyu 已提交
139 140 141 142 143 144 145 146 147
        Debuger.printfLog("Sample changeUiToPreparingShow");
        setViewShowState(mBottomContainer, INVISIBLE);
        setViewShowState(mStartButton, INVISIBLE);
    }

    @Override
    protected void changeUiToPlayingBufferingShow() {
        super.changeUiToPlayingBufferingShow();
        Debuger.printfLog("Sample changeUiToPlayingBufferingShow");
G
guoshuyu 已提交
148 149 150 151
        if (!byStartedClick) {
            setViewShowState(mBottomContainer, INVISIBLE);
            setViewShowState(mStartButton, INVISIBLE);
        }
G
guoshuyu 已提交
152 153 154 155 156 157 158 159 160 161
    }

    @Override
    protected void changeUiToPlayingShow() {
        super.changeUiToPlayingShow();
        Debuger.printfLog("Sample changeUiToPlayingShow");
        if (!byStartedClick) {
            setViewShowState(mBottomContainer, INVISIBLE);
            setViewShowState(mStartButton, INVISIBLE);
        }
G
guoshuyu 已提交
162 163 164 165 166
    }

    @Override
    public void startAfterPrepared() {
        super.startAfterPrepared();
G
guoshuyu 已提交
167
        Debuger.printfLog("Sample startAfterPrepared");
G
guoshuyu 已提交
168
        setViewShowState(mBottomContainer, INVISIBLE);
G
guoshuyu 已提交
169
        setViewShowState(mStartButton, INVISIBLE);
G
guoshuyu 已提交
170
    }
G
guoshuyu 已提交
171 172 173 174 175 176

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        byStartedClick = true;
        super.onStartTrackingTouch(seekBar);
    }
S
shuyu 已提交
177
}