Search in sources :

Example 1 with BufferEventTask

use of com.odysee.app.tasks.BufferEventTask in project odysee-android by OdyseeTeam.

the class FileViewFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_file_view, container, false);
    layoutLoadingState = root.findViewById(R.id.file_view_loading_state);
    layoutNothingAtLocation = root.findViewById(R.id.container_nothing_at_location);
    layoutResolving = root.findViewById(R.id.file_view_loading_container);
    layoutDisplayArea = root.findViewById(R.id.file_view_claim_display_area);
    buttonPublishSomething = root.findViewById(R.id.nothing_at_location_publish_button);
    tipButton = root.findViewById(R.id.file_view_action_tip);
    expandButton = root.findViewById(R.id.expand_commentarea_button);
    singleCommentRoot = root.findViewById(R.id.collapsed_comment);
    relatedContentTitle = root.findViewById(R.id.related_or_playlist);
    containerCommentForm = root.findViewById(R.id.container_comment_form);
    containerReplyToComment = root.findViewById(R.id.comment_form_reply_to_container);
    textReplyingTo = root.findViewById(R.id.comment_form_replying_to_text);
    textReplyToBody = root.findViewById(R.id.comment_form_reply_to_body);
    buttonClearReplyToComment = root.findViewById(R.id.comment_form_clear_reply_to);
    commentChannelSpinner = root.findViewById(R.id.comment_form_channel_spinner);
    progressLoadingChannels = root.findViewById(R.id.comment_form_channels_loading);
    progressPostComment = root.findViewById(R.id.comment_form_post_progress);
    inputComment = root.findViewById(R.id.comment_form_body);
    textCommentLimit = root.findViewById(R.id.comment_form_text_limit);
    buttonPostComment = root.findViewById(R.id.comment_form_post);
    buttonCreateChannel = root.findViewById(R.id.create_channel_button);
    commentPostAsThumbnail = root.findViewById(R.id.comment_form_thumbnail);
    commentPostAsNoThumbnail = root.findViewById(R.id.comment_form_no_thumbnail);
    commentPostAsAlpha = root.findViewById(R.id.comment_form_thumbnail_alpha);
    buttonCommentSignedInUserRequired = root.findViewById(R.id.sign_in_user_button);
    textNothingAtLocation = root.findViewById(R.id.nothing_at_location_text);
    commentLoadingArea = root.findViewById(R.id.file_comments_loading);
    likeReactionAmount = root.findViewById(R.id.likes_amount);
    dislikeReactionAmount = root.findViewById(R.id.dislikes_amount);
    likeReactionIcon = root.findViewById(R.id.like_icon);
    dislikeReactionIcon = root.findViewById(R.id.dislike_icon);
    initUi(root);
    fileViewPlayerListener = new Player.Listener() {

        @Override
        public void onPlaybackStateChanged(@Player.State int playbackState) {
            if (playbackState == Player.STATE_READY) {
                elapsedDuration = MainActivity.appPlayer.getCurrentPosition();
                totalDuration = MainActivity.appPlayer.getDuration() < 0 ? 0 : MainActivity.appPlayer.getDuration();
                if (!playbackStarted) {
                    logPlay(currentUrl, startTimeMillis);
                    playbackStarted = true;
                    long lastPosition = loadLastPlaybackPosition();
                    if (lastPosition > -1) {
                        MainActivity.appPlayer.seekTo(lastPosition);
                    }
                }
                renderTotalDuration();
                scheduleElapsedPlayback();
                hideBuffering();
                if (loadingNewClaim) {
                    setPlaybackSpeedToDefault();
                    setPlayerQualityToDefault();
                    MainActivity.appPlayer.setPlayWhenReady(true);
                    loadingNewClaim = false;
                }
            } else if (playbackState == Player.STATE_BUFFERING) {
                if (!loadingQualityChanged) {
                    Context ctx = getContext();
                    boolean sendBufferingEvents = true;
                    if (ctx != null) {
                        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ctx);
                        sendBufferingEvents = sp.getBoolean(MainActivity.PREFERENCE_KEY_SEND_BUFFERING_EVENTS, true);
                    }
                    if (MainActivity.appPlayer != null && MainActivity.appPlayer.getCurrentPosition() > 0 && sendBufferingEvents) {
                        // we only want to log a buffer event after the media has already started playing
                        if (!Helper.isNullOrEmpty(currentMediaSourceUrl)) {
                            long duration = MainActivity.appPlayer.getDuration();
                            long position = MainActivity.appPlayer.getCurrentPosition();
                            String userIdHash = Lbryio.currentUser != null ? String.valueOf(Lbryio.currentUser.getId()) : "0";
                            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
                            BufferEventTask bufferEvent = new BufferEventTask(actualClaim.getPermanentUrl(), duration, position, 1, userIdHash);
                            bufferEvent.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
                        }
                    }
                }
                loadingQualityChanged = false;
                showBuffering();
            } else if (playbackState == Player.STATE_ENDED) {
                playNextItemInPlaylist();
            } else {
                hideBuffering();
            }
        }

        @Override
        public void onIsPlayingChanged(boolean isPlayng) {
            isPlaying = isPlayng;
        }
    };
    scrollView = root.findViewById(R.id.file_view_scroll_view);
    return root;
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Player(com.google.android.exoplayer2.Player) BufferEventTask(com.odysee.app.tasks.BufferEventTask) SharedPreferences(android.content.SharedPreferences) SolidIconView(com.odysee.app.ui.controls.SolidIconView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) NestedScrollView(androidx.core.widget.NestedScrollView) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) SuppressLint(android.annotation.SuppressLint) Claim(com.odysee.app.model.Claim) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 WebView (android.webkit.WebView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 NestedScrollView (androidx.core.widget.NestedScrollView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 PhotoView (com.github.chrisbanes.photoview.PhotoView)1 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)1 Player (com.google.android.exoplayer2.Player)1 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)1 PlayerView (com.google.android.exoplayer2.ui.PlayerView)1 Claim (com.odysee.app.model.Claim)1 BufferEventTask (com.odysee.app.tasks.BufferEventTask)1 SolidIconView (com.odysee.app.ui.controls.SolidIconView)1 AttributeProviderContext (org.commonmark.renderer.html.AttributeProviderContext)1