is my first question on the website, so i hope to post it in the right way.
Context
I'm developing an application that plays two web videos at the same time.
To do so I have two web views in my activity, each showing a different website (each website contains a video).
If one of the video is muted i can play both of the video without problems, but if they are both unmuted, resuming a video, pauses the other.
Behaviour explanation (guess)
I'm guessing that this is due to audio focus: when a web view video starts playing it requests and obtain audio focus, if another is played it does the same, so the first looses the audio focus and the web view pauses it.
Question
There is a way to prevent this behavior? Preventing the web view to ask audio focus or not pausing the videos when it is lost.
I checked, and while chrome and web views have this behavior, other media apps don't, so maybe is not impossible to fix it.
I was trying to understand if an override was possible, but the audio focus behavior seems quite deep in the source code.
Any suggestion or workaround my be useful!
Thanks everyone!
Related
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.
I have an activity with a YouTubePlayerSupportFragment within it to play youtube videos.
The youtube player's style is set to CHROMELESS (only video, no controls), and playback is controlled by my own custom play/pause button outside of the player's view. Every thing works as expected until the moment I leave the video activity for whatever reason and then come back to it.
Upon leaving the activity the video is paused - as expected - but after returning to it, requesting the player to player.play() does nothing. No errors nor exceptions, it just does nothing. Play() will only work again after I load a new video..
I've trying using YouTubePlayerFragment instead, but the result is the same. However, when using the DEFAULT style pressing the default play button will apparently reload the video (I see the buffer being flushed) from the previous position and work as expected. This leads me to believe that they're handling it somehow directly on their UI control code instead of on the player API..
I can reproduce this issue on the SDK's custom controls sample just by starting a video, pressing the recents key and returning to it so I think it's safe to assume that this is a bug..
Has anyone been able to work around this issue? is there any way to detect that the video needs to be reloaded while this isn't fixed?
Info: I'm using youtube's android player API v1.2.2 and the latest youtube app v10.49.59
After hours, the only solution I found was to save video position on Pause event and reload video (player.loadVideo) on PostResume event (when YouTubeFragment is resumed). But I don't known if this is the only/best solution.
I want to use my media controller instead of build-in one of YouTube Android Player. So, I have put some views overlapped YouTube Android Player. However, I got a problem which is it always pauses automatically after played one second. Therefore, is it possible to overlay some views on YouTube Android Player?
Youtube deliberately prevent any attempt at displaying anything on top of their player.
As soon as it detects this the playback will pause.
This blocks the growth of a whole industry of video meme players :(
One main reason for this could be to prevent the obvious attempt at competing with Google for advertising space and other imaginable features that capitalize on video material published by users.
The YouTube provided player is intended to be the only possible path to accessing Youtube content.
The initial (now deprecated) Youtube API was much more liberal and allowed listing of all encoded quality versions of a clip and direct streaming of it to your own VideoView based player. This was an open path to all kinds of misuse and violations so they scrapped that in favor of a controlled solution where the Youtube player is the gateway that control how playback can occur.
The new API at least allows the player to be controlled such as seeking to a specific position and to query current position. For some apps that is hot enough a possibility for coming up with new end user value.
I have an app that shows a dancing toy in a VideoView at full screen. Sometimes another video executes over the video of the toy, in this case i have problems with the view because the video of the top shows transparent.
If i set vid1.stopPlayback(); before call the second video, it works, but i cant reproduce the first.
Is there some way to play both videos at same time?
I am not fully certain, but I got a feeling I've read simultaneous video playback may not be possible due to the way it is rendered on the screen. I can't find where I read about this, but you may try searching that way though.
I'm developing an application in which I need to play YouTube videos, I tried using webView and videoView, and I searched around a lot, I actually found some solutions, but they seem not to fit into my application needs:
So I want to know in the first place, the best way (approach) to the issue of playing a YouTube video inside an app. Should I use WebView and try to make the video fit the view and extra, or should I try VideoView (which is a little bit more complicated I guess, cause to be able to play videos I have to get the actual .3gp from Youtube).
Well thanks for helping me find the best approach.
MeanWhile I have got another question: is there a way to make the webView take the whole screen (full screen) on landscape mode (when the phone becomes landscape)?
Using the WebView approach can cause problems on some devices. The VideoView approach will work well as long as you have a solid way to parse the correct url. In one of my applications we do this using regex and parsing through the html, so far it works fast and efficiently.