GSYBaseVideoPlayer.java 22.5 KB
Newer Older
S
1.1.3  
shuyu 已提交
1 2 3 4
package com.shuyu.gsyvideoplayer.video;

import android.app.Activity;
import android.content.Context;
5
import android.graphics.Bitmap;
S
1.1.3  
shuyu 已提交
6
import android.graphics.Color;
S
shuyu 已提交
7
import android.graphics.Point;
S
1.1.3  
shuyu 已提交
8 9 10 11 12 13 14 15
import android.os.Handler;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
S
shuyu 已提交
16 17
import android.widget.SeekBar;
import android.widget.TextView;
S
1.1.3  
shuyu 已提交
18

19
import com.shuyu.gsyvideoplayer.GSYTextureView;
S
1.1.3  
shuyu 已提交
20 21 22
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.R;
S
shuyu 已提交
23
import com.shuyu.gsyvideoplayer.SmallVideoTouch;
S
1.1.3  
shuyu 已提交
24
import com.shuyu.gsyvideoplayer.listener.GSYMediaPlayerListener;
S
1.1.9  
shuyu 已提交
25
import com.shuyu.gsyvideoplayer.listener.VideoAllCallBack;
S
1.1.3  
shuyu 已提交
26
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
S
1.1.9  
shuyu 已提交
27
import com.shuyu.gsyvideoplayer.utils.Debuger;
S
1.1.3  
shuyu 已提交
28
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
S
1.2.4  
shuyu 已提交
29
import com.transitionseverywhere.TransitionManager;
S
1.1.3  
shuyu 已提交
30

S
1.3.0  
shuyu 已提交
31
import java.io.File;
S
1.1.3  
shuyu 已提交
32
import java.lang.reflect.Constructor;
S
1.3.0  
shuyu 已提交
33
import java.util.HashMap;
S
1.1.3  
shuyu 已提交
34 35 36 37
import java.util.Map;

import static com.shuyu.gsyvideoplayer.utils.CommonUtil.getActionBarHeight;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.getStatusBarHeight;
S
shuyu 已提交
38
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.hideNavKey;
S
1.1.3  
shuyu 已提交
39
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.hideSupportActionBar;
S
shuyu 已提交
40
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.showNavKey;
S
1.1.3  
shuyu 已提交
41 42 43 44 45 46 47 48
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.showSupportActionBar;

/**
 * Created by shuyu on 2016/11/17.
 */

public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMediaPlayerListener {

S
shuyu 已提交
49
    public static final int SMALL_ID = 84778;
S
1.1.3  
shuyu 已提交
50

S
1.1.9  
shuyu 已提交
51 52
    protected static final int FULLSCREEN_ID = 85597;

S
1.1.3  
shuyu 已提交
53 54 55 56 57 58
    protected static long CLICK_QUIT_FULLSCREEN_TIME = 0;

    protected boolean mActionBar = false;//是否需要在利用window实现全屏幕的时候隐藏actionbar

    protected boolean mStatusBar = false;//是否需要在利用window实现全屏幕的时候隐藏statusbar

S
shuyu 已提交
59 60
    protected boolean mHideKey = true;//是否隐藏虚拟按键

S
1.1.3  
shuyu 已提交
61 62
    protected boolean mCache = false;//是否播边边缓冲

S
1.1.6  
shuyu 已提交
63 64
    private boolean mShowFullAnimation = true;//是否使用全屏动画效果

S
shuyu 已提交
65 66
    protected boolean mNeedShowWifiTip = true; //是否需要显示流量提示

S
1.1.3  
shuyu 已提交
67 68 69 70 71 72
    protected int[] mListItemRect;//当前item框的屏幕位置

    protected int[] mListItemSize;//当前item的大小

    protected int mCurrentState = -1; //当前的播放状态

73 74
    protected int mRotate = 0; //针对某些视频的旋转信息做了旋转处理

75 76
    private int mSystemUiVisibility;

S
1.2.8  
shuyu 已提交
77 78
    protected float mSpeed = 1;//播放速度,只支持6.0以上

S
1.1.3  
shuyu 已提交
79 80
    protected boolean mRotateViewAuto = true; //是否自动旋转

S
1.2.5  
shuyu 已提交
81 82 83
    protected boolean mIfCurrentIsFullscreen = false;//当前是否全屏

    protected boolean mLockLand = false;//当前全屏是否锁定全屏
S
1.1.4  
shuyu 已提交
84

S
1.2.6  
shuyu 已提交
85 86
    protected boolean mLooping = false;//循环

S
1.2.7  
shuyu 已提交
87 88
    protected boolean mHadPlay = false;//是否播放过

S
shuyu 已提交
89 90
    protected boolean mCacheFile = false; //是否是缓存的文件

S
1.1.3  
shuyu 已提交
91 92
    protected Context mContext;

S
1.1.8  
shuyu 已提交
93 94
    protected String mOriginUrl; //原来的url

S
1.2.5  
shuyu 已提交
95
    protected String mUrl; //转化后的URL
S
1.1.3  
shuyu 已提交
96 97 98

    protected Object[] mObjects;

S
1.3.0  
shuyu 已提交
99 100
    protected File mCachePath;

S
1.2.5  
shuyu 已提交
101
    protected ViewGroup mTextureViewContainer; //渲染控件父类
S
1.1.3  
shuyu 已提交
102

S
1.2.5  
shuyu 已提交
103
    protected View mSmallClose; //小窗口关闭按键
S
1.1.9  
shuyu 已提交
104 105 106

    protected VideoAllCallBack mVideoAllCallBack;

S
1.3.0  
shuyu 已提交
107 108
    protected Map<String, String> mMapHeadData = new HashMap<>();

109
    protected GSYTextureView mTextureView;
S
1.1.3  
shuyu 已提交
110

111 112
    protected ImageView mCoverImageView; //内部使用,请勿操作哟~

S
shuyu 已提交
113 114 115 116 117 118 119
    protected View mStartButton;

    protected SeekBar mProgressBar;

    protected ImageView mFullscreenButton;

    protected TextView mCurrentTimeTextView, mTotalTimeTextView;
120

S
shuyu 已提交
121 122 123 124 125
    protected ViewGroup mTopContainer, mBottomContainer;

    protected ImageView mBackButton;

    protected Bitmap mFullPauseBitmap = null;//暂停时的全屏图片;
126

127
    protected OrientationUtils mOrientationUtils; //旋转工具类
128 129

    private Handler mHandler = new Handler();
S
shuyu 已提交
130

S
1.1.6  
shuyu 已提交
131

S
1.1.3  
shuyu 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    public GSYBaseVideoPlayer(Context context) {
        super(context);
    }

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

    public GSYBaseVideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    private ViewGroup getViewGroup() {
        return (ViewGroup) (CommonUtil.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);
    }

    /**
     * 移除没用的
     */
S
shuyu 已提交
152 153
    private void removeVideo(ViewGroup vp, int id) {
        View old = vp.findViewById(id);
S
1.1.3  
shuyu 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
        if (old != null) {
            if (old.getParent() != null) {
                ViewGroup viewGroup = (ViewGroup) old.getParent();
                vp.removeView(viewGroup);
            }
        }
    }

    /**
     * 保存大小和状态
     */
    private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) {
        getLocationOnScreen(mListItemRect);
        int statusBarH = getStatusBarHeight(context);
        int actionBerH = getActionBarHeight((Activity) context);
        if (statusBar) {
            mListItemRect[1] = mListItemRect[1] - statusBarH;
        }
        if (actionBar) {
            mListItemRect[1] = mListItemRect[1] - actionBerH;
        }
        mListItemSize[0] = getWidth();
        mListItemSize[1] = getHeight();
    }

    /**
     * 全屏
     */
S
shuyu 已提交
182
    private void resolveFullVideoShow(Context context, final GSYBaseVideoPlayer gsyVideoPlayer, final FrameLayout frameLayout) {
S
1.1.3  
shuyu 已提交
183 184 185 186 187 188
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) gsyVideoPlayer.getLayoutParams();
        lp.setMargins(0, 0, 0, 0);
        lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.gravity = Gravity.CENTER;
        gsyVideoPlayer.setLayoutParams(lp);
S
1.1.4  
shuyu 已提交
189
        gsyVideoPlayer.setIfCurrentIsFullscreen(true);
S
1.1.3  
shuyu 已提交
190 191
        mOrientationUtils = new OrientationUtils((Activity) context, gsyVideoPlayer);
        mOrientationUtils.setEnable(mRotateViewAuto);
192
        gsyVideoPlayer.mOrientationUtils = mOrientationUtils;
S
1.2.5  
shuyu 已提交
193

S
shuyu 已提交
194 195 196 197
        if (isShowFullAnimation()) {
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
198
                    if (mLockLand && mOrientationUtils.getIsLand() != 1) {
S
shuyu 已提交
199 200 201 202
                        mOrientationUtils.resolveByClick();
                    }
                    gsyVideoPlayer.setVisibility(VISIBLE);
                    frameLayout.setVisibility(VISIBLE);
S
1.2.5  
shuyu 已提交
203
                }
S
shuyu 已提交
204 205 206 207
            }, 300);
        } else {
            if (mLockLand) {
                mOrientationUtils.resolveByClick();
S
1.2.5  
shuyu 已提交
208
            }
S
shuyu 已提交
209 210 211
            gsyVideoPlayer.setVisibility(VISIBLE);
            frameLayout.setVisibility(VISIBLE);
        }
S
1.2.5  
shuyu 已提交
212 213


S
1.1.9  
shuyu 已提交
214 215 216 217 218
        if (mVideoAllCallBack != null) {
            Debuger.printfError("onEnterFullscreen");
            mVideoAllCallBack.onEnterFullscreen(mUrl, mObjects);
        }
        mIfCurrentIsFullscreen = true;
S
1.1.3  
shuyu 已提交
219 220 221 222 223 224
    }

    /**
     * 恢复
     */
    private void resolveNormalVideoShow(View oldF, ViewGroup vp, GSYVideoPlayer gsyVideoPlayer) {
225

S
1.2.5  
shuyu 已提交
226
        if (oldF != null && oldF.getParent() != null) {
S
1.1.3  
shuyu 已提交
227 228 229 230 231 232 233 234 235 236 237 238
            ViewGroup viewGroup = (ViewGroup) oldF.getParent();
            vp.removeView(viewGroup);
        }
        mCurrentState = GSYVideoManager.instance().getLastState();
        if (gsyVideoPlayer != null) {
            mCurrentState = gsyVideoPlayer.getCurrentState();
        }
        GSYVideoManager.instance().setListener(GSYVideoManager.instance().lastListener());
        GSYVideoManager.instance().setLastListener(null);
        setStateAndUi(mCurrentState);
        addTextureView();
        CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
S
1.1.9  
shuyu 已提交
239 240 241 242 243
        if (mVideoAllCallBack != null) {
            Debuger.printfError("onQuitFullscreen");
            mVideoAllCallBack.onQuitFullscreen(mUrl, mObjects);
        }
        mIfCurrentIsFullscreen = false;
S
shuyu 已提交
244 245 246
        if (mHideKey) {
            showNavKey(mContext, mSystemUiVisibility);
        }
247
        showSupportActionBar(mContext, mActionBar, mStatusBar);
S
1.1.3  
shuyu 已提交
248 249 250 251 252 253 254 255 256
    }

    /**
     * 利用window层播放全屏效果
     *
     * @param context
     * @param actionBar 是否有actionBar,有的话需要隐藏
     * @param statusBar 是否有状态bar,有的话需要隐藏
     */
S
1.2.6  
shuyu 已提交
257
    public GSYBaseVideoPlayer startWindowFullscreen(final Context context, final boolean actionBar, final boolean statusBar) {
S
1.1.3  
shuyu 已提交
258

S
shuyu 已提交
259 260
        mSystemUiVisibility = ((Activity) context).getWindow().getDecorView().getSystemUiVisibility();

S
1.1.3  
shuyu 已提交
261 262
        hideSupportActionBar(context, actionBar, statusBar);

S
shuyu 已提交
263 264 265 266
        if (mHideKey) {
            hideNavKey(context);
        }

S
1.1.3  
shuyu 已提交
267 268 269 270 271 272 273 274 275 276
        this.mActionBar = actionBar;

        this.mStatusBar = statusBar;

        mListItemRect = new int[2];

        mListItemSize = new int[2];

        final ViewGroup vp = getViewGroup();

S
shuyu 已提交
277
        removeVideo(vp, FULLSCREEN_ID);
S
1.1.3  
shuyu 已提交
278

279 280 281
        //处理暂停的逻辑
        pauseFullCoverLogic();

S
1.1.3  
shuyu 已提交
282 283 284 285 286 287 288 289 290 291 292
        if (mTextureViewContainer.getChildCount() > 0) {
            mTextureViewContainer.removeAllViews();
        }


        saveLocationStatus(context, statusBar, actionBar);

        try {
            Constructor<GSYBaseVideoPlayer> constructor = (Constructor<GSYBaseVideoPlayer>) GSYBaseVideoPlayer.this.getClass().getConstructor(Context.class);
            final GSYBaseVideoPlayer gsyVideoPlayer = constructor.newInstance(getContext());
            gsyVideoPlayer.setId(FULLSCREEN_ID);
S
1.1.9  
shuyu 已提交
293 294
            gsyVideoPlayer.setIfCurrentIsFullscreen(true);
            gsyVideoPlayer.setVideoAllCallBack(mVideoAllCallBack);
S
1.2.6  
shuyu 已提交
295
            gsyVideoPlayer.setLooping(isLooping());
S
1.2.8  
shuyu 已提交
296
            gsyVideoPlayer.setSpeed(getSpeed());
S
1.2.5  
shuyu 已提交
297 298
            final FrameLayout.LayoutParams lpParent = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            final FrameLayout frameLayout = new FrameLayout(context);
S
1.1.3  
shuyu 已提交
299 300
            frameLayout.setBackgroundColor(Color.BLACK);

S
1.2.4  
shuyu 已提交
301
            if (mShowFullAnimation) {
S
1.1.3  
shuyu 已提交
302 303 304 305 306 307 308 309
                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getWidth(), getHeight());
                lp.setMargins(mListItemRect[0], mListItemRect[1], 0, 0);
                frameLayout.addView(gsyVideoPlayer, lp);
                vp.addView(frameLayout, lpParent);
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        TransitionManager.beginDelayedTransition(vp);
S
shuyu 已提交
310
                        resolveFullVideoShow(context, gsyVideoPlayer, frameLayout);
S
1.1.3  
shuyu 已提交
311 312 313 314 315 316
                    }
                }, 300);
            } else {
                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getWidth(), getHeight());
                frameLayout.addView(gsyVideoPlayer, lp);
                vp.addView(frameLayout, lpParent);
S
1.2.5  
shuyu 已提交
317
                gsyVideoPlayer.setVisibility(INVISIBLE);
S
shuyu 已提交
318 319
                frameLayout.setVisibility(INVISIBLE);
                resolveFullVideoShow(context, gsyVideoPlayer, frameLayout);
S
1.1.3  
shuyu 已提交
320
            }
S
shuyu 已提交
321
            gsyVideoPlayer.mHadPlay = mHadPlay;
S
shuyu 已提交
322
            gsyVideoPlayer.mCacheFile = mCacheFile;
323
            gsyVideoPlayer.mFullPauseBitmap = mFullPauseBitmap;
S
shuyu 已提交
324
            gsyVideoPlayer.mNeedShowWifiTip = mNeedShowWifiTip;
S
1.3.0  
shuyu 已提交
325
            gsyVideoPlayer.setUp(mUrl, mCache, mCachePath, mMapHeadData, mObjects);
S
1.1.3  
shuyu 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
            gsyVideoPlayer.setStateAndUi(mCurrentState);
            gsyVideoPlayer.addTextureView();

            gsyVideoPlayer.getFullscreenButton().setImageResource(R.drawable.video_shrink);
            gsyVideoPlayer.getFullscreenButton().setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    clearFullscreenLayout();
                }
            });

            gsyVideoPlayer.getBackButton().setVisibility(VISIBLE);
            gsyVideoPlayer.getBackButton().setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    clearFullscreenLayout();
                }
            });

            GSYVideoManager.instance().setLastListener(this);
            GSYVideoManager.instance().setListener(gsyVideoPlayer);
S
1.2.6  
shuyu 已提交
347
            return gsyVideoPlayer;
S
1.1.3  
shuyu 已提交
348 349 350
        } catch (Exception e) {
            e.printStackTrace();
        }
S
1.2.6  
shuyu 已提交
351
        return null;
S
1.1.3  
shuyu 已提交
352 353 354 355 356 357 358
    }


    /**
     * 退出window层播放全屏效果
     */
    public void clearFullscreenLayout() {
S
1.3.6  
shuyu 已提交
359
        mIfCurrentIsFullscreen = false;
S
1.1.3  
shuyu 已提交
360 361
        int delay = mOrientationUtils.backToProtVideo();
        mOrientationUtils.setEnable(false);
362
        if (mOrientationUtils != null) {
S
shuyu 已提交
363
            mOrientationUtils.releaseListener();
364 365
            mOrientationUtils = null;
        }
S
1.1.3  
shuyu 已提交
366 367 368 369 370 371 372 373 374 375 376 377
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                backToNormal();
            }
        }, delay);
    }

    /**
     * 回到正常效果
     */
    private void backToNormal() {
S
shuyu 已提交
378

S
1.1.3  
shuyu 已提交
379 380 381 382 383 384
        final ViewGroup vp = getViewGroup();

        final View oldF = vp.findViewById(FULLSCREEN_ID);
        final GSYVideoPlayer gsyVideoPlayer;
        if (oldF != null) {
            gsyVideoPlayer = (GSYVideoPlayer) oldF;
385 386
            //如果暂停了
            pauseFullBackCoverLogic(gsyVideoPlayer);
S
1.2.4  
shuyu 已提交
387
            if (mShowFullAnimation) {
S
1.1.3  
shuyu 已提交
388 389 390 391 392 393 394 395 396 397
                TransitionManager.beginDelayedTransition(vp);

                FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) gsyVideoPlayer.getLayoutParams();
                lp.setMargins(mListItemRect[0], mListItemRect[1], 0, 0);
                lp.width = mListItemSize[0];
                lp.height = mListItemSize[1];
                //注意配置回来,不然动画效果会不对
                lp.gravity = Gravity.NO_GRAVITY;
                gsyVideoPlayer.setLayoutParams(lp);

S
1.2.5  
shuyu 已提交
398
                mHandler.postDelayed(new Runnable() {
S
1.1.3  
shuyu 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412
                    @Override
                    public void run() {
                        resolveNormalVideoShow(oldF, vp, gsyVideoPlayer);
                    }
                }, 400);
            } else {
                resolveNormalVideoShow(oldF, vp, gsyVideoPlayer);
            }

        } else {
            resolveNormalVideoShow(null, vp, null);
        }
    }

413 414 415 416 417 418
    /**
     * 全屏的暂停的时候返回页面不黑色
     */
    private void pauseFullCoverLogic() {
        if (mCurrentState == GSYVideoPlayer.CURRENT_STATE_PAUSE && mTextureView != null
                && (mFullPauseBitmap == null || mFullPauseBitmap.isRecycled())) {
419 420 421 422 423 424
            try {
                mFullPauseBitmap = mTextureView.getBitmap(mTextureView.getSizeW(), mTextureView.getSizeH());
            } catch (Exception e) {
                e.printStackTrace();
                mFullPauseBitmap = null;
            }
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
        }
    }

    /**
     * 全屏的暂停返回的时候返回页面不黑色
     */
    private void pauseFullBackCoverLogic(GSYBaseVideoPlayer gsyVideoPlayer) {
        //如果是暂停状态
        if (gsyVideoPlayer.mCurrentState == GSYVideoPlayer.CURRENT_STATE_PAUSE
                && gsyVideoPlayer.mTextureView != null) {
            //全屏的位图还在,说明没播放,直接用原来的
            if (gsyVideoPlayer.mFullPauseBitmap != null
                    && !gsyVideoPlayer.mFullPauseBitmap.isRecycled()) {
                mFullPauseBitmap = gsyVideoPlayer.mFullPauseBitmap;
            } else {
                //不在了说明已经播放过,还是暂停的话,我们拿回来就好
441 442 443 444 445 446
                try {
                    mFullPauseBitmap = mTextureView.getBitmap(mTextureView.getSizeW(), mTextureView.getSizeH());
                } catch (Exception e) {
                    e.printStackTrace();
                    mFullPauseBitmap = null;
                }
447 448 449 450 451
            }
        }
    }


S
shuyu 已提交
452 453 454
    /**
     * 显示小窗口
     */
S
1.2.6  
shuyu 已提交
455
    public GSYBaseVideoPlayer showSmallVideo(Point size, final boolean actionBar, final boolean statusBar) {
S
shuyu 已提交
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488

        final ViewGroup vp = getViewGroup();

        removeVideo(vp, SMALL_ID);

        if (mTextureViewContainer.getChildCount() > 0) {
            mTextureViewContainer.removeAllViews();
        }

        try {
            Constructor<GSYBaseVideoPlayer> constructor = (Constructor<GSYBaseVideoPlayer>) GSYBaseVideoPlayer.this.getClass().getConstructor(Context.class);
            GSYBaseVideoPlayer gsyVideoPlayer = constructor.newInstance(getContext());
            gsyVideoPlayer.setId(SMALL_ID);

            FrameLayout.LayoutParams lpParent = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            FrameLayout frameLayout = new FrameLayout(mContext);

            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(size.x, size.y);
            int marginLeft = CommonUtil.getScreenWidth(mContext) - size.x;
            int marginTop = CommonUtil.getScreenHeight(mContext) - size.y;

            if (actionBar) {
                marginTop = marginTop - getActionBarHeight((Activity) mContext);
            }

            if (statusBar) {
                marginTop = marginTop - getStatusBarHeight(mContext);
            }

            lp.setMargins(marginLeft, marginTop, 0, 0);
            frameLayout.addView(gsyVideoPlayer, lp);

            vp.addView(frameLayout, lpParent);
S
shuyu 已提交
489
            gsyVideoPlayer.mHadPlay = mHadPlay;
S
1.3.0  
shuyu 已提交
490
            gsyVideoPlayer.setUp(mUrl, mCache, mCachePath, mMapHeadData, mObjects);
S
shuyu 已提交
491 492
            gsyVideoPlayer.setStateAndUi(mCurrentState);
            gsyVideoPlayer.addTextureView();
S
1.2.1  
shuyu 已提交
493
            //隐藏掉所有的弹出状态哟
S
shuyu 已提交
494
            gsyVideoPlayer.onClickUiToggle();
S
1.2.1  
shuyu 已提交
495
            gsyVideoPlayer.setVideoAllCallBack(mVideoAllCallBack);
S
1.2.6  
shuyu 已提交
496
            gsyVideoPlayer.setLooping(isLooping());
S
1.2.8  
shuyu 已提交
497
            gsyVideoPlayer.setSpeed(getSpeed());
S
shuyu 已提交
498 499 500 501 502
            gsyVideoPlayer.setSmallVideoTextureView(new SmallVideoTouch(gsyVideoPlayer, marginLeft, marginTop));

            GSYVideoManager.instance().setLastListener(this);
            GSYVideoManager.instance().setListener(gsyVideoPlayer);

S
1.1.9  
shuyu 已提交
503 504 505 506 507
            if (mVideoAllCallBack != null) {
                Debuger.printfError("onEnterSmallWidget");
                mVideoAllCallBack.onEnterSmallWidget(mUrl, mObjects);
            }

S
1.2.6  
shuyu 已提交
508
            return gsyVideoPlayer;
S
shuyu 已提交
509 510 511
        } catch (Exception e) {
            e.printStackTrace();
        }
S
1.2.6  
shuyu 已提交
512
        return null;
S
shuyu 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
    }

    /**
     * 隐藏小窗口
     */
    public void hideSmallVideo() {
        final ViewGroup vp = getViewGroup();
        GSYVideoPlayer gsyVideoPlayer = (GSYVideoPlayer) vp.findViewById(SMALL_ID);
        removeVideo(vp, SMALL_ID);
        mCurrentState = GSYVideoManager.instance().getLastState();
        if (gsyVideoPlayer != null) {
            mCurrentState = gsyVideoPlayer.getCurrentState();
        }
        GSYVideoManager.instance().setListener(GSYVideoManager.instance().lastListener());
        GSYVideoManager.instance().setLastListener(null);
        setStateAndUi(mCurrentState);
        addTextureView();
        CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
S
1.1.9  
shuyu 已提交
531 532 533 534
        if (mVideoAllCallBack != null) {
            Debuger.printfLog("onQuitSmallWidget");
            mVideoAllCallBack.onQuitSmallWidget(mUrl, mObjects);
        }
S
shuyu 已提交
535 536
    }

S
1.1.3  
shuyu 已提交
537 538 539 540 541 542 543 544 545

    /**
     * 设置播放URL
     *
     * @param url
     * @param cacheWithPlay 是否边播边缓存
     * @param objects
     * @return
     */
S
shuyu 已提交
546
    public abstract boolean setUp(String url, boolean cacheWithPlay, File cachePath, Object... objects);
S
1.1.3  
shuyu 已提交
547 548 549 550 551 552 553 554 555 556 557

    /**
     * 设置播放URL
     *
     * @param url
     * @param cacheWithPlay 是否边播边缓存
     * @param mapHeadData
     * @param objects
     * @return
     */

S
1.3.0  
shuyu 已提交
558
    public abstract boolean setUp(String url, boolean cacheWithPlay, File cachePath, Map<String, String> mapHeadData, Object... objects);
S
1.1.3  
shuyu 已提交
559 560 561 562 563 564 565 566 567 568 569 570 571

    /**
     * 设置播放显示状态
     *
     * @param state
     */
    protected abstract void setStateAndUi(int state);

    /**
     * 添加播放的view
     */
    protected abstract void addTextureView();

S
shuyu 已提交
572 573 574 575 576
    /**
     * 小窗口
     **/
    protected abstract void setSmallVideoTextureView(View.OnTouchListener onTouchListener);

S
1.3.0  
shuyu 已提交
577

S
shuyu 已提交
578 579
    protected abstract void onClickUiToggle();

S
1.1.3  
shuyu 已提交
580 581 582 583 584 585 586 587 588 589 590
    /**
     * 获取全屏按键
     */
    public abstract ImageView getFullscreenButton();

    /**
     * 获取返回按键
     */
    public abstract ImageView getBackButton();


S
1.1.4  
shuyu 已提交
591 592 593 594 595 596 597 598
    public boolean isIfCurrentIsFullscreen() {
        return mIfCurrentIsFullscreen;
    }

    public void setIfCurrentIsFullscreen(boolean ifCurrentIsFullscreen) {
        this.mIfCurrentIsFullscreen = ifCurrentIsFullscreen;
    }

S
1.1.6  
shuyu 已提交
599

S
shuyu 已提交
600
    public boolean isShowFullAnimation() {
S
1.1.6  
shuyu 已提交
601 602 603 604 605 606 607 608 609 610 611
        return mShowFullAnimation;
    }

    /**
     * 全屏动画
     *
     * @param showFullAnimation 是否使用全屏动画效果
     */
    public void setShowFullAnimation(boolean showFullAnimation) {
        this.mShowFullAnimation = showFullAnimation;
    }
S
1.1.9  
shuyu 已提交
612 613


S
1.2.6  
shuyu 已提交
614 615 616 617 618 619 620 621 622 623 624 625
    public boolean isLooping() {
        return mLooping;
    }

    /**
     * 设置循环
     */
    public void setLooping(boolean looping) {
        this.mLooping = looping;
    }


S
1.1.9  
shuyu 已提交
626 627 628 629 630 631 632 633 634
    /**
     * 设置播放过程中的回调
     *
     * @param mVideoAllCallBack
     */
    public void setVideoAllCallBack(VideoAllCallBack mVideoAllCallBack) {
        this.mVideoAllCallBack = mVideoAllCallBack;
    }

S
1.2.5  
shuyu 已提交
635 636 637 638 639 640 641 642 643 644

    public boolean isRotateViewAuto() {
        return mRotateViewAuto;
    }

    /**
     * 是否开启自动旋转
     */
    public void setRotateViewAuto(boolean rotateViewAuto) {
        this.mRotateViewAuto = rotateViewAuto;
645 646 647
        if (mOrientationUtils != null) {
            mOrientationUtils.setEnable(rotateViewAuto);
        }
S
1.2.5  
shuyu 已提交
648 649 650 651 652 653 654 655 656 657 658 659
    }

    public boolean isLockLand() {
        return mLockLand;
    }

    /**
     * 一全屏就锁屏横屏,默认false竖屏,可配合setRotateViewAuto使用
     */
    public void setLockLand(boolean lockLand) {
        this.mLockLand = lockLand;
    }
S
1.2.8  
shuyu 已提交
660 661 662 663 664 665 666 667 668 669 670 671


    public float getSpeed() {
        return mSpeed;
    }

    /**
     * 播放速度,只支持6.0以上
     */
    public void setSpeed(float speed) {
        this.mSpeed = speed;
    }
S
shuyu 已提交
672 673 674 675 676 677

    public boolean isHideKey() {
        return mHideKey;
    }

    /**
S
1.3.5  
shuyu 已提交
678
     * 全屏隐藏虚拟按键,默认打开
S
shuyu 已提交
679 680 681 682
     */
    public void setHideKey(boolean hideKey) {
        this.mHideKey = hideKey;
    }
S
shuyu 已提交
683 684 685 686 687 688 689 690 691 692 693

    public boolean isNeedShowWifiTip() {
        return mNeedShowWifiTip;
    }

    /**
     * 是否需要显示流量提示,默认true
     */
    public void setNeedShowWifiTip(boolean needShowWifiTip) {
        this.mNeedShowWifiTip = needShowWifiTip;
    }
S
1.1.3  
shuyu 已提交
694
}