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;
}
Aggregations