Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fd7a669
Saving streams positions and resume it
Koitharu Dec 27, 2018
7fb6274
Show watch position on VideoDetailFragment
Koitharu Dec 27, 2018
2d1e5ab
Database migration
Koitharu Dec 27, 2018
e0b8d7c
Show toast on playback resumed
Koitharu Dec 27, 2018
000b7b7
Dont resume playback if less then 10 seconds left
Koitharu Dec 29, 2018
b86c420
Playback resume preference
Koitharu Dec 29, 2018
83fcb1a
Show player interface on playback resumed
Koitharu Dec 29, 2018
fafbd59
Fix bug with player state
Koitharu Dec 29, 2018
d01158b
Increase database version
Koitharu Dec 31, 2018
31300e0
Use StreamState
Koitharu Jan 9, 2019
982d427
Merge branch 'dev' into playback_resume
Koitharu Feb 23, 2019
40570f7
Refactor: threshold constant
Koitharu Feb 27, 2019
1c11b36
Merge branch 'dev' into playback_resume
Koitharu Mar 5, 2019
e482b68
Fixes
Koitharu Mar 5, 2019
7464362
Save playback state in popup player
Koitharu Mar 5, 2019
dd88990
Save playback state in background player
Koitharu Mar 5, 2019
2dc3d54
Merge branch 'dev' into playback_resume
theScrabi Mar 5, 2019
f10ebc8
Fix playback save thresholds
Koitharu Mar 6, 2019
2677298
Remove playback state on finishing stream
Koitharu Mar 6, 2019
3269692
Save playback state on change quality
Koitharu Mar 6, 2019
0a097ee
Merge branch 'dev' of https://github.com/TeamNewPipe/NewPipe into pla…
Koitharu Mar 6, 2019
3cbc84d
Fix settings layout
Koitharu Mar 6, 2019
93e6eef
Merge branch 'dev' of https://github.com/TeamNewPipe/NewPipe into pla…
Koitharu Mar 11, 2019
b73d3c7
Reset playback state on playing complete
Koitharu Mar 11, 2019
06cf59f
Fix logging
Koitharu Mar 12, 2019
393cea9
Fix playback state saving again
Koitharu Mar 12, 2019
ca103ae
Fix trouble with background player
Koitharu Mar 12, 2019
d3153d9
Merge branch 'dev' into playback_resume
TobiGr Apr 8, 2019
41a9b44
Merge branch 'dev' into playback_resume
TobiGr Apr 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public abstract class StreamHistoryDAO implements HistoryDAO<StreamHistoryEntity
@Nullable
public abstract StreamHistoryEntity getLatestEntry();

@Query("SELECT * FROM " + STREAM_HISTORY_TABLE + " WHERE " + JOIN_STREAM_ID +
" = :streamId ORDER BY " + STREAM_ACCESS_DATE + " DESC LIMIT 1")
@Nullable
public abstract StreamHistoryEntity getLatestEntry(final long streamId);

@Override
@Query("SELECT * FROM " + STREAM_HISTORY_TABLE)
public abstract Flowable<List<StreamHistoryEntity>> getAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
Expand All @@ -49,6 +50,8 @@

import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
Expand All @@ -71,6 +74,7 @@
import org.schabi.newpipe.info_list.InfoItemDialog;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.player.BasePlayer;
import org.schabi.newpipe.player.MainVideoPlayer;
import org.schabi.newpipe.player.PopupVideoPlayer;
import org.schabi.newpipe.player.playqueue.PlayQueue;
Expand All @@ -95,6 +99,7 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import icepick.State;
import io.reactivex.Single;
Expand Down Expand Up @@ -134,8 +139,10 @@ public class VideoDetailFragment

private StreamInfo currentInfo;
private Disposable currentWorker;

@NonNull
private CompositeDisposable disposables = new CompositeDisposable();
private HistoryRecordManager recordManager;

private List<VideoStream> sortedVideoStreams;
private int selectedVideoStreamIndex = -1;
Expand All @@ -153,6 +160,7 @@ public class VideoDetailFragment
private View thumbnailBackgroundButton;
private ImageView thumbnailImageView;
private ImageView thumbnailPlayButton;
private ProgressBar positionView;

private View videoTitleRoot;
private TextView videoTitleTextView;
Expand All @@ -165,6 +173,7 @@ public class VideoDetailFragment
private TextView detailControlsDownload;
private TextView appendControlsDetail;
private TextView detailDurationView;
private TextView detailPositionView;

private LinearLayout videoDescriptionRootLayout;
private TextView videoUploadDateView;
Expand Down Expand Up @@ -259,6 +268,8 @@ public void onResume() {
// Check if it was loading when the fragment was stopped/paused,
if (wasLoading.getAndSet(false)) {
selectAndLoadVideo(serviceId, url, name);
} else if (currentInfo != null) {
updatePositionInfo(currentInfo);
}
}

Expand Down Expand Up @@ -289,10 +300,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case ReCaptchaActivity.RECAPTCHA_REQUEST:
if (resultCode == Activity.RESULT_OK) {
NavigationHelper.openVideoDetailFragment(getFragmentManager(), serviceId, url, name);
} else Log.e(TAG, "ReCaptcha failed");
} else if (DEBUG) Log.e(TAG, "ReCaptcha failed");
break;
default:
Log.e(TAG, "Request code from activity not supported [" + requestCode + "]");
if (DEBUG) Log.e(TAG, "Request code from activity not supported [" + requestCode + "]");
break;
}
}
Expand Down Expand Up @@ -385,7 +396,7 @@ public void onClick(View v) {
break;
case R.id.detail_uploader_root_layout:
if (TextUtils.isEmpty(currentInfo.getUploaderUrl())) {
Log.w(TAG, "Can't open channel because we got no channel URL");
if (DEBUG) Log.w(TAG, "Can't open channel because we got no channel URL");
} else {
try {
NavigationHelper.openChannelFragment(
Expand Down Expand Up @@ -455,6 +466,7 @@ protected void initViews(View rootView, Bundle savedInstanceState) {
thumbnailBackgroundButton = rootView.findViewById(R.id.detail_thumbnail_root_layout);
thumbnailImageView = rootView.findViewById(R.id.detail_thumbnail_image_view);
thumbnailPlayButton = rootView.findViewById(R.id.detail_thumbnail_play_button);
positionView = rootView.findViewById(R.id.position_view);

contentRootLayoutHiding = rootView.findViewById(R.id.detail_content_root_hiding);

Expand All @@ -469,6 +481,7 @@ protected void initViews(View rootView, Bundle savedInstanceState) {
detailControlsDownload = rootView.findViewById(R.id.detail_controls_download);
appendControlsDetail = rootView.findViewById(R.id.touch_append_detail);
detailDurationView = rootView.findViewById(R.id.detail_duration_view);
detailPositionView = rootView.findViewById(R.id.detail_position_view);

videoDescriptionRootLayout = rootView.findViewById(R.id.detail_description_root_layout);
videoUploadDateView = rootView.findViewById(R.id.detail_upload_date_view);
Expand Down Expand Up @@ -672,8 +685,10 @@ private static void showInstallKoreDialog(final Context context) {
}

private void setupActionBarOnError(final String url) {
if (DEBUG) Log.d(TAG, "setupActionBarHandlerOnError() called with: url = [" + url + "]");
Log.e("-----", "missing code");
if (DEBUG) {
Log.d(TAG, "setupActionBarHandlerOnError() called with: url = [" + url + "]");
Log.e("-----", "missing code");
}
}

private void setupActionBar(final StreamInfo info) {
Expand Down Expand Up @@ -724,10 +739,10 @@ public void pushToStack(int serviceId, String videoUrl, String name) {
if (stack.size() > 0
&& stack.peek().getServiceId() == serviceId
&& stack.peek().getUrl().equals(videoUrl)) {
Log.d(TAG, "pushToStack() called with: serviceId == peek.serviceId = ["
if (DEBUG) Log.d(TAG, "pushToStack() called with: serviceId == peek.serviceId = ["
+ serviceId + "], videoUrl == peek.getUrl = [" + videoUrl + "]");
return;
} else {
} else if (DEBUG) {
Log.d(TAG, "pushToStack() wasn't equal");
}

Expand Down Expand Up @@ -944,11 +959,15 @@ private void startOnExternalPlayer(@NonNull final Context context,
NavigationHelper.playOnExternalPlayer(context, currentInfo.getName(),
currentInfo.getUploaderName(), selectedStream);

final HistoryRecordManager recordManager = new HistoryRecordManager(requireContext());
if (recordManager == null) {
recordManager = new HistoryRecordManager(requireContext());
}
disposables.add(recordManager.onViewed(info).onErrorComplete()
.subscribe(
ignored -> {/* successful */},
error -> Log.e(TAG, "Register view failure: ", error)
error -> {
if (DEBUG) Log.e(TAG, "Register view failure: ", error);
}
));
}

Expand Down Expand Up @@ -1032,6 +1051,8 @@ public void showLoading() {
animateView(spinnerToolbar, false, 200);
animateView(thumbnailPlayButton, false, 50);
animateView(detailDurationView, false, 100);
animateView(detailPositionView, false, 100);
animateView(positionView, false, 50);

videoTitleTextView.setText(name != null ? name : "");
videoTitleTextView.setMaxLines(1);
Expand Down Expand Up @@ -1146,6 +1167,7 @@ public void handleResult(@NonNull StreamInfo info) {
videoUploadDateView.setText(Localization.localizeDate(activity, info.getUploadDate()));
}
prepareDescription(info.getDescription());
updatePositionInfo(info);

animateView(spinnerToolbar, true, 500);
setupActionBar(info);
Expand Down Expand Up @@ -1250,4 +1272,46 @@ public void onBlockedByGemaError() {

showError(getString(R.string.blocked_by_gema), false, R.drawable.gruese_die_gema);
}

private void updatePositionInfo(final StreamInfo info) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
final boolean playbackResumeEnabled =
prefs.getBoolean(activity.getString(R.string.enable_watch_history_key), true)
&& prefs.getBoolean(activity.getString(R.string.enable_playback_resume_key), true);
if (!playbackResumeEnabled || info.getDuration() <= 0) {
positionView.setVisibility(View.INVISIBLE);
detailPositionView.setVisibility(View.GONE);
return;
}
if (recordManager == null) {
recordManager = new HistoryRecordManager(requireContext());
}
disposables.add(recordManager.loadStreamState(info)
.onErrorComplete()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
state -> {
final int seconds = (int) (state.getProgressTime() / 1000.f);
if (seconds > BasePlayer.PLAYBACK_SAVE_THRESHOLD_START_SECONDS &&
seconds < info.getDuration() - BasePlayer.PLAYBACK_SAVE_THRESHOLD_END_SECONDS) {
positionView.setMax((int) info.getDuration());
positionView.setProgress(seconds);
detailPositionView.setText(Localization.getDurationString(seconds));
animateView(positionView, true, 500);
animateView(detailPositionView, true, 500);
} else {
animateView(positionView, false, 500);
animateView(detailPositionView, false, 500);
}
},
error -> {
if (DEBUG) Log.e(TAG, "Player resume failure: ", error);
},
() -> {
animateView(positionView, false, 500);
animateView(detailPositionView, false, 500);
}
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ public Flowable<List<StreamHistoryEntry>> getStreamHistory() {
return streamHistoryTable.getHistory().subscribeOn(Schedulers.io());
}

public Maybe<StreamHistoryEntity> getStreamHistory(final StreamInfo info) {
return Maybe.fromCallable(() -> {
final long streamId = streamTable.upsert(new StreamEntity(info));
return streamHistoryTable.getLatestEntry(streamId);
}).subscribeOn(Schedulers.io());
}

public Flowable<List<StreamStatisticsEntry>> getStreamStatistics() {
return streamHistoryTable.getStatistics().subscribeOn(Schedulers.io());
}
Expand Down Expand Up @@ -195,6 +202,13 @@ public Maybe<Long> saveStreamState(@NonNull final StreamInfo info, final long pr
})).subscribeOn(Schedulers.io());
}

public Maybe<Integer> resetStreamState(@NonNull final StreamInfo info) {
return Maybe.fromCallable(() -> database.runInTransaction(() -> {
final long streamId = streamTable.upsert(new StreamEntity(info));
return streamStateTable.deleteState(streamId);
})).subscribeOn(Schedulers.io());
}

///////////////////////////////////////////////////////
// Utility
///////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private void onClose() {
lockManager.releaseWifiAndCpu();
}
if (basePlayerImpl != null) {
basePlayerImpl.savePlaybackState();
basePlayerImpl.stopActivityBinding();
basePlayerImpl.destroy();
}
Expand Down
Loading