Example usage for android.view TextureView TextureView

List of usage examples for android.view TextureView TextureView

Introduction

In this page you can find the example usage for android.view TextureView TextureView.

Prototype

public TextureView(Context context) 

Source Link

Document

Creates a new TextureView.

Usage

From source file:im.ene.toro.exoplayer.ExoVideoView.java

public ExoVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // By default, TextureView is used for Android 23 and below, and SurfaceView is for the rest
    boolean useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ExoVideoView, 0, 0);
        try {//from   w  ww. j  av a 2 s. co  m
            int surfaceType = a.getInt(R.styleable.ExoVideoView_tx1_surfaceType, SURFACE_TYPE_DEFAULT);
            switch (surfaceType) {
            case SURFACE_TYPE_SURFACE_VIEW:
                useTextureView = false;
                break;
            case SURFACE_TYPE_TEXTURE_VIEW:
                useTextureView = true;
                break;
            case SURFACE_TYPE_DEFAULT:
            default:
                // Unchanged, so don't need to execute the line below
                // useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
                break;
            }

            resizeMode = a.getInt(R.styleable.ExoVideoView_tx1_resizeMode, RESIZE_MODE_FIXED_WIDTH);
        } finally {
            a.recycle();
        }
    }

    View view = useTextureView ? new TextureView(context) : new SurfaceView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(params);
    surfaceView = view;
    addView(surfaceView, 0);

    playerListener = new VideoPlayerListener();

    SurfaceHelper surfaceHelper = SurfaceHelper.Factory.getInstance(this, surfaceView);
    surfaceHelper.setupForView(surfaceView);

    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();
}

From source file:com.example.android.foldinglayout.FoldingLayoutActivity.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void initTextureView() {
    if (hasApiLevel(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
        mTextureView = new TextureView(this);
        ((TextureView) mTextureView).setSurfaceTextureListener(createSurfaceTextureListener());
    }/*from w  w  w.  j  a  va2s .  c  o m*/
}

From source file:com.ezartech.ezar.videooverlay.ezAR.java

@Override
public void initialize(final CordovaInterface cordova, final CordovaWebView cvWebView) {
    super.initialize(cordova, cvWebView);

    webViewView = cvWebView.getView();/*from w w w. ja  v a  2  s.c o m*/

    activity = cordova.getActivity();
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {

            //configure webview
            webViewView.setKeepScreenOn(true);

            Log.d(TAG, "WebView HW accelerated: " + webViewView.isHardwareAccelerated());
            // if (webViewView.isHardwareAccelerated()) {
            //    webViewView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null);
            // } else {
            //    webViewView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
            // }

            //temporarily remove webview from view stack
            ((ViewGroup) webViewView.getParent()).removeView(webViewView);

            cordovaViewContainer = new FrameLayout(activity);
            cordovaViewContainer.setBackgroundColor(Color.BLACK);
            activity.setContentView(cordovaViewContainer,
                    new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            //create & add videoOverlay to view stack

            cameraView = new TextureView(activity);
            cameraView.setSurfaceTextureListener(mSurfaceTextureListener);
            cordovaViewContainer.addView(cameraView,
                    new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            //add webview on top of videoOverlay
            cordovaViewContainer.addView(webViewView,
                    new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            if ("org.xwalk.core.XWalkView".equals(webViewView.getClass().getName())
                    || "org.crosswalk.engine.XWalkCordovaView".equals(webViewView.getClass().getName())) {
                try {
                    /* view.setZOrderOnTop(true)
                     * Called just in time as with root.setBackground(...) the color
                     * come in front and take the whoel screen */
                    webViewView.getClass().getMethod("setZOrderOnTop", boolean.class).invoke(webViewView, true);
                } catch (Exception e) {
                }
            }
            ((FrameLayout) cordovaViewContainer.getParent()).addOnLayoutChangeListener(layoutChangeListener);
            ((FrameLayout) cordovaViewContainer.getParent()).setBackgroundColor(Color.BLACK);
        }
    });
}

From source file:im.ene.toro.exoplayer2.ExoVideoView.java

public ExoVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // By default, TextureView is used for Android 23 and below, and SurfaceView is for the rest
    boolean useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ExoVideoView, 0, 0);
        try {/*from w ww  .j  a v  a 2 s  .  co  m*/
            int surfaceType = a.getInt(R.styleable.ExoVideoView_tx2_surfaceType, SURFACE_TYPE_DEFAULT);
            switch (surfaceType) {
            case SURFACE_TYPE_SURFACE_VIEW:
                useTextureView = false;
                break;
            case SURFACE_TYPE_TEXTURE_VIEW:
                useTextureView = true;
                break;
            case SURFACE_TYPE_DEFAULT:
            default:
                // Unchanged, so don't need to execute the line below
                // useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
                break;
            }

            resizeMode = a.getInt(R.styleable.ExoVideoView_tx2_resizeMode, RESIZE_MODE_FIXED_WIDTH);
        } finally {
            a.recycle();
        }
    }

    View view = useTextureView ? new TextureView(context) : new SurfaceView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(params);
    surfaceView = view;
    addView(surfaceView, 0);

    shutterView = new View(context);
    ViewGroup.LayoutParams shutterViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    shutterView.setLayoutParams(shutterViewParams);
    shutterView.setBackgroundColor(Color.BLACK);
    addView(shutterView);

    window = new Timeline.Window();

    componentListener = new ComponentListener();

    mediaDataSourceFactory = buildDataSourceFactory(true);
    mainHandler = new Handler();

    if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
        CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
    }

    requestFocus();
}

From source file:org.telegram.ui.ChannelAdminLogActivity.java

private TextureView createTextureView(boolean add) {
    if (parentLayout == null) {
        return null;
    }//from w  ww.java2 s .  c o m
    if (roundVideoContainer == null) {
        if (Build.VERSION.SDK_INT >= 21) {
            roundVideoContainer = new FrameLayout(getParentActivity()) {
                @Override
                public void setTranslationY(float translationY) {
                    super.setTranslationY(translationY);
                    contentView.invalidate();
                }
            };
            roundVideoContainer.setOutlineProvider(new ViewOutlineProvider() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.roundMessageSize, AndroidUtilities.roundMessageSize);
                }
            });
            roundVideoContainer.setClipToOutline(true);
        } else {
            roundVideoContainer = new FrameLayout(getParentActivity()) {
                @Override
                protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                    super.onSizeChanged(w, h, oldw, oldh);
                    aspectPath.reset();
                    aspectPath.addCircle(w / 2, h / 2, w / 2, Path.Direction.CW);
                    aspectPath.toggleInverseFillType();
                }

                @Override
                public void setTranslationY(float translationY) {
                    super.setTranslationY(translationY);
                    contentView.invalidate();
                }

                @Override
                public void setVisibility(int visibility) {
                    super.setVisibility(visibility);
                    if (visibility == VISIBLE) {
                        setLayerType(View.LAYER_TYPE_HARDWARE, null);
                    }
                }

                @Override
                protected void dispatchDraw(Canvas canvas) {
                    super.dispatchDraw(canvas);
                    canvas.drawPath(aspectPath, aspectPaint);
                }
            };
            aspectPath = new Path();
            aspectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            aspectPaint.setColor(0xff000000);
            aspectPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        }
        roundVideoContainer.setWillNotDraw(false);
        roundVideoContainer.setVisibility(View.INVISIBLE);

        aspectRatioFrameLayout = new AspectRatioFrameLayout(getParentActivity());
        aspectRatioFrameLayout.setBackgroundColor(0);
        if (add) {
            roundVideoContainer.addView(aspectRatioFrameLayout,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        }

        videoTextureView = new TextureView(getParentActivity());
        videoTextureView.setOpaque(false);
        aspectRatioFrameLayout.addView(videoTextureView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    }
    if (roundVideoContainer.getParent() == null) {
        contentView.addView(roundVideoContainer, 1, new FrameLayout.LayoutParams(
                AndroidUtilities.roundMessageSize, AndroidUtilities.roundMessageSize));
    }
    roundVideoContainer.setVisibility(View.INVISIBLE);
    aspectRatioFrameLayout.setDrawingReady(false);
    return videoTextureView;
}

From source file:org.telegram.ui.ArticleViewer.java

public void setParentActivity(Activity activity) {
    if (parentActivity == activity) {
        return;/*  www. ja  v  a 2  s . c o  m*/
    }
    parentActivity = activity;

    backgroundPaint = new Paint();
    backgroundPaint.setColor(0xffffffff);

    layerShadowDrawable = activity.getResources().getDrawable(R.drawable.layer_shadow);
    slideDotDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_small);
    slideDotBigDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_big);
    scrimPaint = new Paint();

    windowView = new WindowView(activity);
    windowView.setWillNotDraw(false);
    windowView.setClipChildren(true);
    windowView.setFocusable(false);

    containerView = new FrameLayout(activity);
    windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    containerView.setFitsSystemWindows(true);
    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @SuppressLint("NewApi")
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                WindowInsets oldInsets = (WindowInsets) lastInsets;
                lastInsets = insets;
                if (oldInsets == null || !oldInsets.toString().equals(insets.toString())) {
                    windowView.requestLayout();
                }
                return insets.consumeSystemWindowInsets();
            }
        });
    }
    containerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);

    photoContainerBackground = new View(activity);
    photoContainerBackground.setVisibility(View.INVISIBLE);
    photoContainerBackground.setBackgroundDrawable(photoBackgroundDrawable);
    windowView.addView(photoContainerBackground, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    animatingImageView = new ClippingImageView(activity);
    animatingImageView.setAnimationValues(animationValues);
    animatingImageView.setVisibility(View.GONE);
    windowView.addView(animatingImageView, LayoutHelper.createFrame(40, 40));

    photoContainerView = new FrameLayoutDrawer(activity) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            int y = bottom - top - captionTextView.getMeasuredHeight();
            if (bottomLayout.getVisibility() == VISIBLE) {
                y -= bottomLayout.getMeasuredHeight();
            }
            captionTextView.layout(0, y, captionTextView.getMeasuredWidth(),
                    y + captionTextView.getMeasuredHeight());
        }
    };
    photoContainerView.setVisibility(View.INVISIBLE);
    photoContainerView.setWillNotDraw(false);
    windowView.addView(photoContainerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    fullscreenVideoContainer = new FrameLayout(activity);
    fullscreenVideoContainer.setBackgroundColor(0xff000000);
    fullscreenVideoContainer.setVisibility(View.INVISIBLE);
    windowView.addView(fullscreenVideoContainer,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    fullscreenAspectRatioView = new AspectRatioFrameLayout(activity);
    fullscreenAspectRatioView.setVisibility(View.GONE);
    fullscreenVideoContainer.addView(fullscreenAspectRatioView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));

    fullscreenTextureView = new TextureView(activity);

    if (Build.VERSION.SDK_INT >= 21) {
        barBackground = new View(activity);
        barBackground.setBackgroundColor(0xff000000);
        windowView.addView(barBackground);
    }

    listView = new RecyclerListView(activity);
    listView.setLayoutManager(
            layoutManager = new LinearLayoutManager(parentActivity, LinearLayoutManager.VERTICAL, false));
    listView.setAdapter(adapter = new WebpageAdapter(parentActivity));
    listView.setClipToPadding(false);
    listView.setPadding(0, AndroidUtilities.dp(56), 0, 0);
    listView.setTopGlowOffset(AndroidUtilities.dp(56));
    listView.setGlowColor(0xfff5f6f7);
    containerView.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
        @Override
        public boolean onItemClick(View view, int position) {
            return false;
        }
    });
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position == blocks.size() && currentPage != null) {
                if (previewsReqId != 0) {
                    return;
                }
                TLRPC.User user = MessagesController.getInstance().getUser("previews");
                if (user != null) {
                    openPreviewsChat(user, currentPage.id);
                } else {
                    final long pageId = currentPage.id;
                    showProgressView(true);
                    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
                    req.username = "previews";
                    previewsReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                        @Override
                        public void run(final TLObject response, final TLRPC.TL_error error) {
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public void run() {
                                    if (previewsReqId == 0) {
                                        return;
                                    }
                                    previewsReqId = 0;
                                    showProgressView(false);
                                    if (response != null) {
                                        TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                                        MessagesController.getInstance().putUsers(res.users, false);
                                        MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats,
                                                false, true);
                                        if (!res.users.isEmpty()) {
                                            openPreviewsChat(res.users.get(0), pageId);
                                        }
                                    }
                                }
                            });
                        }
                    });
                }
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (listView.getChildCount() == 0) {
                return;
            }
            checkScroll(dy);
        }
    });
    headerView = new FrameLayout(activity);
    headerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    headerView.setBackgroundColor(0xff000000);
    containerView.addView(headerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56));

    backButton = new ImageView(activity);
    backButton.setScaleType(ImageView.ScaleType.CENTER);
    backDrawable = new BackDrawable(false);
    backDrawable.setAnimationTime(200.0f);
    backDrawable.setColor(0xffb3b3b3);
    backDrawable.setRotated(false);
    backButton.setImageDrawable(backDrawable);
    backButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    headerView.addView(backButton, LayoutHelper.createFrame(54, 56));
    backButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*if (collapsed) {
            uncollapse();
            } else {
            collapse();
            }*/
            close(true, true);
        }
    });

    shareContainer = new FrameLayout(activity);
    headerView.addView(shareContainer, LayoutHelper.createFrame(48, 56, Gravity.TOP | Gravity.RIGHT));
    shareContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (currentPage == null || parentActivity == null) {
                return;
            }
            showDialog(new ShareAlert(parentActivity, null, currentPage.url, false, currentPage.url, true));
            hideActionBar();
        }
    });

    shareButton = new ImageView(activity);
    shareButton.setScaleType(ImageView.ScaleType.CENTER);
    shareButton.setImageResource(R.drawable.ic_share_article);
    shareButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    shareContainer.addView(shareButton, LayoutHelper.createFrame(48, 56));

    progressView = new ContextProgressView(activity, 2);
    progressView.setVisibility(View.GONE);
    shareContainer.addView(progressView, LayoutHelper.createFrame(48, 56));

    windowLayoutParams = new WindowManager.LayoutParams();
    windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.format = PixelFormat.TRANSLUCENT;
    windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
    if (Build.VERSION.SDK_INT >= 21) {
        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
    } else {
        windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    }

    if (progressDrawables == null) {
        progressDrawables = new Drawable[4];
        progressDrawables[0] = parentActivity.getResources().getDrawable(R.drawable.circle_big);
        progressDrawables[1] = parentActivity.getResources().getDrawable(R.drawable.cancel_big);
        progressDrawables[2] = parentActivity.getResources().getDrawable(R.drawable.load_big);
        progressDrawables[3] = parentActivity.getResources().getDrawable(R.drawable.play_big);
    }

    scroller = new Scroller(activity);

    blackPaint.setColor(0xff000000);

    actionBar = new ActionBar(activity);
    actionBar.setBackgroundColor(Theme.ACTION_BAR_PHOTO_VIEWER_COLOR);
    actionBar.setOccupyStatusBar(false);
    actionBar.setTitleColor(0xffffffff);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, false);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
    photoContainerView.addView(actionBar,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                closePhoto(true);
            } else if (id == gallery_menu_save) {
                if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    parentActivity
                            .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
                    return;
                }
                File f = getMediaFile(currentIndex);
                if (f != null && f.exists()) {
                    MediaController.saveFile(f.toString(), parentActivity, isMediaVideo(currentIndex) ? 1 : 0,
                            null, null);
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
                    showDialog(builder.create());
                }
            } else if (id == gallery_menu_share) {
                onSharePressed();
            } else if (id == gallery_menu_openin) {
                try {
                    AndroidUtilities.openForView(getMedia(currentIndex), parentActivity);
                    closePhoto(false);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        }

        @Override
        public boolean canOpenMenu() {
            File f = getMediaFile(currentIndex);
            return f != null && f.exists();
        }
    });

    ActionBarMenu menu = actionBar.createMenu();

    menu.addItem(gallery_menu_share, R.drawable.share);
    menuItem = menu.addItem(0, R.drawable.ic_ab_other);
    menuItem.setLayoutInScreen(true);
    menuItem.addSubItem(gallery_menu_openin,
            LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
    //menuItem.addSubItem(gallery_menu_share, LocaleController.getString("ShareFile", R.string.ShareFile), 0);
    menuItem.addSubItem(gallery_menu_save, LocaleController.getString("SaveToGallery", R.string.SaveToGallery));

    bottomLayout = new FrameLayout(parentActivity);
    bottomLayout.setBackgroundColor(0x7f000000);
    photoContainerView.addView(bottomLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));

    captionTextViewOld = new TextView(activity);
    captionTextViewOld.setMaxLines(10);
    captionTextViewOld.setBackgroundColor(0x7f000000);
    captionTextViewOld.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20),
            AndroidUtilities.dp(8));
    captionTextViewOld.setLinkTextColor(0xffffffff);
    captionTextViewOld.setTextColor(0xffffffff);
    captionTextViewOld.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    captionTextViewOld.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    captionTextViewOld.setVisibility(View.INVISIBLE);
    photoContainerView.addView(captionTextViewOld, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT));

    captionTextView = captionTextViewNew = new TextView(activity);
    captionTextViewNew.setMaxLines(10);
    captionTextViewNew.setBackgroundColor(0x7f000000);
    captionTextViewNew.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20),
            AndroidUtilities.dp(8));
    captionTextViewNew.setLinkTextColor(0xffffffff);
    captionTextViewNew.setTextColor(0xffffffff);
    captionTextViewNew.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    captionTextViewNew.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    captionTextViewNew.setVisibility(View.INVISIBLE);
    photoContainerView.addView(captionTextViewNew, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT));

    radialProgressViews[0] = new RadialProgressView(activity, photoContainerView);
    radialProgressViews[0].setBackgroundState(0, false);
    radialProgressViews[1] = new RadialProgressView(activity, photoContainerView);
    radialProgressViews[1].setBackgroundState(0, false);
    radialProgressViews[2] = new RadialProgressView(activity, photoContainerView);
    radialProgressViews[2].setBackgroundState(0, false);

    videoPlayerSeekbar = new SeekBar(activity);
    videoPlayerSeekbar.setColors(0x66ffffff, 0xffffffff, 0xffffffff);
    videoPlayerSeekbar.setDelegate(new SeekBar.SeekBarDelegate() {
        @Override
        public void onSeekBarDrag(float progress) {
            if (videoPlayer != null) {
                videoPlayer.seekTo((int) (progress * videoPlayer.getDuration()));
            }
        }
    });

    videoPlayerControlFrameLayout = new FrameLayout(activity) {
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            int x = (int) event.getX();
            int y = (int) event.getY();
            if (videoPlayerSeekbar.onTouch(event.getAction(), event.getX() - AndroidUtilities.dp(48),
                    event.getY())) {
                getParent().requestDisallowInterceptTouchEvent(true);
                invalidate();
                return true;
            }
            return super.onTouchEvent(event);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            long duration;
            if (videoPlayer != null) {
                duration = videoPlayer.getDuration();
                if (duration == C.TIME_UNSET) {
                    duration = 0;
                }
            } else {
                duration = 0;
            }
            duration /= 1000;
            int size = (int) Math
                    .ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d",
                            duration / 60, duration % 60, duration / 60, duration % 60)));
            videoPlayerSeekbar.setSize(getMeasuredWidth() - AndroidUtilities.dp(48 + 16) - size,
                    getMeasuredHeight());
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            float progress = 0;
            if (videoPlayer != null) {
                progress = videoPlayer.getCurrentPosition() / (float) videoPlayer.getDuration();
            }
            videoPlayerSeekbar.setProgress(progress);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.save();
            canvas.translate(AndroidUtilities.dp(48), 0);
            videoPlayerSeekbar.draw(canvas);
            canvas.restore();
        }
    };
    videoPlayerControlFrameLayout.setWillNotDraw(false);
    bottomLayout.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    videoPlayButton = new ImageView(activity);
    videoPlayButton.setScaleType(ImageView.ScaleType.CENTER);
    videoPlayerControlFrameLayout.addView(videoPlayButton,
            LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
    videoPlayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (videoPlayer != null) {
                if (isPlaying) {
                    videoPlayer.pause();
                } else {
                    videoPlayer.play();
                }
            }
        }
    });

    videoPlayerTime = new TextView(activity);
    videoPlayerTime.setTextColor(0xffffffff);
    videoPlayerTime.setGravity(Gravity.CENTER_VERTICAL);
    videoPlayerTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    videoPlayerControlFrameLayout.addView(videoPlayerTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 8, 0));

    gestureDetector = new GestureDetector(activity, this);
    gestureDetector.setOnDoubleTapListener(this);

    ImageReceiver.ImageReceiverDelegate imageReceiverDelegate = new ImageReceiver.ImageReceiverDelegate() {
        @Override
        public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
            if (imageReceiver == centerImage && set && scaleToFill()) {
                if (!wasLayout) {
                    dontResetZoomOnFirstLayout = true;
                } else {
                    setScaleToFill();
                }
            }
        }
    };

    centerImage.setParentView(photoContainerView);
    centerImage.setCrossfadeAlpha((byte) 2);
    centerImage.setInvalidateAll(true);
    centerImage.setDelegate(imageReceiverDelegate);
    leftImage.setParentView(photoContainerView);
    leftImage.setCrossfadeAlpha((byte) 2);
    leftImage.setInvalidateAll(true);
    leftImage.setDelegate(imageReceiverDelegate);
    rightImage.setParentView(photoContainerView);
    rightImage.setCrossfadeAlpha((byte) 2);
    rightImage.setInvalidateAll(true);
    rightImage.setDelegate(imageReceiverDelegate);
}

From source file:net.bluehack.ui.PhotoViewer.java

@SuppressLint("NewApi")
private void preparePlayer(File file, boolean playWhenReady) {
    if (parentActivity == null) {
        return;//from   w  w w  .  j  av  a 2 s  .  c o  m
    }
    releasePlayer();
    if (videoTextureView == null) {
        aspectRatioFrameLayout = new AspectRatioFrameLayout(parentActivity);
        aspectRatioFrameLayout.setVisibility(View.INVISIBLE);
        containerView.addView(aspectRatioFrameLayout, 0,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));

        videoTextureView = new TextureView(parentActivity);
        videoTextureView.setOpaque(false);
        videoTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
            @Override
            public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
                if (videoPlayer != null) {
                    videoPlayer.setSurface(new Surface(videoTextureView.getSurfaceTexture()));
                }
            }

            @Override
            public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {

            }

            @Override
            public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
                if (videoPlayer != null) {
                    videoPlayer.blockingClearSurface();
                }
                return true;
            }

            @Override
            public void onSurfaceTextureUpdated(SurfaceTexture surface) {
                if (!textureUploaded) {
                    textureUploaded = true;
                    containerView.invalidate();
                }
            }
        });
        aspectRatioFrameLayout.addView(videoTextureView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
    }
    textureUploaded = false;
    videoCrossfadeStarted = false;
    videoTextureView.setAlpha(videoCrossfadeAlpha = 0.0f);
    videoPlayButton.setImageResource(R.drawable.inline_video_play);
    if (videoPlayer == null) {
        videoPlayer = new VideoPlayer(new VideoPlayer.ExtractorRendererBuilder(parentActivity,
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
                Uri.fromFile(file)));
        videoPlayer.addListener(new VideoPlayer.Listener() {
            @Override
            public void onStateChanged(boolean playWhenReady, int playbackState) {
                if (videoPlayer == null) {
                    return;
                }
                if (playbackState != VideoPlayer.STATE_ENDED && playbackState != VideoPlayer.STATE_IDLE) {
                    try {
                        parentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else {
                    try {
                        parentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                if (playbackState == VideoPlayer.STATE_READY
                        && aspectRatioFrameLayout.getVisibility() != View.VISIBLE) {
                    aspectRatioFrameLayout.setVisibility(View.VISIBLE);
                }
                if (videoPlayer.getPlayerControl().isPlaying() && playbackState != VideoPlayer.STATE_ENDED) {
                    if (!isPlaying) {
                        isPlaying = true;
                        videoPlayButton.setImageResource(R.drawable.inline_video_pause);
                        AndroidUtilities.runOnUIThread(updateProgressRunnable);
                    }
                } else if (isPlaying) {
                    isPlaying = false;
                    videoPlayButton.setImageResource(R.drawable.inline_video_play);
                    AndroidUtilities.cancelRunOnUIThread(updateProgressRunnable);
                    if (playbackState == VideoPlayer.STATE_ENDED) {
                        if (!videoPlayerSeekbar.isDragging()) {
                            videoPlayerSeekbar.setProgress(0.0f);
                            videoPlayerControlFrameLayout.invalidate();
                            videoPlayer.seekTo(0);
                            videoPlayer.getPlayerControl().pause();
                        }
                    }
                }
                updateVideoPlayerTime();
            }

            @Override
            public void onError(Exception e) {
                FileLog.e("tmessages", e);
            }

            @Override
            public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
                    float pixelWidthHeightRatio) {
                if (aspectRatioFrameLayout != null) {
                    if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    aspectRatioFrameLayout.setAspectRatio(
                            height == 0 ? 1 : (width * pixelWidthHeightRatio) / height,
                            unappliedRotationDegrees);
                }
            }
        });
        long duration;
        if (videoPlayer != null) {
            duration = videoPlayer.getDuration();
            if (duration == ExoPlayer.UNKNOWN_TIME) {
                duration = 0;
            }
        } else {
            duration = 0;
        }
        duration /= 1000;
        int size = (int) Math.ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d",
                duration / 60, duration % 60, duration / 60, duration % 60)));

        playerNeedsPrepare = true;
    }
    if (playerNeedsPrepare) {
        videoPlayer.prepare();
        playerNeedsPrepare = false;
    }
    if (videoPlayerControlFrameLayout != null) {
        if (currentBotInlineResult != null && (currentBotInlineResult.type.equals("video")
                || MessageObject.isVideoDocument(currentBotInlineResult.document))) {
            bottomLayout.setVisibility(View.VISIBLE);
            bottomLayout.setTranslationY(-AndroidUtilities.dp(48));
        }
        videoPlayerControlFrameLayout.setVisibility(View.VISIBLE);
        dateTextView.setVisibility(View.GONE);
        nameTextView.setVisibility(View.GONE);
        if (allowShare) {
            shareButton.setVisibility(View.GONE);
            menuItem.showSubItem(gallery_menu_share);
        }
    }
    if (videoTextureView.getSurfaceTexture() != null) {
        videoPlayer.setSurface(new Surface(videoTextureView.getSurfaceTexture()));
    }
    videoPlayer.setPlayWhenReady(playWhenReady);
}

From source file:kr.wdream.ui.PhotoViewer.java

@SuppressLint("NewApi")
private void preparePlayer(File file, boolean playWhenReady) {
    if (parentActivity == null) {
        return;/*from   w w  w . j  a v  a  2s  .  c  om*/
    }
    releasePlayer();
    if (videoTextureView == null) {
        aspectRatioFrameLayout = new AspectRatioFrameLayout(parentActivity);
        aspectRatioFrameLayout.setVisibility(View.INVISIBLE);
        containerView.addView(aspectRatioFrameLayout, 0,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));

        videoTextureView = new TextureView(parentActivity);
        videoTextureView.setOpaque(false);
        videoTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
            @Override
            public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
                if (videoPlayer != null) {
                    videoPlayer.setSurface(new Surface(videoTextureView.getSurfaceTexture()));
                }
            }

            @Override
            public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {

            }

            @Override
            public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
                if (videoPlayer != null) {
                    videoPlayer.blockingClearSurface();
                }
                return true;
            }

            @Override
            public void onSurfaceTextureUpdated(SurfaceTexture surface) {
                if (!textureUploaded) {
                    textureUploaded = true;
                    containerView.invalidate();
                }
            }
        });
        aspectRatioFrameLayout.addView(videoTextureView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
    }
    textureUploaded = false;
    videoCrossfadeStarted = false;
    videoTextureView.setAlpha(videoCrossfadeAlpha = 0.0f);
    videoPlayButton.setImageResource(kr.wdream.storyshop.R.drawable.inline_video_play);
    if (videoPlayer == null) {
        videoPlayer = new VideoPlayer(new VideoPlayer.ExtractorRendererBuilder(parentActivity,
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
                Uri.fromFile(file)));
        videoPlayer.addListener(new VideoPlayer.Listener() {
            @Override
            public void onStateChanged(boolean playWhenReady, int playbackState) {
                if (videoPlayer == null) {
                    return;
                }
                if (playbackState != VideoPlayer.STATE_ENDED && playbackState != VideoPlayer.STATE_IDLE) {
                    try {
                        parentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                } else {
                    try {
                        parentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                if (playbackState == VideoPlayer.STATE_READY
                        && aspectRatioFrameLayout.getVisibility() != View.VISIBLE) {
                    aspectRatioFrameLayout.setVisibility(View.VISIBLE);
                }
                if (videoPlayer.getPlayerControl().isPlaying() && playbackState != VideoPlayer.STATE_ENDED) {
                    if (!isPlaying) {
                        isPlaying = true;
                        videoPlayButton.setImageResource(kr.wdream.storyshop.R.drawable.inline_video_pause);
                        AndroidUtilities.runOnUIThread(updateProgressRunnable);
                    }
                } else if (isPlaying) {
                    isPlaying = false;
                    videoPlayButton.setImageResource(kr.wdream.storyshop.R.drawable.inline_video_play);
                    AndroidUtilities.cancelRunOnUIThread(updateProgressRunnable);
                    if (playbackState == VideoPlayer.STATE_ENDED) {
                        if (!videoPlayerSeekbar.isDragging()) {
                            videoPlayerSeekbar.setProgress(0.0f);
                            videoPlayerControlFrameLayout.invalidate();
                            videoPlayer.seekTo(0);
                            videoPlayer.getPlayerControl().pause();
                        }
                    }
                }
                updateVideoPlayerTime();
            }

            @Override
            public void onError(Exception e) {
                FileLog.e("tmessages", e);
            }

            @Override
            public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
                    float pixelWidthHeightRatio) {
                if (aspectRatioFrameLayout != null) {
                    if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    aspectRatioFrameLayout.setAspectRatio(
                            height == 0 ? 1 : (width * pixelWidthHeightRatio) / height,
                            unappliedRotationDegrees);
                }
            }
        });
        long duration;
        if (videoPlayer != null) {
            duration = videoPlayer.getDuration();
            if (duration == ExoPlayer.UNKNOWN_TIME) {
                duration = 0;
            }
        } else {
            duration = 0;
        }
        duration /= 1000;
        int size = (int) Math.ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d",
                duration / 60, duration % 60, duration / 60, duration % 60)));

        playerNeedsPrepare = true;
    }
    if (playerNeedsPrepare) {
        videoPlayer.prepare();
        playerNeedsPrepare = false;
    }
    if (videoPlayerControlFrameLayout != null) {
        if (currentBotInlineResult != null && (currentBotInlineResult.type.equals("video")
                || MessageObject.isVideoDocument(currentBotInlineResult.document))) {
            bottomLayout.setVisibility(View.VISIBLE);
            bottomLayout.setTranslationY(-AndroidUtilities.dp(48));
        }
        videoPlayerControlFrameLayout.setVisibility(View.VISIBLE);
        dateTextView.setVisibility(View.GONE);
        nameTextView.setVisibility(View.GONE);
        if (allowShare) {
            shareButton.setVisibility(View.GONE);
            menuItem.showSubItem(gallery_menu_share);
        }
    }
    if (videoTextureView.getSurfaceTexture() != null) {
        videoPlayer.setSurface(new Surface(videoTextureView.getSurfaceTexture()));
    }
    videoPlayer.setPlayWhenReady(playWhenReady);
}

From source file:org.telegram.ui.ArticleViewer.java

@SuppressLint("NewApi")
private void preparePlayer(File file, boolean playWhenReady) {
    if (parentActivity == null) {
        return;/*  w  w w. j av  a2 s  . com*/
    }
    releasePlayer();
    if (videoTextureView == null) {
        aspectRatioFrameLayout = new AspectRatioFrameLayout(parentActivity);
        aspectRatioFrameLayout.setVisibility(View.INVISIBLE);
        photoContainerView.addView(aspectRatioFrameLayout, 0,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));

        videoTextureView = new TextureView(parentActivity);
        videoTextureView.setOpaque(false);
        aspectRatioFrameLayout.addView(videoTextureView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
    }
    textureUploaded = false;
    videoCrossfadeStarted = false;
    videoTextureView.setAlpha(videoCrossfadeAlpha = 0.0f);
    videoPlayButton.setImageResource(R.drawable.inline_video_play);
    if (videoPlayer == null) {
        videoPlayer = new VideoPlayer();
        videoPlayer.setTextureView(videoTextureView);
        videoPlayer.setDelegate(new VideoPlayer.VideoPlayerDelegate() {
            @Override
            public void onStateChanged(boolean playWhenReady, int playbackState) {
                if (videoPlayer == null) {
                    return;
                }
                if (playbackState != ExoPlayer.STATE_ENDED && playbackState != ExoPlayer.STATE_IDLE) {
                    try {
                        parentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                } else {
                    try {
                        parentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                }
                if (playbackState == ExoPlayer.STATE_READY
                        && aspectRatioFrameLayout.getVisibility() != View.VISIBLE) {
                    aspectRatioFrameLayout.setVisibility(View.VISIBLE);
                }
                if (videoPlayer.isPlaying() && playbackState != ExoPlayer.STATE_ENDED) {
                    if (!isPlaying) {
                        isPlaying = true;
                        videoPlayButton.setImageResource(R.drawable.inline_video_pause);
                        AndroidUtilities.runOnUIThread(updateProgressRunnable);
                    }
                } else if (isPlaying) {
                    isPlaying = false;
                    videoPlayButton.setImageResource(R.drawable.inline_video_play);
                    AndroidUtilities.cancelRunOnUIThread(updateProgressRunnable);
                    if (playbackState == ExoPlayer.STATE_ENDED) {
                        if (!videoPlayerSeekbar.isDragging()) {
                            videoPlayerSeekbar.setProgress(0.0f);
                            videoPlayerControlFrameLayout.invalidate();
                            videoPlayer.seekTo(0);
                            videoPlayer.pause();
                        }
                    }
                }
                updateVideoPlayerTime();
            }

            @Override
            public void onError(Exception e) {
                FileLog.e(e);
            }

            @Override
            public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
                    float pixelWidthHeightRatio) {
                if (aspectRatioFrameLayout != null) {
                    if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    aspectRatioFrameLayout.setAspectRatio(
                            height == 0 ? 1 : (width * pixelWidthHeightRatio) / height,
                            unappliedRotationDegrees);
                }
            }

            @Override
            public void onRenderedFirstFrame() {
                if (!textureUploaded) {
                    textureUploaded = true;
                    containerView.invalidate();
                }
            }

            @Override
            public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
                return false;
            }

            @Override
            public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {

            }
        });
        long duration;
        if (videoPlayer != null) {
            duration = videoPlayer.getDuration();
            if (duration == C.TIME_UNSET) {
                duration = 0;
            }
        } else {
            duration = 0;
        }
        duration /= 1000;
        int size = (int) Math.ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d",
                duration / 60, duration % 60, duration / 60, duration % 60)));
    }
    videoPlayer.preparePlayer(Uri.fromFile(file), "other");
    bottomLayout.setVisibility(View.VISIBLE);
    videoPlayer.setPlayWhenReady(playWhenReady);
}