-
-
Notifications
You must be signed in to change notification settings - Fork 745
Introduce HAMediaPlayer to migrate existing player to compose #5408
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
Conversation
app/src/main/kotlin/io/homeassistant/companion/android/player/BufferingState.kt
Fixed
Show fixed
Hide fixed
app/src/main/kotlin/io/homeassistant/companion/android/player/BufferingState.kt
Fixed
Show fixed
Hide fixed
app/src/main/kotlin/io/homeassistant/companion/android/player/HAMediaPlayer.kt
Fixed
Show fixed
Hide fixed
I think this would qualify as visual changes not in the frontend, so please include a screenshot in the future for similar changes ;) |
I will the only thing for now is that until it is not integrated in the app it's not very clear how it looks like. I'm going to add how it looks like on the dev activity. |
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.
Seems like a pretty good start for a basic player!
If I turn off the screen, I lose video progress and it starts back at the start of the video. Not entirely sure if that is the demo video or the Compose implementation.
Small size player highlights layout issues:
- the bottom bar partially obscures the play/pause icon
- start and end padding isn't the same because of the icon button, I think the text needs more padding at the start
LeakCanary popped up after exiting the activity, saying there was an issue:
LeakCanary trace
┬───
│ GC Root: System class
│
├─ android.provider.FontsContract class
│ Leaking: NO (HomeAssistantApplication↓ is not leaking and a class is never
│ leaking)
│ ↓ static FontsContract.sContext
├─ io.homeassistant.companion.android.HomeAssistantApplication instance
│ Leaking: NO (Application is a singleton)
│ mBase instance of android.app.ContextImpl
│ ↓ Application.mLoadedApk
│ ~~~~~~~~~~
├─ android.app.LoadedApk instance
│ Leaking: UNKNOWN
│ Retaining 10.1 kB in 162 objects
│ mApplication instance of io.homeassistant.companion.android.
│ HomeAssistantApplication
│ Receivers
│ ..DemoExoPlayerActivity@38767496
│ ....MediaSessionLegacyStub$MediaButtonReceiver@39579224
│ ..HomeAssistantApplication@33649392
│ ....MediaPlayerControlsWidget@35483216
│ ....SensorReceiver@35328608
│ ....VisibilityTracker@34591576
│ ....cs@39014000
│ ....TemplateWidget@35487080
│ ....io@39255048
│ ....ButtonWidget@35467640
│ ....WebsocketBroadcastReceiver@35102864
│ ....TodoWidget@35494184
│ ....it@39172856
│ ....NetworkTypeObserver$Receiver@39433520
│ ....EntityWidget@35474104
│ ....ik@39255632
│ ↓ LoadedApk.mReceivers
│ ~~~~~~~~~~
├─ android.util.ArrayMap instance
│ Leaking: UNKNOWN
│ Retaining 9.6 kB in 148 objects
│ ↓ ArrayMap.mArray
│ ~~~~~~
├─ java.lang.Object[] array
│ Leaking: UNKNOWN
│ Retaining 9.5 kB in 146 objects
│ ↓ Object[0]
│ ~~~
╰→ io.homeassistant.companion.android.developer.DemoExoPlayerActivity instance
Leaking: YES (ObjectWatcher was watching this because io.homeassistant.
companion.android.developer.DemoExoPlayerActivity received
Activity#onDestroy() callback and Activity#mDestroyed is true)
Retaining 280.9 kB in 4236 objects
key = 6f808c2c-a2cc-4915-8dc3-e1ac7f0be014
watchDurationMillis = 50022
retainedDurationMillis = 45018
mApplication instance of io.homeassistant.companion.android.
HomeAssistantApplication
mBase instance of androidx.appcompat.view.ContextThemeWrapper
METADATA
Build.VERSION.SDK_INT: 36
Build.MANUFACTURER: Google
LeakCanary version: 2.14
App process name: io.homeassistant.companion.android.debug
Class count: 41689
Instance count: 274500
Primitive array count: 197937
Object array count: 40711
Thread count: 50
Heap total bytes: 36924602
Bitmap count: 3
Bitmap total bytes: 36163
Large bitmap count: 0
Large bitmap total bytes: 0
Db 1: open /data/user/0/io.homeassistant.companion.android.
debug/no_backup/androidx.work.workdb
Db 2: open /data/user/0/io.homeassistant.companion.android.
debug/databases/HomeAssistantDB
Stats: LruCache[maxSize=3000,hits=133643,misses=254955,hitRate=34%]
RandomAccess[bytes=12572701,reads=254955,travel=136972692539,range=45653516,size
=56454593]
Analysis duration: 79901 ms
I learned some new KDoc syntax, nice.
app/src/main/kotlin/io/homeassistant/companion/android/player/BufferingState.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/player/FakePlayer.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/player/HAMediaPlayer.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/player/HAMediaPlayer.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/player/HAMediaPlayer.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/player/MuteUnmuteButtonState.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/player/BufferingState.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/player/HAMediaPlayer.kt
Outdated
Show resolved
Hide resolved
About the Leak did it happen with PiP? Are you able to reproduce it all the time? |
While working on the migration of the WebViewActivity I came around the fact that I should have extract the Player initialization out of the Compose definition. 🤦🏻 |
Test Results 41 files 41 suites 4m 47s ⏱️ Results for commit aa449de. ♻️ This comment has been updated with latest results. |
I was able to reproduce it all the time, but not anymore since you removed the MediaSession. Just opening the activity, and going back using the system back button was enough to trigger it.
OK, seems reasonable. New issue that also would apply to the classic view ExoPlayer: the preview in the playground activity can no longer be full screened, maybe it's better to make that one bigger so we can test all functionality (making it smaller is easy enough with splitscreen).
OK, let's keep that out of scope for this PR. |
...rc/main/kotlin/io/homeassistant/companion/android/util/compose/media/player/HAMediaPlayer.kt
Outdated
Show resolved
Hide resolved
...rc/main/kotlin/io/homeassistant/companion/android/util/compose/media/player/HAMediaPlayer.kt
Outdated
Show resolved
Hide resolved
...rc/main/kotlin/io/homeassistant/companion/android/util/compose/media/player/HAMediaPlayer.kt
Show resolved
Hide resolved
...rc/main/kotlin/io/homeassistant/companion/android/util/compose/media/player/HAMediaPlayer.kt
Outdated
Show resolved
Hide resolved
...kotlin/io/homeassistant/companion/android/util/compose/media/player/MuteUnmuteButtonState.kt
Outdated
Show resolved
Hide resolved
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 seems good enough for now, I couldn't discover any more issues. We can improve the UI in the future based on feedback.
Summary
In order to migrate to compose the
WebViewActivity
we need to have a compose view of the media player. By default only the surface is provided not the control, this PR adds a very basic implementation of the controls. It is not feature complete. Since the WebView at the moment is only using this player to play a camera, the implementation is currently limited to this use case.I decided to first make a PR that replace the player in
DevPlayground
so it can be use later in the PR for the WebView to compose.Checklist
Screenshots
demo_player.mp4
Any other notes
I'm not a compose expert so any comment on how to make it better is very much appreciated.
I added the media session so that the system can control the player too. It is useful to stop a playback for instance when the player is in a PiP mode.