I am developing an android news application in which we are having a fragment that we use for Article details listing.
An article might contain any media like plain Image or a Video as the top content with the Article Title. The Fragment is simply consist of a plain RecyclerView in it.
When we scroll up, we will see the Article Body followed by the Relative Articles listing. The body might consist of plain text paragraph, HTML paragraphs having clickable Anchor tag text in it or the entire body might be a full web-based script that could be loaded in a webview.
The situation is being uncontrolled when we encounter media like YouTube Video iFrame, Tweet having video in it or some streamed audio with media controls. As of previous implementations this videos could be played inline on the same page and user can continue scrolling through the remaining article body, which was okay yet.
Now what we are doing, just lifting up the top title video out of recyclerView, so it could be continued playing even when user scrolled down a lot while reading the article body content.
Problem Statement: When the main Media is playing in the top (Could be a brightcove or youtube video), and if user clicks the play button of the media rendered in WebView, the previous native player video continues playing with the WebView video/audio stream. Yes they are playing simultaneously having the audio collision too.
What I want: I am in search of some callback that will notify me about the media stream started and finished playing in WebView from the WebView itself. Or if WebView is not capable to do so, a callback from the Android system also could help when the latest audio stream attached and de-attached to OS Audio Channel for being played via speakers.
What I have tried: I have went through lot of official and other documentations and articles about WebView methods and callbacks, Android MediaSession callback also. Nothing helped me that much, the problem is still there.
Points to consider:
- The Top Title Video is being played in Native SDKs from Brightcove and YouTube.
- We are having full controls over these players, so we can play, pause or restrict user interactions anytime programmatically on them.
- So while some flag named isWebViewPlayingMedia valued true we will ignore user play requests on Native players.
- The VideoPlayer will completely be independent of RecyclerView item lifecycle, it won't stop playing video when user scrolled up a lot even upto the bottom of the RecyclerView. The player is floating on the top of our recyclerView.