// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/utils/ExoPlayerEventListenerImpl.java
// public class ExoPlayerEventListenerImpl implements Player.EventListener {
//     @Override
//     public void onTimelineChanged(Timeline timeline, Object manifest) {
// 
//     }
// 
//     @Override
//     public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
// 
//     }
// 
//     @Override
//     public void onLoadingChanged(boolean isLoading) {
// 
//     }
// 
//     @Override
//     public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
// 
//     }
// 
//     @Override
//     public void onRepeatModeChanged(int repeatMode) {
// 
//     }
// 
//     @Override
//     public void onPlayerError(ExoPlaybackException error) {
// 
//     }
// 
//     @Override
//     public void onPositionDiscontinuity() {
// 
//     }
// 
//     @Override
//     public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
// 
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/utils/SimpleExoPlayerInitializer.java
// public class SimpleExoPlayerInitializer {
// 
//     public static SimpleExoPlayer initializeExoPlayer(Context context) {
//         return ExoPlayerFactory.newSimpleInstance(
//                 new DefaultRenderersFactory(context),
//                 new DefaultTrackSelector(), new DefaultLoadControl());
//     }
// 
//     public static MediaSource buildMediaSource(Uri uri, Context context) {
//         String userAgent = Util.getUserAgent(context, context.getResources().getString(R.string.app_name));
//         return new ExtractorMediaSource(uri,
//                 new DefaultHttpDataSourceFactory(userAgent),
//                 new DefaultExtractorsFactory(), null, null);
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/utils/VideoRendererEventListenerImpl.java
// public class VideoRendererEventListenerImpl implements VideoRendererEventListener {
//     @Override
//     public void onVideoEnabled(DecoderCounters counters) {
// 
//     }
// 
//     @Override
//     public void onVideoDecoderInitialized(String decoderName, long initializedTimestampMs, long initializationDurationMs) {
// 
//     }
// 
//     @Override
//     public void onVideoInputFormatChanged(Format format) {
// 
//     }
// 
//     @Override
//     public void onDroppedFrames(int count, long elapsedMs) {
// 
//     }
// 
//     @Override
//     public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
// 
//     }
// 
//     @Override
//     public void onRenderedFirstFrame(Surface surface) {
// 
//     }
// 
//     @Override
//     public void onVideoDisabled(DecoderCounters counters) {
// 
//     }
// }


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.view.TextureView;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.util.Util;
import com.quickblox.ui.kit.chatmessage.adapter.R;
import com.quickblox.ui.kit.chatmessage.adapter.media.utils.ExoPlayerEventListenerImpl;
import com.quickblox.ui.kit.chatmessage.adapter.media.utils.SimpleExoPlayerInitializer;
import com.quickblox.ui.kit.chatmessage.adapter.media.utils.VideoRendererEventListenerImpl;
    private void releasePlayer() {
        if (player != null) {
            shouldAutoPlay = player.getPlayWhenReady();
            updateResumePosition();
            player.release();
            player = null;
        }
    }

    private void updateResumePosition() {
        resumeWindow = player.getCurrentWindowIndex();
        resumePosition = player.isCurrentWindowSeekable() ? Math.max(0, player.getCurrentPosition())
                : C.TIME_UNSET;
    }

    private void setPlayerToStartPosition() {
        player.seekTo(0);
        player.setPlayWhenReady(false);
    }

    private class PlayerStateListener extends ExoPlayerEventListenerImpl {

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            if (playbackState == Player.STATE_ENDED) {
                setPlayerToStartPosition();
            }
        }
    }

// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/utils/ExoPlayerEventListenerImpl.java
// public class ExoPlayerEventListenerImpl implements Player.EventListener {
//     @Override
//     public void onTimelineChanged(Timeline timeline, Object manifest) {
// 
//     }
// 
//     @Override
//     public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
// 
//     }
// 
//     @Override
//     public void onLoadingChanged(boolean isLoading) {
// 
//     }
// 
//     @Override
//     public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
// 
//     }
// 
//     @Override
//     public void onRepeatModeChanged(int repeatMode) {
// 
//     }
// 
//     @Override
//     public void onPlayerError(ExoPlaybackException error) {
// 
//     }
// 
//     @Override
//     public void onPositionDiscontinuity() {
// 
//     }
// 
//     @Override
//     public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
// 
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/utils/SimpleExoPlayerInitializer.java
// public class SimpleExoPlayerInitializer {
// 
//     public static SimpleExoPlayer initializeExoPlayer(Context context) {
//         return ExoPlayerFactory.newSimpleInstance(
//                 new DefaultRenderersFactory(context),
//                 new DefaultTrackSelector(), new DefaultLoadControl());
//     }
// 
//     public static MediaSource buildMediaSource(Uri uri, Context context) {
//         String userAgent = Util.getUserAgent(context, context.getResources().getString(R.string.app_name));
//         return new ExtractorMediaSource(uri,
//                 new DefaultHttpDataSourceFactory(userAgent),
//                 new DefaultExtractorsFactory(), null, null);
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/utils/VideoRendererEventListenerImpl.java
// public class VideoRendererEventListenerImpl implements VideoRendererEventListener {
//     @Override
//     public void onVideoEnabled(DecoderCounters counters) {
// 
//     }
// 
//     @Override
//     public void onVideoDecoderInitialized(String decoderName, long initializedTimestampMs, long initializationDurationMs) {
// 
//     }
// 
//     @Override
//     public void onVideoInputFormatChanged(Format format) {
// 
//     }
// 
//     @Override
//     public void onDroppedFrames(int count, long elapsedMs) {
// 
//     }
// 
//     @Override
//     public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
// 
//     }
// 
//     @Override
//     public void onRenderedFirstFrame(Surface surface) {
// 
//     }
// 
//     @Override
//     public void onVideoDisabled(DecoderCounters counters) {
// 
//     }
// }


// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/video/ui/VideoPlayerActivity.java
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.view.TextureView;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.util.Util;
import com.quickblox.ui.kit.chatmessage.adapter.R;
import com.quickblox.ui.kit.chatmessage.adapter.media.utils.ExoPlayerEventListenerImpl;
import com.quickblox.ui.kit.chatmessage.adapter.media.utils.SimpleExoPlayerInitializer;
import com.quickblox.ui.kit.chatmessage.adapter.media.utils.VideoRendererEventListenerImpl;

    private void releasePlayer() {
        if (player != null) {
            shouldAutoPlay = player.getPlayWhenReady();
            updateResumePosition();
            player.release();
            player = null;
        }
    }

    private void updateResumePosition() {
        resumeWindow = player.getCurrentWindowIndex();
        resumePosition = player.isCurrentWindowSeekable() ? Math.max(0, player.getCurrentPosition())
                : C.TIME_UNSET;
    }

    private void setPlayerToStartPosition() {
        player.seekTo(0);
        player.setPlayWhenReady(false);
    }

    private class PlayerStateListener extends ExoPlayerEventListenerImpl {

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            if (playbackState == Player.STATE_ENDED) {
                setPlayerToStartPosition();
            }
        }
    }

    private class VideoListener extends VideoRendererEventListenerImpl {