Integrate External Player
If you're looking to extend the NativeWaves playback capabilities by integrating an external Player instance, our SDK provides a seamless way to inject your own Player. This flexibility ensures that you can tailor the playback experience to fit your specific needs while leveraging the robust features of ExoPlayer.
Currently, our SDK supports the integration of external ExoPlayer instances only.
To smoothly add your own version of ExoPlayer to the SDK's video playback process, use the SDK's special observer feature. This feature waits for the right time, indicated by the SDK, to add your ExoPlayer.
It's important to note that this observer is strategically triggered under specific conditions to ensure optimal synchronization with the SDK's lifecycle and usage scenarios:
- Initialization: The observer is activated during the initialization phase of audio or video players, preparing the environment for immediate playback needs.
- Switching Streams: Additionally, the observer reactivates whenever there's a switch in video camera feeds or commentary streams (if applicable), accommodating dynamic content changes without disrupting the user experience.
Below is a code snippet illustrating how to observe for the signal and inject your ExoPlayer instance. Note that while this implementation demonstrates the process, it's not mandatory for developers to use this exact approach. Feel free to adapt it to suit your application's architecture and requirements.
- Initialize : Create and maintain a reference to ExperiencePlaybackService within your composable function. This reference is observed to detect when the service is ready to accept an ExoPlayer instance.
- Observe and Respond: Utilize LaunchedEffect with the expPlayback state as a key. This effect listens for any changes to the expPlayback state, which signal readiness for ExoPlayer injection.
- Inject ExoPlayer: Upon receiving the signal, use the expInitializePlayer flow to get a Channel. Through this channel, send your custom ExoPlayer instance using trySend(generateExoplayer()). After sending, close the channel with responseChannel.close() to indicate completion.
This mechanism ensures a decoupled and flexible way to integrate custom ExoPlayer instances into your application, enhancing the video and audio playback capabilities of the SDK with your tailored solutions.