Search in sources :

Example 6 with VideoSlide

use of org.thoughtcrime.securesms.mms.VideoSlide in project Signal-Android by WhisperSystems.

the class VideoEditorFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    player = view.findViewById(R.id.video_player);
    uri = requireArguments().getParcelable(KEY_URI);
    isVideoGif = requireArguments().getBoolean(KEY_IS_VIDEO_GIF);
    long maxOutput = requireArguments().getLong(KEY_MAX_OUTPUT);
    long maxSend = requireArguments().getLong(KEY_MAX_SEND);
    VideoSlide slide = new VideoSlide(requireContext(), uri, 0, isVideoGif);
    boolean autoplay = isVideoGif;
    player.setWindow(requireActivity().getWindow());
    player.setVideoSource(slide, autoplay);
    if (slide.isVideoGif()) {
        player.setPlayerCallback(new VideoPlayer.PlayerCallback() {

            @Override
            public void onPlaying() {
                controller.onPlayerReady();
            }

            @Override
            public void onStopped() {
            // Do nothing.
            }

            @Override
            public void onError() {
                controller.onPlayerError();
            }
        });
        player.hideControls();
        player.loopForever();
    } else if (MediaConstraints.isVideoTranscodeAvailable()) {
        hud = view.findViewById(R.id.video_editor_hud);
        hud.setEventListener(this);
        updateHud(data);
        if (data.durationEdited) {
            player.clip(data.startTimeUs, data.endTimeUs, autoplay);
        }
        try {
            hud.setVideoSource(slide, new VideoBitRateCalculator(maxOutput), maxSend);
            hud.setVisibility(View.VISIBLE);
            startPositionUpdates();
        } catch (IOException e) {
            Log.w(TAG, e);
        }
        player.setOnClickListener(v -> {
            player.pause();
            hud.showPlayButton();
        });
        player.setPlayerCallback(new VideoPlayer.PlayerCallback() {

            @Override
            public void onReady() {
                controller.onPlayerReady();
            }

            @Override
            public void onPlaying() {
                hud.fadePlayButton();
            }

            @Override
            public void onStopped() {
                hud.showPlayButton();
            }

            @Override
            public void onError() {
                controller.onPlayerError();
            }
        });
    }
}
Also used : VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) VideoPlayer(org.thoughtcrime.securesms.video.VideoPlayer) VideoBitRateCalculator(org.thoughtcrime.securesms.video.VideoBitRateCalculator) RequiresApi(androidx.annotation.RequiresApi) VideoPlayer(org.thoughtcrime.securesms.video.VideoPlayer) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) VideoBitRateCalculator(org.thoughtcrime.securesms.video.VideoBitRateCalculator) Uri(android.net.Uri) IOException(java.io.IOException) VideoEditorHud(org.thoughtcrime.securesms.scribbles.VideoEditorHud) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) Log(org.signal.core.util.logging.Log) Throttler(org.thoughtcrime.securesms.util.Throttler) Nullable(androidx.annotation.Nullable) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) Handler(android.os.Handler) Looper(android.os.Looper) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Build(android.os.Build) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) IOException(java.io.IOException)

Aggregations

VideoSlide (org.thoughtcrime.securesms.mms.VideoSlide)6 Uri (android.net.Uri)4 View (android.view.View)4 Bundle (android.os.Bundle)3 SuppressLint (android.annotation.SuppressLint)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Context (android.content.Context)2 Intent (android.content.Intent)2 Color (android.graphics.Color)2 PorterDuff (android.graphics.PorterDuff)2 Build (android.os.Build)2 Spannable (android.text.Spannable)2 SpannableString (android.text.SpannableString)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 LayoutInflater (android.view.LayoutInflater)2 MotionEvent (android.view.MotionEvent)2 ViewGroup (android.view.ViewGroup)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 IOException (java.io.IOException)2