Skip to content

Tags: Alitzlan/bv

Tags

2026.5.9-memory-qr-fix

Toggle 2026.5.9-memory-qr-fix's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Reduce OOM and use simple QR code renderer

## Overview

This PR reduces OOM / lag risk on low-memory Android TV devices by simplifying the TV login QR code and tightening playback resource cleanup.

### TV login QR

- Replaces the animated `MaterialShapeQr` login QR on TV with a static `SimpleQrCode` component.
- The new component uses ZXing to generate a simple black/white QR bitmap with `Bitmap.Config.RGB_565`.
- This avoids the previous Lottie background, dynamic Material-shape renderer objects, per-frame Canvas animation, and 60fps state updates during sign-in.
- `AppQrLoginViewModel` now updates `loginUrl` / `key` on the Main thread and cancels the QR polling timer in `onCleared()`.

### Player / native resource cleanup

- Hardens `ExoMediaPlayer.release()`:
  - removes the listener
  - stops playback
  - clears media items
  - releases the player
  - nulls player/media/listener references
- Clears the previous media source before switching streams to reduce native decoder / MediaCodec buffer retention on TV boxes.
- Detaches `PlayerView` from ExoPlayer in `AndroidView.onRelease` via `playerView.player = null`, so Surface/decoder resources can be returned promptly.

### Danmaku cleanup without breaking seek

- Releases the old `DanmakuPlayer` and clears old danmaku/mask/video-shot/subtitle data when loading a new video or when the ViewModel is cleared.
- Fast-forward / rewind behavior is intentionally preserved: timeline jumps still keep the current `DanmakuPlayer` and loaded danmaku data, and continue to use `seekTo(position)` rather than releasing/reloading danmaku.
- Preserves subtitle auto-restore for next episode playback by recording whether subtitles were enabled before clearing old playback data.

## Why

Low-end Android TV boxes are sensitive to native decoder buffers, Surface resources, large UI animations, and full in-memory danmaku data. The previous TV sign-in QR implementation was visually nice but heavy for a one-time login screen, and playback cleanup relied too much on delayed lifecycle/dispose behavior.

This PR favors predictable low-memory behavior over visual effects on TV.

## Review notes

Please pay special attention to:

1. TV login screen: QR should display and scan correctly.
2. Enter/exit playback repeatedly: memory should be less likely to accumulate.
3. Switch episodes/videos: old danmaku resources should be released and new danmaku should load.
4. Fast-forward / rewind: danmaku should still seek and display correctly after timeline jumps.
5. Subtitle auto-restore on next episode should still work when subtitles were enabled.

## Testing

Not run in this environment. Recommended local checks:

```bash
./gradlew :app📺assembleDebug
```

Then test on an Android TV device / emulator:

- sign in with QR
- play a video with danmaku enabled
- fast-forward / rewind repeatedly
- switch to another episode/video
- exit and re-enter playback several times