-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create media session UI and fix player notification #8678
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM mostly.
but there are build failures and some minor problems:
PS: I will test this when the build works again
@Override | ||
public void onBroadcastReceived(final Intent intent) { | ||
super.onBroadcastReceived(intent); | ||
// TODO decide whether to handle ACTION_HEADSET_PLUG or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO detected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already there before, I will not take care of it in this PR. I added it to #8616.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't know. Maybe we should remove this TODO and call it a day, since it has been there since forever and NewPipe's behavior when headsets are plugged or unplugged is currently correct. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I think we should remove it.
If someone has a problem, we can create an issue and handle it there.
Optional.ofNullable(player.getThumbnail()) | ||
.filter(bitmap -> showThumbnail) | ||
.ifPresent(bitmap -> { | ||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap); | ||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't something like
if (player.getPrefs().getBoolean(context.getString(R.string.show_thumbnail_key), true)) {
final BitMap bitmap = player.getThumbnail(); // might be done inline
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap);
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap);
}
be better here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the bitmap was set only if it was non null, so I made sure the same behavior is kept, avoiding setting null
thumbnails, even though it should not really be a problem.
app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/player/mediasession/PlayQueueNavigator.java
Outdated
Show resolved
Hide resolved
I applied two review suggestions and rebased.
Not a problem in this PR, see #8679 |
Anything else apart from these 2 issues?
Well, yes, but we wouldn't know which ones to look for between the current release and this PR. Gotta test whatever we can, I guess. |
In the middle of a video, I suddenly got a buffering indicator for ~half a second, and then the app completely crashed, with no error caught by Newpipe. Scoop's crash report:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM
Did a quick test and everything seems to work fine.
Profiler also said that there are no bigger performance problems.
However you may address opus comment above before merging.
And btw you may also cleanup your fork-repo, there are a ton of unused branches there which are fetched by Git when I check it out :/
@opusforlife2's problem is unrelated to this PR. It is instead another instance of #8661.
@litetex Ok, I'll do it, I never cared about old branches 😅. But did you know you don't need to check my fork-repo out? You can just add this to your
And then you can do |
This comment was marked as off-topic.
This comment was marked as off-topic.
8d0cea4
to
d402ed7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased and retested, LGTM
Also thank you for the tip Stypox but I will stay at least for now with my
git remote add Stypox https://github.com/Stypox/NewPipe.git
and do the rest via GH desktop :D
The player is now passed directly, it made no sense to wrap around it in a callback that was not really a callback but rather, actually, a wrapper.
The thumbnail was not being updated in the media session metadata after it was loaded, since there was no metadata update in that case, only a notification update.
Before the thumbnail finishes loading for the new video the player is now playing, the old thumbnail was being used, leading to wrong thumbnails set in the media session and the notification.
This makes sure the thumbnail is removed from the notification if the user disables thumbnails
A while ago NewPipe called the metadata update function very often, so checks were needed to ensure not wasting time updating metadata if it were already up to date. Now, instead, the metadata update function is called exactly when needed, i.e. when metadata changes, so such checks are not needed anymore (and were probably also a little resource-heavy).
Though still make sure metadata is updated after the thumbnail is loaded. This fixes the wrong seekbar properties (duration and current position) being shown in the notification sometimes.
Before the Target would sometimes be garbage collected before being called with the loaded thumbnail, since Picasso holds weak references to targets
+ Automatically fixed code style (imports)
de8dcc9
to
59d1ded
Compare
Kudos, SonarCloud Quality Gate passed! |
What is it?
Description of the changes in your PR
This PR solves one of the points in #8616: it introduces
MediaSessionPlayerUi
, moving more code out of thePlayer
, and fixes various serious issues related to the player notification and the media session. I tried to put as much info as possible in commit messages and comments, so that it is simpler to debug and git blame.MediaSessionCallback
andPlayerMediaSession
was just a wrapper for some player functions (half of which used in one place, half in another), but it didn't make any sense not to use the player instance directly bca9543MediaSessionManager
was moved inMediaSessionPlayerUi
49be75ecould happenalmost always happened that the new thumbnail would never be shown. 80df363null
thumbnail, until the new thumbnail loading finishes. The placeholder thumbnail is not used anymore, as it makes more sense to just not set a thumbnail. 25f40a6null
when the user disables all thumbnails from settings while the notification is open (this requires a notification update to kick in), otherwise the lastly set thumbnail would be incorrectly shown. c9c55b1MediaSessionConnector.setMetadataDeduplicationEnabled(true)
was used to keep the previous behavior of not updating metadata if nothing changed from the already-set metadata. Now the number of updates is a little bit higher (tested by setting "noisy non-suspending breakpoints"), but there is no random update while playing or with other actions that do not change the current stream info, which would drain battery. E.g. 7 metadata updates instead of 2 when the player is started, and 3 instead of 2 when a new stream info plays. (740ab8a) and most importantly d0677bbYou can test changes to the media session by installing this neat media session testing app. Some of the
Test
s provided there are unsuccessful, but I don't know why since the actions they test are actually performed correctly (I included this sentence just so you know, as fixing the tests, which are related to player actions, is out of the scope of this PR).This is related to #7166, so I'd like @litetex to review.
Before/After Screenshots/Screen Record
I am not providing screenshots of all of the various issues there were before, since they take a while to reproduce and if you have used NewPipe for a while you know about them by now.
Fixes the following issue(s)
Strangely enough I could not find any... Maybe somebody of you has a clue?
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.
Due diligence