Beispiel #1
0
  private void startWebmConversion(Binder binder, MediaUri url) {
    logger.info("Start converting gif to webm");

    // normalize to http://
    String gifUrl = url.toString().replace("https://", "http://");

    // and start conversion!
    conversion =
        gifToVideoService
            .toVideo(gifUrl)
            .compose(binder.get())
            .subscribe(
                result -> {
                  checkMainThread();

                  // create the correct child-viewer
                  MediaView mediaView;
                  if (result.getVideoUrl().isPresent()) {
                    logger.info("Converted successfully, replace with video player");
                    MediaUri webm =
                        url.withUri(
                            Uri.parse(result.getVideoUrl().get()), MediaUri.MediaType.VIDEO);
                    mediaView =
                        MediaViews.newInstance(getContext(), binder, webm, this::onMediaShown);

                  } else {
                    logger.info("Conversion did not work, showing gif");
                    mediaView = new GifMediaView(getContext(), binder, url, this::onMediaShown);
                  }

                  mediaView.removePreviewImage();
                  setChild(mediaView);
                },
                defaultOnError());
  }
Beispiel #2
0
  private void initializeMediaView() {
    int padding = AndroidUtility.getActionBarContentOffset(getActivity());

    // initialize a new viewer fragment
    MediaUri uri = MediaUri.of(feedItem.getId(), UriHelper.of(getContext()).media(feedItem));
    if (!uri.isLocal() && AndroidUtility.isOnMobile(getActivity())) {
      Settings.ConfirmOnMobile confirmOnMobile = settings.confirmPlayOnMobile(getContext());
      if (confirmOnMobile == Settings.ConfirmOnMobile.ALL) {
        uri = uri.withDelay(true);

      } else if (confirmOnMobile == Settings.ConfirmOnMobile.VIDEO
          && uri.getMediaType() != MediaUri.MediaType.IMAGE) {

        uri = uri.withDelay(true);
      }
    }

    viewer =
        MediaViews.newInstance(
            getActivity(),
            uri,
            () -> {
              //  mark this item seen. We do that in a background thread
              seenService.markAsSeen(feedItem);
            });

    // inform viewer over fragment lifecycle events!
    MediaViews.adaptFragmentLifecycle(lifecycle(), viewer);

    registerTapListener(viewer);

    PreviewInfo previewInfo =
        this.previewInfo != null ? this.previewInfo : getPreviewInfoFromCache();

    if (previewInfo != null) {
      viewer.setPreviewImage(previewInfo, "TransitionTarget-" + feedItem.getId());
      if (Sdk.isAtLeastLollipop()) {
        viewer.postDelayed(this::onTransitionEnds, 350);
      } else {
        viewer.post(this::onTransitionEnds);
      }
    } else {
      viewer.post(this::onTransitionEnds);
    }

    // add views in the correct order
    int idx = playerContainer.indexOfChild(voteAnimationIndicator);
    playerContainer.addView(viewer, idx);

    if (tabletLayout) {
      viewer.setLayoutParams(
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT,
              ViewGroup.LayoutParams.MATCH_PARENT,
              Gravity.CENTER));
    } else {
      viewer.setPadding(0, padding, 0, 0);

      // we add a placeholder to the first element of the recycler view.
      // this placeholder will mirror the size of the viewer.
      PlaceholderView placeholder = new PlaceholderView();
      adapter.addAdapter(SingleViewAdapter.ofView(placeholder));

      RxView.layoutChanges(viewer)
          .subscribe(
              event -> {
                int newHeight = viewer.getMeasuredHeight();
                if (newHeight != placeholder.fixedHeight) {
                  placeholder.fixedHeight = newHeight;

                  if (Sdk.isAtLeastKitKat()) {
                    placeholder.requestLayout();
                  } else {
                    // it looks like a requestLayout is not honored on pre kitkat devices
                    // if already in a layout pass.
                    placeholder.post(placeholder::requestLayout);
                  }

                  if (isVideoFullScreen()) {
                    realignFullScreen();
                  }
                }
              });

      RxView.layoutChanges(placeholder)
          .subscribe(
              event -> {
                // simulate scroll after layouting the placeholder to
                // reflect changes to the viewers clipping.
                simulateScroll();
              });
    }
  }