StandardGSYVideoPlayer.java 34.3 KB
Newer Older
S
shuyu 已提交
1 2 3 4 5 6 7
package com.shuyu.gsyvideoplayer.video;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
S
1.2.6  
shuyu 已提交
8
import android.graphics.Point;
S
1.1.8  
shuyu 已提交
9
import android.graphics.drawable.Drawable;
S
shuyu 已提交
10 11 12 13 14 15 16 17 18 19 20
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
S
shuyu 已提交
21
import android.widget.RelativeLayout;
S
shuyu 已提交
22 23 24 25 26 27 28 29
import android.widget.TextView;
import android.widget.Toast;


import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.R;
import com.shuyu.gsyvideoplayer.listener.StandardVideoAllCallBack;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
S
1.1.9  
shuyu 已提交
30
import com.shuyu.gsyvideoplayer.utils.Debuger;
S
shuyu 已提交
31
import com.shuyu.gsyvideoplayer.utils.NetworkUtils;
S
shuyu 已提交
32

S
1.3.0  
shuyu 已提交
33
import java.io.File;
S
shuyu 已提交
34 35 36
import java.util.Timer;
import java.util.TimerTask;

S
shuyu 已提交
37 38 39
import moe.codeest.enviews.ENDownloadView;
import moe.codeest.enviews.ENPlayView;

40

S
shuyu 已提交
41
/**
S
shuyu 已提交
42
 * 标准播放器
S
shuyu 已提交
43 44 45 46 47 48
 * Created by shuyu on 2016/11/11.
 */

public class StandardGSYVideoPlayer extends GSYVideoPlayer {


S
shuyu 已提交
49
    protected Timer DISSMISS_CONTROL_VIEW_TIMER;
S
shuyu 已提交
50

S
shuyu 已提交
51 52 53
    protected ProgressBar mBottomProgressBar;

    private ENDownloadView mLoadingProgressBar;
S
shuyu 已提交
54 55 56 57 58 59

    protected TextView mTitleTextView; //title

    protected RelativeLayout mThumbImageViewLayout;//封面父布局

    private View mThumbImageView; //封面
S
shuyu 已提交
60 61

    protected Dialog mBrightnessDialog;
S
shuyu 已提交
62

S
shuyu 已提交
63
    protected TextView mBrightnessDialogTv;
S
shuyu 已提交
64

S
shuyu 已提交
65
    protected Dialog mVolumeDialog;
S
shuyu 已提交
66

S
shuyu 已提交
67
    protected ProgressBar mDialogVolumeProgressBar;
S
shuyu 已提交
68 69 70 71

    protected StandardVideoAllCallBack mStandardVideoAllCallBack;//标准播放器的回调

    protected DismissControlViewTimerTask mDismissControlViewTimerTask;
S
shuyu 已提交
72

S
shuyu 已提交
73 74 75 76 77
    protected Dialog mProgressDialog;
    protected ProgressBar mDialogProgressBar;
    protected TextView mDialogSeekTime;
    protected TextView mDialogTotalTime;
    protected ImageView mDialogIcon;
S
shuyu 已提交
78
    protected ImageView mLockScreen;
S
shuyu 已提交
79

S
1.1.8  
shuyu 已提交
80 81 82 83 84 85
    protected Drawable mBottomProgressDrawable;
    protected Drawable mBottomShowProgressDrawable;
    protected Drawable mBottomShowProgressThumbDrawable;
    protected Drawable mVolumeProgressDrawable;
    protected Drawable mDialogProgressBarDrawable;

S
shuyu 已提交
86 87 88 89 90 91
    protected boolean mLockCurScreen;//锁定屏幕点击

    protected boolean mNeedLockFull;//是否需要锁定屏幕

    private boolean mThumbPlay;//是否点击封面播放

S
1.1.8  
shuyu 已提交
92 93 94 95
    private int mDialogProgressHighLightColor = -11;

    private int mDialogProgressNormalColor = -11;

S
shuyu 已提交
96

S
shuyu 已提交
97
    public void setStandardVideoAllCallBack(StandardVideoAllCallBack standardVideoAllCallBack) {
S
shuyu 已提交
98
        this.mStandardVideoAllCallBack = standardVideoAllCallBack;
S
shuyu 已提交
99
        setVideoAllCallBack(standardVideoAllCallBack);
S
shuyu 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112
    }

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

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

    @Override
    protected void init(Context context) {
        super.init(context);
S
shuyu 已提交
113 114 115
        mBottomProgressBar = (ProgressBar) findViewById(R.id.bottom_progressbar);
        mTitleTextView = (TextView) findViewById(R.id.title);
        mThumbImageViewLayout = (RelativeLayout) findViewById(R.id.thumb);
S
shuyu 已提交
116
        mLockScreen = (ImageView) findViewById(R.id.lock_screen);
117

S
shuyu 已提交
118
        mLoadingProgressBar = (ENDownloadView) findViewById(R.id.loading);
S
shuyu 已提交
119 120 121 122

        mThumbImageViewLayout.setVisibility(GONE);
        mThumbImageViewLayout.setOnClickListener(this);
        mBackButton.setOnClickListener(this);
123
        if (mThumbImageView != null && !mIfCurrentIsFullscreen) {
S
shuyu 已提交
124 125
            mThumbImageViewLayout.removeAllViews();
            resolveThumbImage(mThumbImageView);
S
shuyu 已提交
126
        }
S
shuyu 已提交
127

S
1.1.8  
shuyu 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140

        if (mBottomProgressDrawable != null) {
            mBottomProgressBar.setProgressDrawable(mBottomProgressDrawable);
        }

        if (mBottomShowProgressDrawable != null) {
            mProgressBar.setProgressDrawable(mBottomProgressDrawable);
        }

        if (mBottomShowProgressThumbDrawable != null) {
            mProgressBar.setThumb(mBottomShowProgressThumbDrawable);
        }

S
shuyu 已提交
141 142 143 144 145 146 147 148
        mLockScreen.setVisibility(GONE);

        mLockScreen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mLockCurScreen) {
                    mLockScreen.setImageResource(R.drawable.unlock);
                    mLockCurScreen = false;
149 150
                    if (mOrientationUtils != null)
                        mOrientationUtils.setEnable(mRotateViewAuto);
S
shuyu 已提交
151 152 153
                } else {
                    mLockScreen.setImageResource(R.drawable.lock);
                    mLockCurScreen = true;
154 155
                    if (mOrientationUtils != null)
                        mOrientationUtils.setEnable(false);
S
shuyu 已提交
156 157 158 159 160
                    hideAllWidget();
                }
            }
        });

S
shuyu 已提交
161 162
    }

S
false  
shuyu 已提交
163 164 165 166 167 168 169 170
    /**
     * 设置播放URL
     *
     * @param url           播放url
     * @param cacheWithPlay 是否边播边缓存
     * @param objects       object[0]目前为title
     * @return
     */
S
shuyu 已提交
171 172
    @Override
    public boolean setUp(String url, boolean cacheWithPlay, Object... objects) {
S
1.3.0  
shuyu 已提交
173 174 175
        return setUp(url, cacheWithPlay, (File) null, objects);
    }

S
false  
shuyu 已提交
176 177 178 179 180 181 182 183 184
    /**
     * 设置播放URL
     *
     * @param url           播放url
     * @param cacheWithPlay 是否边播边缓存
     * @param cachePath     缓存路径,如果是M3U8或者HLS,请设置为false
     * @param objects       object[0]目前为title
     * @return
     */
S
1.3.0  
shuyu 已提交
185 186 187 188 189 190
    @Override
    public boolean setUp(String url, boolean cacheWithPlay, File cachePath, Object... objects) {
        if (super.setUp(url, cacheWithPlay, cachePath, objects)) {
            if (objects != null && objects.length > 0) {
                mTitleTextView.setText(objects[0].toString());
            }
S
shuyu 已提交
191
            if (mIfCurrentIsFullscreen) {
S
shuyu 已提交
192
                mFullscreenButton.setImageResource(R.drawable.video_shrink);
S
shuyu 已提交
193
            } else {
S
shuyu 已提交
194 195
                mFullscreenButton.setImageResource(R.drawable.video_enlarge);
                mBackButton.setVisibility(View.GONE);
S
shuyu 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
            }
            return true;
        }
        return false;
    }

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

    @Override
    protected void setStateAndUi(int state) {
        super.setStateAndUi(state);
        switch (mCurrentState) {
            case CURRENT_STATE_NORMAL:
                changeUiToNormal();
                break;
            case CURRENT_STATE_PREPAREING:
                changeUiToPrepareingShow();
                startDismissControlViewTimer();
                break;
            case CURRENT_STATE_PLAYING:
                changeUiToPlayingShow();
                startDismissControlViewTimer();
                break;
            case CURRENT_STATE_PAUSE:
                changeUiToPauseShow();
                cancelDismissControlViewTimer();
                break;
            case CURRENT_STATE_ERROR:
                changeUiToError();
                break;
            case CURRENT_STATE_AUTO_COMPLETE:
                changeUiToCompleteShow();
                cancelDismissControlViewTimer();
S
shuyu 已提交
232
                mBottomProgressBar.setProgress(100);
S
shuyu 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
                break;
            case CURRENT_STATE_PLAYING_BUFFERING_START:
                changeUiToPlayingBufferingShow();
                break;
        }
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int id = v.getId();
        if (id == R.id.surface_container) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    break;
                case MotionEvent.ACTION_MOVE:
                    break;
                case MotionEvent.ACTION_UP:
                    startDismissControlViewTimer();
                    if (mChangePosition) {
                        int duration = getDuration();
                        int progress = mSeekTimePosition * 100 / (duration == 0 ? 1 : duration);
S
shuyu 已提交
254
                        mBottomProgressBar.setProgress(progress);
S
shuyu 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
                    }
                    if (!mChangePosition && !mChangeVolume && !mBrightness) {
                        onClickUiToggle();
                    }
                    break;
            }
        } else if (id == R.id.progress) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    cancelDismissControlViewTimer();
                    break;
                case MotionEvent.ACTION_UP:
                    startDismissControlViewTimer();
                    break;
            }
        }
S
shuyu 已提交
271 272 273 274 275

        if (mIfCurrentIsFullscreen && mLockCurScreen && mNeedLockFull) {
            return true;
        }

S
shuyu 已提交
276 277 278 279 280 281 282 283
        return super.onTouch(v, event);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        int i = v.getId();
        if (i == R.id.thumb) {
S
1.3.0  
shuyu 已提交
284 285 286
            if (!mThumbPlay) {
                return;
            }
S
shuyu 已提交
287 288 289 290 291
            if (TextUtils.isEmpty(mUrl)) {
                Toast.makeText(getContext(), getResources().getString(R.string.no_url), Toast.LENGTH_SHORT).show();
                return;
            }
            if (mCurrentState == CURRENT_STATE_NORMAL) {
S
shuyu 已提交
292
                if (!mUrl.startsWith("file") && !CommonUtil.isWifiConnected(getContext()) && mNeedShowWifiTip) {
S
shuyu 已提交
293 294 295
                    showWifiDialog();
                    return;
                }
S
shuyu 已提交
296
                startPlayLogic();
S
shuyu 已提交
297 298 299 300
            } else if (mCurrentState == CURRENT_STATE_AUTO_COMPLETE) {
                onClickUiToggle();
            }
        } else if (i == R.id.surface_container) {
S
shuyu 已提交
301
            if (mStandardVideoAllCallBack != null && isCurrentMediaListener()) {
S
shuyu 已提交
302
                if (mIfCurrentIsFullscreen) {
S
1.1.9  
shuyu 已提交
303
                    Debuger.printfLog("onClickBlankFullscreen");
S
shuyu 已提交
304
                    mStandardVideoAllCallBack.onClickBlankFullscreen(mUrl, mObjects);
S
shuyu 已提交
305
                } else {
S
1.1.9  
shuyu 已提交
306
                    Debuger.printfLog("onClickBlank");
S
shuyu 已提交
307
                    mStandardVideoAllCallBack.onClickBlank(mUrl, mObjects);
S
shuyu 已提交
308 309 310 311 312 313 314 315 316
                }
            }
            startDismissControlViewTimer();
        }
    }

    @Override
    public void showWifiDialog() {
        super.showWifiDialog();
S
shuyu 已提交
317 318 319 320
        if (!NetworkUtils.isAvailable(mContext)) {
            Toast.makeText(mContext, getResources().getString(R.string.no_net), Toast.LENGTH_LONG).show();
            return;
        }
S
shuyu 已提交
321 322 323 324 325 326
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setMessage(getResources().getString(R.string.tips_not_wifi));
        builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
S
shuyu 已提交
327
                startPlayLogic();
S
shuyu 已提交
328 329 330 331 332 333 334 335 336 337 338
            }
        });
        builder.setNegativeButton(getResources().getString(R.string.tips_not_wifi_cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
    }

S
shuyu 已提交
339 340

    @Override
S
shuyu 已提交
341
    public void startPlayLogic() {
S
shuyu 已提交
342
        if (mStandardVideoAllCallBack != null) {
S
1.1.9  
shuyu 已提交
343
            Debuger.printfLog("onClickStartThumb");
S
shuyu 已提交
344
            mStandardVideoAllCallBack.onClickStartThumb(mUrl, mObjects);
S
shuyu 已提交
345 346 347 348 349
        }
        prepareVideo();
        startDismissControlViewTimer();
    }

S
shuyu 已提交
350 351
    @Override
    protected void onClickUiToggle() {
S
shuyu 已提交
352 353 354 355
        if (mIfCurrentIsFullscreen && mLockCurScreen && mNeedLockFull) {
            mLockScreen.setVisibility(VISIBLE);
            return;
        }
S
shuyu 已提交
356
        if (mCurrentState == CURRENT_STATE_PREPAREING) {
S
shuyu 已提交
357
            if (mBottomContainer.getVisibility() == View.VISIBLE) {
S
shuyu 已提交
358 359 360 361 362
                changeUiToPrepareingClear();
            } else {
                changeUiToPrepareingShow();
            }
        } else if (mCurrentState == CURRENT_STATE_PLAYING) {
S
shuyu 已提交
363
            if (mBottomContainer.getVisibility() == View.VISIBLE) {
S
shuyu 已提交
364 365 366 367 368
                changeUiToPlayingClear();
            } else {
                changeUiToPlayingShow();
            }
        } else if (mCurrentState == CURRENT_STATE_PAUSE) {
S
shuyu 已提交
369
            if (mBottomContainer.getVisibility() == View.VISIBLE) {
S
shuyu 已提交
370 371 372 373 374
                changeUiToPauseClear();
            } else {
                changeUiToPauseShow();
            }
        } else if (mCurrentState == CURRENT_STATE_AUTO_COMPLETE) {
S
shuyu 已提交
375
            if (mBottomContainer.getVisibility() == View.VISIBLE) {
S
shuyu 已提交
376 377 378 379 380
                changeUiToCompleteClear();
            } else {
                changeUiToCompleteShow();
            }
        } else if (mCurrentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
S
shuyu 已提交
381
            if (mBottomContainer.getVisibility() == View.VISIBLE) {
S
shuyu 已提交
382 383 384 385 386 387 388 389 390 391
                changeUiToPlayingBufferingClear();
            } else {
                changeUiToPlayingBufferingShow();
            }
        }
    }

    @Override
    protected void setProgressAndTime(int progress, int secProgress, int currentTime, int totalTime) {
        super.setProgressAndTime(progress, secProgress, currentTime, totalTime);
S
shuyu 已提交
392
        if (progress != 0) mBottomProgressBar.setProgress(progress);
393
        if (secProgress != 0 && !mCacheFile) mBottomProgressBar.setSecondaryProgress(secProgress);
S
shuyu 已提交
394 395 396 397 398
    }

    @Override
    protected void resetProgressAndTime() {
        super.resetProgressAndTime();
S
shuyu 已提交
399 400
        mBottomProgressBar.setProgress(0);
        mBottomProgressBar.setSecondaryProgress(0);
S
shuyu 已提交
401 402 403 404
    }

    //Unified management Ui
    private void changeUiToNormal() {
S
1.3.5  
shuyu 已提交
405
        Debuger.printfLog("changeUiToNormal");
S
shuyu 已提交
406 407 408 409
        mTopContainer.setVisibility(View.VISIBLE);
        mBottomContainer.setVisibility(View.INVISIBLE);
        mStartButton.setVisibility(View.VISIBLE);
        mLoadingProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
410
        mLoadingProgressBar.reset();
S
shuyu 已提交
411 412 413
        mThumbImageViewLayout.setVisibility(View.VISIBLE);
        mCoverImageView.setVisibility(View.VISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
414
        mLockScreen.setVisibility((mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
S
shuyu 已提交
415 416 417 418
        updateStartImage();
    }

    private void changeUiToPrepareingShow() {
S
1.3.5  
shuyu 已提交
419
        Debuger.printfLog("changeUiToPrepareingShow");
S
shuyu 已提交
420 421 422 423
        mTopContainer.setVisibility(View.VISIBLE);
        mBottomContainer.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.INVISIBLE);
        mLoadingProgressBar.setVisibility(View.VISIBLE);
S
shuyu 已提交
424
        mLoadingProgressBar.start();
S
shuyu 已提交
425 426 427
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
        mCoverImageView.setVisibility(View.VISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
428
        mLockScreen.setVisibility(GONE);
S
shuyu 已提交
429 430 431
    }

    private void changeUiToPrepareingClear() {
S
1.3.5  
shuyu 已提交
432
        Debuger.printfLog("changeUiToPrepareingClear");
S
shuyu 已提交
433 434 435 436 437 438
        mTopContainer.setVisibility(View.INVISIBLE);
        mBottomContainer.setVisibility(View.INVISIBLE);
        mStartButton.setVisibility(View.INVISIBLE);
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
        mCoverImageView.setVisibility(View.VISIBLE);
S
shuyu 已提交
439
        mLockScreen.setVisibility(GONE);
S
shuyu 已提交
440 441 442
    }

    private void changeUiToPlayingShow() {
S
1.3.5  
shuyu 已提交
443
        Debuger.printfLog("changeUiToPlayingShow");
S
shuyu 已提交
444 445 446 447
        mTopContainer.setVisibility(View.VISIBLE);
        mBottomContainer.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.VISIBLE);
        mLoadingProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
448
        mLoadingProgressBar.reset();
S
shuyu 已提交
449 450 451
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
        mCoverImageView.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
452
        mLockScreen.setVisibility((mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
S
shuyu 已提交
453 454 455 456
        updateStartImage();
    }

    private void changeUiToPlayingClear() {
S
1.3.5  
shuyu 已提交
457
        Debuger.printfLog("changeUiToPlayingClear");
S
shuyu 已提交
458
        changeUiToClear();
S
shuyu 已提交
459
        mBottomProgressBar.setVisibility(View.VISIBLE);
S
shuyu 已提交
460 461 462
    }

    private void changeUiToPauseShow() {
S
1.3.5  
shuyu 已提交
463
        Debuger.printfLog("changeUiToPauseShow");
S
shuyu 已提交
464 465 466 467
        mTopContainer.setVisibility(View.VISIBLE);
        mBottomContainer.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.VISIBLE);
        mLoadingProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
468
        mLoadingProgressBar.reset();
S
shuyu 已提交
469
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
470
        //mCoverImageView.setVisibility(View.INVISIBLE);
S
shuyu 已提交
471
        mBottomProgressBar.setVisibility(View.INVISIBLE);
472
        mLockScreen.setVisibility((mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
S
shuyu 已提交
473
        updateStartImage();
474
        updatePauseCover();
S
shuyu 已提交
475 476 477
    }

    private void changeUiToPauseClear() {
S
1.3.5  
shuyu 已提交
478
        Debuger.printfLog("changeUiToPauseClear");
S
shuyu 已提交
479
        changeUiToClear();
S
shuyu 已提交
480
        mBottomProgressBar.setVisibility(View.VISIBLE);
481
        updatePauseCover();
S
shuyu 已提交
482 483 484
    }

    private void changeUiToPlayingBufferingShow() {
S
1.3.5  
shuyu 已提交
485
        Debuger.printfLog("changeUiToPlayingBufferingShow");
S
shuyu 已提交
486 487 488 489
        mTopContainer.setVisibility(View.VISIBLE);
        mBottomContainer.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.INVISIBLE);
        mLoadingProgressBar.setVisibility(View.VISIBLE);
S
shuyu 已提交
490
        mLoadingProgressBar.start();
S
shuyu 已提交
491 492 493
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
        mCoverImageView.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
494
        mLockScreen.setVisibility(GONE);
S
shuyu 已提交
495 496 497
    }

    private void changeUiToPlayingBufferingClear() {
S
1.3.5  
shuyu 已提交
498
        Debuger.printfLog("changeUiToPlayingBufferingClear");
S
shuyu 已提交
499 500 501 502
        mTopContainer.setVisibility(View.INVISIBLE);
        mBottomContainer.setVisibility(View.INVISIBLE);
        mStartButton.setVisibility(View.INVISIBLE);
        mLoadingProgressBar.setVisibility(View.VISIBLE);
S
shuyu 已提交
503
        mLoadingProgressBar.start();
S
shuyu 已提交
504 505 506
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
        mCoverImageView.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.VISIBLE);
S
shuyu 已提交
507
        mLockScreen.setVisibility(GONE);
S
shuyu 已提交
508 509 510 511
        updateStartImage();
    }

    private void changeUiToClear() {
S
1.3.5  
shuyu 已提交
512
        Debuger.printfLog("changeUiToClear");
S
shuyu 已提交
513 514 515 516
        mTopContainer.setVisibility(View.INVISIBLE);
        mBottomContainer.setVisibility(View.INVISIBLE);
        mStartButton.setVisibility(View.INVISIBLE);
        mLoadingProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
517
        mLoadingProgressBar.reset();
S
shuyu 已提交
518 519 520
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
        mCoverImageView.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
521
        mLockScreen.setVisibility(GONE);
S
shuyu 已提交
522 523 524
    }

    private void changeUiToCompleteShow() {
S
1.3.5  
shuyu 已提交
525
        Debuger.printfLog("changeUiToCompleteShow");
S
shuyu 已提交
526 527 528 529
        mTopContainer.setVisibility(View.VISIBLE);
        mBottomContainer.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.VISIBLE);
        mLoadingProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
530
        mLoadingProgressBar.reset();
S
shuyu 已提交
531 532 533
        mThumbImageViewLayout.setVisibility(View.VISIBLE);
        mCoverImageView.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
534
        mLockScreen.setVisibility((mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
S
shuyu 已提交
535 536 537 538
        updateStartImage();
    }

    private void changeUiToCompleteClear() {
S
1.3.5  
shuyu 已提交
539
        Debuger.printfLog("changeUiToCompleteClear");
S
shuyu 已提交
540 541 542 543
        mTopContainer.setVisibility(View.INVISIBLE);
        mBottomContainer.setVisibility(View.INVISIBLE);
        mStartButton.setVisibility(View.VISIBLE);
        mLoadingProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
544
        mLoadingProgressBar.reset();
S
shuyu 已提交
545 546 547
        mThumbImageViewLayout.setVisibility(View.VISIBLE);
        mCoverImageView.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.VISIBLE);
548
        mLockScreen.setVisibility((mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
S
shuyu 已提交
549 550 551 552
        updateStartImage();
    }

    private void changeUiToError() {
S
1.3.5  
shuyu 已提交
553
        Debuger.printfLog("changeUiToError");
S
shuyu 已提交
554 555 556 557
        mTopContainer.setVisibility(View.INVISIBLE);
        mBottomContainer.setVisibility(View.INVISIBLE);
        mStartButton.setVisibility(View.VISIBLE);
        mLoadingProgressBar.setVisibility(View.INVISIBLE);
S
shuyu 已提交
558
        mLoadingProgressBar.reset();
S
shuyu 已提交
559 560 561
        mThumbImageViewLayout.setVisibility(View.INVISIBLE);
        mCoverImageView.setVisibility(View.VISIBLE);
        mBottomProgressBar.setVisibility(View.INVISIBLE);
562
        mLockScreen.setVisibility((mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
S
shuyu 已提交
563 564 565 566
        updateStartImage();
    }

    private void updateStartImage() {
S
shuyu 已提交
567 568
        ENPlayView enPlayView = (ENPlayView) mStartButton;
        enPlayView.setDuration(500);
S
shuyu 已提交
569
        if (mCurrentState == CURRENT_STATE_PLAYING) {
S
shuyu 已提交
570 571
            enPlayView.play();
            //mStartButton.setImageResource(R.drawable.video_click_pause_selector);
S
shuyu 已提交
572
        } else if (mCurrentState == CURRENT_STATE_ERROR) {
S
shuyu 已提交
573 574
            enPlayView.pause();
            //mStartButton.setImageResource(R.drawable.video_click_error_selector);
S
shuyu 已提交
575
        } else {
S
shuyu 已提交
576 577
            enPlayView.pause();
            //mStartButton.setImageResource(R.drawable.video_click_play_selector);
S
shuyu 已提交
578 579 580
        }
    }

581 582 583

    private void updatePauseCover() {
        if (mFullPauseBitmap == null || mFullPauseBitmap.isRecycled()) {
584 585 586 587 588 589
            try {
                mFullPauseBitmap = mTextureView.getBitmap(mTextureView.getSizeW(), mTextureView.getSizeH());
            } catch (Exception e) {
                e.printStackTrace();
                mFullPauseBitmap = null;
            }
590 591 592 593
        }
        showPauseCover();
    }

S
shuyu 已提交
594 595 596 597 598 599
    @Override
    protected void showProgressDialog(float deltaX, String seekTime, int seekTimePosition, String totalTime, int totalTimeDuration) {
        super.showProgressDialog(deltaX, seekTime, seekTimePosition, totalTime, totalTimeDuration);
        if (mProgressDialog == null) {
            View localView = LayoutInflater.from(getContext()).inflate(R.layout.video_progress_dialog, null);
            mDialogProgressBar = ((ProgressBar) localView.findViewById(R.id.duration_progressbar));
S
1.1.8  
shuyu 已提交
600 601 602
            if (mDialogProgressBarDrawable != null) {
                mDialogProgressBar.setProgressDrawable(mDialogProgressBarDrawable);
            }
S
shuyu 已提交
603 604 605 606 607 608 609 610
            mDialogSeekTime = ((TextView) localView.findViewById(R.id.tv_current));
            mDialogTotalTime = ((TextView) localView.findViewById(R.id.tv_duration));
            mDialogIcon = ((ImageView) localView.findViewById(R.id.duration_image_tip));
            mProgressDialog = new Dialog(getContext(), R.style.video_style_dialog_progress);
            mProgressDialog.setContentView(localView);
            mProgressDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
            mProgressDialog.getWindow().addFlags(32);
            mProgressDialog.getWindow().addFlags(16);
611
            mProgressDialog.getWindow().setLayout(getWidth(), getHeight());
S
1.2.6  
shuyu 已提交
612
            if (mDialogProgressNormalColor != -11) {
S
1.1.8  
shuyu 已提交
613 614 615 616 617
                mDialogTotalTime.setTextColor(mDialogProgressNormalColor);
            }
            if (mDialogProgressHighLightColor != -11) {
                mDialogSeekTime.setTextColor(mDialogProgressHighLightColor);
            }
S
shuyu 已提交
618
            WindowManager.LayoutParams localLayoutParams = mProgressDialog.getWindow().getAttributes();
619 620 621
            localLayoutParams.gravity = Gravity.TOP;
            localLayoutParams.width = getWidth();
            localLayoutParams.height = getHeight();
622 623 624 625
            int location[] = new int[2];
            getLocationOnScreen(location);
            localLayoutParams.x = location[0];
            localLayoutParams.y = location[1];
S
shuyu 已提交
626 627 628 629 630 631 632 633
            mProgressDialog.getWindow().setAttributes(localLayoutParams);
        }
        if (!mProgressDialog.isShowing()) {
            mProgressDialog.show();
        }

        mDialogSeekTime.setText(seekTime);
        mDialogTotalTime.setText(" / " + totalTime);
634 635
        if (totalTimeDuration > 0)
            mDialogProgressBar.setProgress(seekTimePosition * 100 / totalTimeDuration);
S
shuyu 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
        if (deltaX > 0) {
            mDialogIcon.setBackgroundResource(R.drawable.video_forward_icon);
        } else {
            mDialogIcon.setBackgroundResource(R.drawable.video_backward_icon);
        }

    }

    @Override
    protected void dismissProgressDialog() {
        super.dismissProgressDialog();
        if (mProgressDialog != null) {
            mProgressDialog.dismiss();
        }
    }

    @Override
    protected void showVolumeDialog(float deltaY, int volumePercent) {
        super.showVolumeDialog(deltaY, volumePercent);
        if (mVolumeDialog == null) {
            View localView = LayoutInflater.from(getContext()).inflate(R.layout.video_volume_dialog, null);
            mDialogVolumeProgressBar = ((ProgressBar) localView.findViewById(R.id.volume_progressbar));
S
1.1.8  
shuyu 已提交
658 659 660
            if (mVolumeProgressDrawable != null) {
                mDialogVolumeProgressBar.setProgressDrawable(mVolumeProgressDrawable);
            }
S
shuyu 已提交
661 662 663 664 665 666 667
            mVolumeDialog = new Dialog(getContext(), R.style.video_style_dialog_progress);
            mVolumeDialog.setContentView(localView);
            mVolumeDialog.getWindow().addFlags(8);
            mVolumeDialog.getWindow().addFlags(32);
            mVolumeDialog.getWindow().addFlags(16);
            mVolumeDialog.getWindow().setLayout(-2, -2);
            WindowManager.LayoutParams localLayoutParams = mVolumeDialog.getWindow().getAttributes();
668 669 670
            localLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            localLayoutParams.width = getWidth();
            localLayoutParams.height = getHeight();
671 672 673 674
            int location[] = new int[2];
            getLocationOnScreen(location);
            localLayoutParams.x = location[0];
            localLayoutParams.y = location[1];
S
shuyu 已提交
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
            mVolumeDialog.getWindow().setAttributes(localLayoutParams);
        }
        if (!mVolumeDialog.isShowing()) {
            mVolumeDialog.show();
        }

        mDialogVolumeProgressBar.setProgress(volumePercent);
    }

    @Override
    protected void dismissVolumeDialog() {
        super.dismissVolumeDialog();
        if (mVolumeDialog != null) {
            mVolumeDialog.dismiss();
        }
    }

    @Override
    protected void showBrightnessDialog(float percent) {
        if (mBrightnessDialog == null) {
            View localView = LayoutInflater.from(getContext()).inflate(R.layout.video_brightness, null);
            mBrightnessDialogTv = (TextView) localView.findViewById(R.id.app_video_brightness);
            mBrightnessDialog = new Dialog(getContext(), R.style.video_style_dialog_progress);
            mBrightnessDialog.setContentView(localView);
            mBrightnessDialog.getWindow().addFlags(8);
            mBrightnessDialog.getWindow().addFlags(32);
            mBrightnessDialog.getWindow().addFlags(16);
            mBrightnessDialog.getWindow().setLayout(-2, -2);
            WindowManager.LayoutParams localLayoutParams = mBrightnessDialog.getWindow().getAttributes();
704 705 706
            localLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
            localLayoutParams.width = getWidth();
            localLayoutParams.height = getHeight();
707 708 709 710
            int location[] = new int[2];
            getLocationOnScreen(location);
            localLayoutParams.x = location[0];
            localLayoutParams.y = location[1];
S
shuyu 已提交
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
            mBrightnessDialog.getWindow().setAttributes(localLayoutParams);
        }
        if (!mBrightnessDialog.isShowing()) {
            mBrightnessDialog.show();
        }
        if (mBrightnessDialogTv != null)
            mBrightnessDialogTv.setText((int) (percent * 100) + "%");
    }

    @Override
    protected void dismissBrightnessDialog() {
        super.dismissVolumeDialog();
        if (mBrightnessDialog != null) {
            mBrightnessDialog.dismiss();
        }
    }

S
1.2.6  
shuyu 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
    @Override
    protected void loopSetProgressAndTime() {
        super.loopSetProgressAndTime();
        mBottomProgressBar.setProgress(0);
    }


    @Override
    public void onBackFullscreen() {
        clearFullscreenLayout();
    }


    @Override
    public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean actionBar, boolean statusBar) {
        GSYBaseVideoPlayer gsyBaseVideoPlayer = super.startWindowFullscreen(context, actionBar, statusBar);
        if (gsyBaseVideoPlayer != null) {
            StandardGSYVideoPlayer gsyVideoPlayer = (StandardGSYVideoPlayer) gsyBaseVideoPlayer;
            gsyVideoPlayer.setStandardVideoAllCallBack(mStandardVideoAllCallBack);
S
shuyu 已提交
747
            gsyVideoPlayer.setNeedLockFull(isNeedLockFull());
748
            initFullUI(gsyVideoPlayer);
S
1.2.6  
shuyu 已提交
749 750 751 752 753 754 755 756 757 758 759 760 761 762
        }
        return gsyBaseVideoPlayer;
    }


    @Override
    public GSYBaseVideoPlayer showSmallVideo(Point size, boolean actionBar, boolean statusBar) {
        GSYBaseVideoPlayer gsyBaseVideoPlayer = super.showSmallVideo(size, actionBar, statusBar);
        if (gsyBaseVideoPlayer != null) {
            StandardGSYVideoPlayer gsyVideoPlayer = (StandardGSYVideoPlayer) gsyBaseVideoPlayer;
            gsyVideoPlayer.setStandardVideoAllCallBack(mStandardVideoAllCallBack);
        }
        return gsyBaseVideoPlayer;
    }
S
shuyu 已提交
763

S
1.3.0  
shuyu 已提交
764 765 766 767 768 769 770
    /**
     * 初始化为正常状态
     */
    public void initUIState() {
        setStateAndUi(CURRENT_STATE_NORMAL);
    }

771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
    /**
     * 全屏的UI逻辑
     */
    private void initFullUI(StandardGSYVideoPlayer standardGSYVideoPlayer) {

        if (mBottomProgressDrawable != null) {
            standardGSYVideoPlayer.setBottomProgressBarDrawable(mBottomProgressDrawable);
        }

        if (mBottomShowProgressDrawable != null && mBottomShowProgressThumbDrawable != null) {
            standardGSYVideoPlayer.setBottomShowProgressBarDrawable(mBottomShowProgressDrawable,
                    mBottomShowProgressThumbDrawable);
        }

        if (mVolumeProgressDrawable != null) {
            standardGSYVideoPlayer.setDialogVolumeProgressBar(mVolumeProgressDrawable);
        }

        if (mDialogProgressBarDrawable != null) {
            standardGSYVideoPlayer.setDialogProgressBar(mDialogProgressBarDrawable);
        }

        if (mDialogProgressHighLightColor >= 0 && mDialogProgressNormalColor >= 0) {
            standardGSYVideoPlayer.setDialogProgressColor(mDialogProgressHighLightColor, mDialogProgressNormalColor);
        }
    }

S
shuyu 已提交
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
    private void startDismissControlViewTimer() {
        cancelDismissControlViewTimer();
        DISSMISS_CONTROL_VIEW_TIMER = new Timer();
        mDismissControlViewTimerTask = new DismissControlViewTimerTask();
        DISSMISS_CONTROL_VIEW_TIMER.schedule(mDismissControlViewTimerTask, 2500);
    }

    private void cancelDismissControlViewTimer() {
        if (DISSMISS_CONTROL_VIEW_TIMER != null) {
            DISSMISS_CONTROL_VIEW_TIMER.cancel();
        }
        if (mDismissControlViewTimerTask != null) {
            mDismissControlViewTimerTask.cancel();
        }

    }

    protected class DismissControlViewTimerTask extends TimerTask {

        @Override
        public void run() {
            if (mCurrentState != CURRENT_STATE_NORMAL
                    && mCurrentState != CURRENT_STATE_ERROR
                    && mCurrentState != CURRENT_STATE_AUTO_COMPLETE) {
                if (getContext() != null && getContext() instanceof Activity) {
                    ((Activity) getContext()).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
S
shuyu 已提交
826 827
                            hideAllWidget();
                            mLockScreen.setVisibility(GONE);
S
shuyu 已提交
828 829 830 831 832 833
                        }
                    });
                }
            }
        }
    }
S
shuyu 已提交
834

S
1.4.4  
shuyu 已提交
835
    protected void hideAllWidget() {
S
shuyu 已提交
836 837 838 839 840 841
        mBottomContainer.setVisibility(View.INVISIBLE);
        mTopContainer.setVisibility(View.INVISIBLE);
        mBottomProgressBar.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.INVISIBLE);
    }

S
shuyu 已提交
842
    private void resolveThumbImage(View thumb) {
S
shuyu 已提交
843
        mThumbImageViewLayout.addView(thumb);
S
shuyu 已提交
844 845 846 847 848 849 850 851 852 853
        ViewGroup.LayoutParams layoutParams = thumb.getLayoutParams();
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        thumb.setLayoutParams(layoutParams);
    }

    /***
     * 设置封面
     */
    public void setThumbImageView(View view) {
S
shuyu 已提交
854 855
        if (mThumbImageViewLayout != null) {
            mThumbImageView = view;
S
shuyu 已提交
856 857 858 859 860 861 862 863
            resolveThumbImage(view);
        }
    }

    /***
     * 清除封面
     */
    public void clearThumbImageView() {
S
shuyu 已提交
864 865
        if (mThumbImageViewLayout != null) {
            mThumbImageViewLayout.removeAllViews();
S
shuyu 已提交
866 867 868
        }
    }

S
shuyu 已提交
869 870 871
    /**
     * 回去title
     */
S
shuyu 已提交
872
    public TextView getTitleTextView() {
S
shuyu 已提交
873
        return mTitleTextView;
S
shuyu 已提交
874 875
    }

S
shuyu 已提交
876

S
1.1.8  
shuyu 已提交
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
    /**
     * 底部进度条-弹出的
     */
    public void setBottomShowProgressBarDrawable(Drawable drawable, Drawable thumb) {
        mBottomShowProgressDrawable = drawable;
        mBottomShowProgressThumbDrawable = thumb;
        if (mProgressBar != null) {
            mProgressBar.setProgressDrawable(drawable);
            mProgressBar.setThumb(thumb);
        }
    }

    /**
     * 底部进度条-非弹出
     */
    public void setBottomProgressBarDrawable(Drawable drawable) {
        mBottomProgressDrawable = drawable;
        if (mBottomProgressBar != null) {
            mBottomProgressBar.setProgressDrawable(drawable);
        }
    }

    /**
     * 声音进度条
     */
    public void setDialogVolumeProgressBar(Drawable drawable) {
        mVolumeProgressDrawable = drawable;
    }


    /**
     * 中间进度条
     */
    public void setDialogProgressBar(Drawable drawable) {
        mDialogProgressBarDrawable = drawable;
    }

    /**
     * 中间进度条字体颜色
     */
    public void setDialogProgressColor(int highLightColor, int normalColor) {
        mDialogProgressHighLightColor = highLightColor;
        mDialogProgressNormalColor = normalColor;
    }

S
1.3.0  
shuyu 已提交
922 923 924 925 926 927 928 929 930 931 932 933 934
    /**
     * 是否点击封面可以播放
     */
    public void setThumbPlay(boolean thumbPlay) {
        this.mThumbPlay = thumbPlay;
    }

    /**
     * 封面布局
     */
    public RelativeLayout getThumbImageViewLayout() {
        return mThumbImageViewLayout;
    }
S
shuyu 已提交
935

S
shuyu 已提交
936 937 938 939 940 941 942

    public boolean isNeedLockFull() {
        return mNeedLockFull;
    }

    /**
     * 是否需要全屏锁定屏幕功能
S
shuyu 已提交
943
     * 如果单独使用请设置setIfCurrentIsFullscreen为true
S
shuyu 已提交
944 945 946 947 948 949
     */
    public void setNeedLockFull(boolean needLoadFull) {
        this.mNeedLockFull = needLoadFull;
    }


S
shuyu 已提交
950
}