Skip to content
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

Move ExoPlayer initialization to a Dagger module and optimize its dependencies #4296

Merged
merged 4 commits into from
Mar 9, 2024

Conversation

cbeyls
Copy link
Contributor

@cbeyls cbeyls commented Feb 29, 2024

Currently, ExoPlayer is initialized explicitly in ViewMediaFragment with all its dependencies, including many that are not useful for viewing Mastodon media attachments.

This pull request moves most ExoPlayer initialization and configuration to a new Dagger module, and instead a Provider<ExoPlayer> factory is injected in the Fragment so it can create new instances when needed.

The following ExoPlayer components will be configured:

  • Renderers: all of them (audio, video, metadata, subtitles) except for the CameraMotionRenderer.
  • Extractors: FLAC, Wav, Mp4, Ogg, Matroska/WebM and MP3 containers, to provide the same support as Firefox or Chrome browsers. Other container formats that are either image formats (already covered by Glide), not web-friendly or reserved for live streaming are skipped.
  • MediaSource: only progressive download (through OkHttp) is provided. Live streaming support using protocols like RTSP, MPEG/Dash or HLS is skipped, because Mastodon servers don't use these protocols to download attachments.

The Mastodon documentation mentions the supported media formats for attachments and this covers them and even more. The docs also mentions that the video and audio files are transcoded to MP4 and MP3 upon upload but that was not the case in the past (for example WebM was used) and it could change again in the future.

Specifying these components manually allows reducing the APK size by about 200 KB thanks to R8 shrinking.

There are also a few extra code changes:

  • Remove the code specific to API < 24 since the min SDK of the app is now 24.
  • Add support for pausing a video when unplugging headphones.
  • Specify the audio attributes according to content type to help the Android audio mixer.

@connyduck connyduck requested a review from mcclure March 1, 2024 08:10
Copy link
Collaborator

@mcclure mcclure left a comment

Choose a reason for hiding this comment

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

This seems like a great improvement! Note, I have not had the chance to build and test locally so I'll assume you've done basic smoke tests at your end.

@connyduck connyduck merged commit 9901376 into tuskyapp:develop Mar 9, 2024
3 checks passed
@cbeyls cbeyls deleted the refactor/player_module branch April 8, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants