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

Remove global AVPlayer instance #382

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

rikner
Copy link
Contributor

@rikner rikner commented Dec 7, 2022

Fixes #

Type of change:

Motivation (current vs expected behavior)

We have a global AVPlayer instance in order to be able to reference our AVPlayer inside JNI callbacks. While this works it's not a good practice and wouldn't work anymore once there are more than on AVPlayer instances.
This PR saves the memory address of our AVPlayer inside the kotlin implementation (userContext) which we can use to later retrieve our player instance in the native callbacks.

Please check if the PR fulfills these requirements

  • Self-review: I am confident this is the simplest and clearest way to achieve the expected behaviour
  • There are no dependencies on other PRs or I have linked dependencies through Zenhub
  • The commit messages are clean and understandable
  • Tests for the changes have been added (for bug fixes / features)

@rikner rikner changed the base branch from master to video-jni-error December 7, 2022 12:41
Copy link
Member

@ephemer ephemer left a comment

Choose a reason for hiding this comment

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

I would like to see the naming of what is currently called userContext more closely reflect what it really is, rather than using the generic naming. Other than that though, this looks good to me!

}
}

exoPlayer.addListener(listener)
}

fun setUserContext(ctx: Long) {
this.userContext = ctx
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain the naming of userContext? If the idea based on C APIs which take a void * userCtx parameter, then I think the naming might be too generic for what it really is.

From my current understanding, I would just call this "pointerToSwiftAVPlayerInstance" or something equally specific. userContext in the C meaning of the word is something very generic that could be anything at all, which is why it's usually defined as void*. That doesn't really fit our use case here 🙏🏼

Base automatically changed from video-jni-error to master December 8, 2022 11:46
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.

2 participants