Is it possible to overlay some views on YouTube Android Player? - android

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.

Related

Receiving callbacks on Audio/Video Stream being Played and Paused in Android WebView

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.

How to play a youtube video in side-by-side view on Android WebView

I'm trying to make an Android App and I need help.
Do you have any idea how to play a online video (like a video on Youtube) in side-by-side view at the very same time by using Android WebView?
so, when I watch a Youtube video, I want to be able to have two views on left and right side on My Android SmartPhone Screen, and play and control the same video both on left and right views at the very same time.
Regards.
----2nd Feb, edited----
following things I've tried and failed.
・using Youtube API, get 3gp address, and try to play it with VideoView
・Using draw method and getDrawingCache method of WebView
・using onShowCustomView of WebView
Look at using a html5 video player like Video.js or Sublime Video. You will need to create some javascript with each of these that fires the left and right video at the same time.
You can also look at what this guys did for some more inspiration.
http://html5demos.com/two-videos
The trick is getting the videos to fire at the same time if you need them in sync. It's not easy to achieve if you don't control the source video and server as you are relying on an outside party to do this. YouTube is NOT a good choice for serving your videos if you need them to be in sync as you can't guarantee the video load and launch times, or control if an ad will get injected into the video stream.

SoundCloud HTML5 Widget API - Play Not Working in Chrome for Android

You can see the player live here:
www.stateofpsychosis.com/media/
The viewable player is a custom player. The default SC player has been shrunk down to a 1x1px iframe so it can't be seen without using the developer tools to make changes to the style.
This is only a problem on Chrome for Android
For some reason I can't get the API to actually play the music. The Previous/Next buttons work in the sense that they query and change the info, but they won't play the song either. It does however change the default SoundCloud widget play button to a pause button. It changes the track info. But it just won't actually make any noise. If I make the widget viewable and push anything in the default player (as opposed to the custom one), it seems to work though.
I too, am facing the same issue.
It seems that Chrome for Android restricts the ability to trigger HTML5 audio playing. This is to protect users from extra data usage on their phones. It seems that triggering the audio to play from a script is not allowed.
You can read more about the issue
here
Hopefully they lift this restriction in the near future.

Play video with direct link on Android

I need to play a video with fullscreen when a user plays it.
Unfortunately, as far as I understand, if the HTML5 Video tag is used, Android plays it in-frame. So that tried webkitEnterFullScreen() and it seems to work(kind of...) but user has to click the play button again. Overall performance feels a bit clumsy and not sure if old OS like 2.0+ could handle it.
As an alternative method, I'm now trying to play video using direct link rather than the Video tag. For example, [a href="video.mp4"]Click to play[/a]. I think that it works well but the only problem is that it asks to choose a application either 'Video Player' or 'Browser'.
So my question is
How can I define using javascript to play the video using Video Player, so that the selection dialog won't prompt?.
What is the native video player for Android? For example, iOS uses Quicktime and it is possible to embed video using Quicktime object. And are there any equivalent method for Android?
When the Video tag is used, how to play video simultaneously with fullscreen?
try following code :
String path1="/path/to/video/file.3gp";
Uri uri=Uri.parse(path1);
VideoView video=(VideoView)findViewById(R.id.VideoView01);
video.setVideoURI(uri);
video.start();
You have to realize something very important: There is no native video player for android.
There is a dozens players for android and it is not your decision but the users decision if he should use player A or B. Don't try to force Android users to iOS behavior, it really doesn't give a better impression.

Playing youtube video in Android app

In my Android app I'd like the user to tap an image once, have a youtube video play automatically and when the video is done the user is immediately returned to the app. What's the best way to do this in Android?
I tried using intents. This works in that the video comes up on what I think is a youtube web page. However playing the video requires another tap. I'd like to avoid this if possible.
I tried the whole MediaPlayer, prepareAsync, setOnPreparedListener and never got it to work. For some reason onPrepared was never called. No exceptions were thrown. I'm using the emulator to test and I'm new to Android so I'm not sure if the behavior will be different on physical devices.
I got this working well on iOS by getting creative with webviews. I'm hoping it's more straightforward on Android. The docs sure make it sound straight forward.
Cheers!
Update: Everything below is still correct, but the official YouTube API for Android is now available.
By far, the easiest way to play a YouTube video on Android is to simply fire an Intent to launch the native Android YouTube app. Of course, this will fail if you are not on a certified Google device, that doesn't have the complement of Google apps. (The Kindle Fire is probably the biggest example of such a device). The problem with this approach is that the user will not automatically wind up back at your app when the video finishes; they have to press the Back button, and at this point you've probably lost them.
As a second option, you can use the MediaPlayer API to play YouTube videos. But there are three caveats with this approach:
1) You need to make a call to YouTube's GData webservice API, passing it the ID of the video. You'll get back a ton of metadata, along with it the RTSP URL that you should pass to MediaPlayer to play back an H.264-encoded stream. This is probably the reason why your attempt to use MediaPlayer failed; you probably weren't using the correct URL to stream.
2) The GData/MediaPlayer approach will only play back low-resolution content (176x144 or similar). This is a deliberate decision on the part of YouTube, to prevent theft of content. Of course, this doesn't provide a very satisfactory experience. There are back-door hacks to get higher resolution streams, but they aren't supported on all releases of Android and using them is a violation of YouTube's terms of service.
3) The RTSP streams can be blocked by some internal networks/firewalls, so this approach may not work for all users.
The third option is to embed a WebView in your application. There two approaches you can take here:
1) You can embed a Flash object and run the standard desktop Flash player for YouTube. You can even use the Javascript API to control the player, and relay events back to the native Android app. This approach works well, but unfortunately Flash is being deprecated on the Android platform, and will not work for Android 4.1 and later.
2) You can embed a <video> tag to play YouTube via HTML5. Support for this varies between various releases of Android. It works well on Android 4.0 and later; earlier releases have somewhat spotty HTML5 <video> support. So, depending upon what releases of Android your application must support, you can take a hybrid approach of embedding HTML5 on Android 4.x or later, and Flash for all earlier versions of Android.
There are several threads here on StackOverflow about using HTML5 to play YouTube video; none of them really describe the entire process you must follow in one place. Here's links to a few of them:
Android - How to play Youtube video in WebView?
How to embed a YouTube clip in a WebView on Android
Play Youtube HTML5 embedded Video in Android WebView
All of this will get dramatically easier in the weeks/months to come; at Google I/O 2012, they presented/demoed a new YouTube API for Android that will support direct embedding of YouTube content in your application, with full support back to Android 2.2 (about 95% of the Android userbase as of this writing). It can't arrive fast enough.

Categories

Resources