Git Product home page Git Product logo

Comments (6)

yschimke avatar yschimke commented on June 5, 2024 1

We made a deliberate decision to build the sample around the Google promoted options like Hilt. We previously avoided this in our samples, and we found that we ended up inventing a lot of DI concepts in the sample to fill gaps, overall was not simple either.

Some specifics:

prepare the player and release it (it seems this was removed from PlayerRepositoryImpl)

This has moved into Hilt, this lifecycle code is easy to get wrong, and once you are injecting it, it's hard to know what the tear down involves.

This is the code

Using a service to enable background playback (but not a browser service)

There are better examples that show the direct use of Media3 types, such as

https://github.com/androidx/media/blob/3f366109b7e5cbf7b7e5b46e8b923e167e9ae893/demos/session/src/main/java/androidx/media3/demo/session/PlaybackService.kt#L88

Proper way to handle updating elapsed time

This has changed to a Compose first method, see here

val progress = ProgressStateHolder.fromTrackPositionUiModel(trackPositionUiModel)

So we read the position, status, and playback speed and predict the position for each frame.

Thanks for the feedback, I'll leave this open and discuss how we can better document this.

from horologist.

Digipom avatar Digipom commented on June 5, 2024 1

Now that I've finished the migration, the main sticking points for me were:

  1. Migrating from a custom PlayerRepositoryImpl to a standard one (I was able to just delete it, use the built-in one and migrate the prepare and release code to my view model)
  2. Updating the UI for the changes and handling time updates -- your comments helped me out a lot here.
mediaDisplay = { playerUiState ->
                    val timestampProvider = LocalTimestampProvider.current
                    var position by remember { mutableStateOf(null as Duration?) }
                    val summary = position?.let {
                        DateUtils.formatElapsedTime(it.inWholeSeconds)
                    } ?: ""
                    TextMediaDisplay(
                        title = "",
                        subtitle = summary
                    )

                    LaunchedEffect(playerUiState.trackPositionUiModel) {
                        when (val state = playerUiState.trackPositionUiModel) {
                            is TrackPositionUiModel.Actual -> position = state.position
                            TrackPositionUiModel.Hidden -> position = null
                            is TrackPositionUiModel.Loading -> {
                                // Ignore -- don't erase previous value.
                            }

                            is TrackPositionUiModel.Predictive -> {
                                while (isActive) {
                                    val timestamp = timestampProvider.getTimestamp()
                                    val duration = state.predictor.predictDuration(timestamp)
                                    position = state.predictor.predictPosition(timestamp)
                                        .coerceAtMost(duration)
                                    delay(1000)
                                }
                            }
                        }
                    }
                },

I didn't have to modify the rest of the integration, but I think it would still be beneficial to have a simpler example showing how to use the framework for playing a single file out of a playlist.

from horologist.

yschimke avatar yschimke commented on June 5, 2024 1

Going to close this, as I don't think we have plans for another media sample. And I think a real media player using remote content, DI, is more useful for this if we have to choose one. So it's a choice.

But please ask on slack if you are stuck.

from horologist.

yschimke avatar yschimke commented on June 5, 2024

Also we are active on kotlin lang slack, if you have other questions, feel free to connect there and I can help 1:1. Then work out how to update the docs based on those results.

from horologist.

Digipom avatar Digipom commented on June 5, 2024

Thanks, this is super appreciated. I'll check out the slack channels too.

from horologist.

yschimke avatar yschimke commented on June 5, 2024

cc @kul3r4 for feedback

from horologist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.