Skip to content

Conversation

litetex
Copy link
Member

@litetex litetex commented Sep 21, 2021

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

This PR massively improves the handling of player errors. It consist of 2 parts:

1. Improving the player error handling

Up to this PR player errors are always just reported as grafik (or similar)
This PR introduces an option (default=off) to report the Error directly (via acra):

NPBetterErrorHandlingDemo.mp4

2. Added an option to simulate player errors

To simulate errors a debug option was introduced to crash the player.

Notes:

  • This option is only available when using a Debug version of the app (the same as the DebugSettingsFragment)
  • To make this work in all player variants (main, mini, background, popup) it was added toVideoDetailFragment - otherwise at least sometimes there is no UI where the error can be triggered from.
  • This is not a true Exoplayer error as it's not possible to crash the player internally (we would have to mess up the streaming data or something similar) therefore Player#onPlayerError is simply called with an exception
  • When no player is available (because e.g. it was crashed) a toast shows up
    grafik

Fixes the following issue(s)

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

@litetex litetex force-pushed the better-player-error-handling branch from 89a9573 to 0accbb4 Compare September 21, 2021 19:39
@litetex litetex marked this pull request as ready for review September 21, 2021 19:40
@litetex litetex added the player Issues related to any player (main, popup and background) label Sep 21, 2021
@AudricV AudricV added the feature request Issue is related to a feature in the app label Sep 24, 2021
@Stypox
Copy link
Member

Stypox commented Sep 27, 2021

I was thinking about a different approach for exceptions to report in services. I would create a new static method in the ErrorActivity that creates a notification (iirc two methods already exist for the two other ways to report an error, i.e. by opening the activity directly and by showing the bottom bar). Then when the user taps on the notification the error activity is opened via a PendingIntent.
That method could then be used in more places, e.g. in the downloader service

@Stypox
Copy link
Member

Stypox commented Sep 27, 2021

Having an option to change error reporting mode and showing it to the user seems complicated for them, and also introduces a new setting the user has to know about

@litetex
Copy link
Member Author

litetex commented Oct 1, 2021

@Stypox

Should I change anything now here in this PR? Or do you want to do a followup?
I was using what existed and tried to stick with it 😄 (KISS-principle 4tw)

@litetex
Copy link
Member Author

litetex commented Oct 24, 2021

Exoplayer sometimes throws exception that are not serializable, e.g.:
#7302 (comment)

W/PlayerErrorHandler: Unable to report error:
    java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.google.android.exoplayer2.ExoPlaybackException)
        at android.os.Parcel.writeSerializable(Parcel.java:2113)
        at org.schabi.newpipe.error.ErrorInfo.writeToParcel(Unknown Source:38)
        at android.os.Parcel.writeParcelable(Parcel.java:1904)
        at android.os.Parcel.writeValue(Parcel.java:1810)
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:975)
        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620)
        at android.os.Bundle.writeToParcel(Bundle.java:1303)
        at android.os.Parcel.writeBundle(Parcel.java:1044)
        at android.content.Intent.writeToParcel(Intent.java:10855)
        at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:3668)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1723)
        at android.app.ContextImpl.startActivity(ContextImpl.java:1023)
        at android.app.ContextImpl.startActivity(ContextImpl.java:994)
        at android.content.ContextWrapper.startActivity(ContextWrapper.java:403)
        at android.content.ContextWrapper.startActivity(ContextWrapper.java:403)
        at org.schabi.newpipe.error.ErrorActivity.reportError(ErrorActivity.java:84)
        at org.schabi.newpipe.player.playererror.PlayerErrorHandler.reportError(PlayerErrorHandler.java:69)
        at org.schabi.newpipe.player.playererror.PlayerErrorHandler.showPlayerError(PlayerErrorHandler.java:53)
        at org.schabi.newpipe.player.Player.onPlayerError(Player.java:2533)
        at com.google.android.exoplayer2.ExoPlayerImpl$PlaybackInfoUpdate.lambda$run$3$com-google-android-exoplayer2-ExoPlayerImpl$PlaybackInfoUpdate(ExoPlayerImpl.java:1425)
        at com.google.android.exoplayer2.ExoPlayerImpl$PlaybackInfoUpdate$$ExternalSyntheticLambda10.invokeListener(Unknown Source:2)
        at com.google.android.exoplayer2.BasePlayer$ListenerHolder.invoke(BasePlayer.java:279)
        at com.google.android.exoplayer2.ExoPlayerImpl.invokeAll(ExoPlayerImpl.java:1498)
        at com.google.android.exoplayer2.ExoPlayerImpl.access$100(ExoPlayerImpl.java:56)
        at com.google.android.exoplayer2.ExoPlayerImpl$PlaybackInfoUpdate.run(ExoPlayerImpl.java:1425)
        at com.google.android.exoplayer2.ExoPlayerImpl.notifyListeners(ExoPlayerImpl.java:1328)
        at com.google.android.exoplayer2.ExoPlayerImpl.updatePlaybackInfo(ExoPlayerImpl.java:956)
        at com.google.android.exoplayer2.ExoPlayerImpl.handlePlaybackInfo(ExoPlayerImpl.java:920)
        at com.google.android.exoplayer2.ExoPlayerImpl.lambda$new$0$com-google-android-exoplayer2-ExoPlayerImpl(ExoPlayerImpl.java:162)
        at com.google.android.exoplayer2.ExoPlayerImpl$$ExternalSyntheticLambda5.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.io.NotSerializableException: com.google.android.exoplayer2.mediacodec.MediaCodecInfo
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
        at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:463)
        at java.lang.Throwable.writeObject(Throwable.java:1027)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1036)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1552)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)
        at android.os.Parcel.writeSerializable(Parcel.java:2108)
        	... 36 more

So I guess we have to do some kind of workaround here...

@litetex litetex force-pushed the better-player-error-handling branch from 79152e3 to e34b2eb Compare October 24, 2021 19:09
@litetex
Copy link
Member Author

litetex commented Oct 24, 2021

Added a workaround by converting the affected exceptions into a serializable ones. Can be tested using #7302

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do you want to do a followup?

Yes, I'll do a followup

@litetex litetex force-pushed the better-player-error-handling branch from beeaba6 to 0d51eef Compare November 23, 2021 19:12
@opusforlife2
Copy link
Collaborator

Again, please don't introduce new settings.

@Stypox I think it would be better to have this kind of discussion here in the main PR comments instead of code review comments. You're not really reviewing "code". You're commenting on a general design/logic decision taken by the author, which can get lost among all the other actual code review comments. (Plus Github notifications can't properly link to the exact comment. You're just taken to the PR page and have to find it yourself, unlike a main PR comment, where you're taken to the actual comment.)

Also, you were kicked by the IRC bot for being idle. Pls rejoin.

@litetex
Copy link
Member Author

litetex commented Nov 27, 2021

@Stypox
Everything should now be refactored accordingly.
Could you please review again? :)

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to have this kind of discussion here in the main PR comments instead of code review comments.

You are right, sorry

I am unable to test whether the crasher works since I keep getting this unrelated exception when I click on the crash button, but before the selection menu shows up:

Exception

  • User Action: ui error
  • Request: ACRA report
  • Content Language: en-GB
  • Service: none
  • Version: 0.21.13
  • OS: Linux Android 10 - 29
Crash log

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
	at android.view.ViewRootImpl.setView(ViewRootImpl.java:928)
	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:387)
	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
	at android.app.Dialog.show(Dialog.java:342)
	at org.schabi.newpipe.fragments.detail.VideoDetailPlayerCrasher.onCrashThePlayer(VideoDetailPlayerCrasher.java:133)
	at org.schabi.newpipe.fragments.detail.VideoDetailFragment.lambda$initListeners$1$org-schabi-newpipe-fragments-detail-VideoDetailFragment(VideoDetailFragment.java:660)
	at org.schabi.newpipe.fragments.detail.VideoDetailFragment$$ExternalSyntheticLambda18.onClick(Unknown Source:2)
	at android.view.View.performClick(View.java:7259)
	at android.view.View.performClickInternal(View.java:7236)
	at android.view.View.access$3600(View.java:801)
	at android.view.View$PerformClick.run(View.java:27892)
	at android.os.Handler.handleCallback(Handler.java:883)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loop(Looper.java:214)
	at android.app.ActivityThread.main(ActivityThread.java:7356)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)


@litetex
Copy link
Member Author

litetex commented Nov 28, 2021

@Stypox
Should be fixed now: The exception was causes by using the wrong context.

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you! I will start the followup PR this week :-)

@Stypox Stypox merged commit c7daf32 into TeamNewPipe:dev Nov 28, 2021
@litetex litetex deleted the better-player-error-handling branch November 28, 2021 16:04
This was referenced Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Issue is related to a feature in the app player Issues related to any player (main, popup and background)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better handling of ExoPlayer/unrecoverable player errors

4 participants