ThAlKa
ThAlKa

Reputation: 31

YouTube android API and buffer infrormation (getVideoLoadedFraction)

It would be very interesting for me to have the methods below available for the Youtube Android API:

player.getVideoLoadedFraction():Float

As I can see in the YouTube player API for Javascript (iframe) these methods are included.

These methods are very useful to get the statistics of the buffer while a video is being played

Has anyone figured out a way to include these methods in the Youtube android api as well?

Upvotes: 2

Views: 367

Answers (1)

SPYFF
SPYFF

Reputation: 131

As far as I know there is no way to do that (maybe with reflection you are able to hack out some relevant information but you have to reverse engineer of the obfuscated code for that).

I tried a simple workaround for that result:

  1. Simple WebView in android, which navigates to a prepared website just after on program load: that contains a iframe youtube player. I saved that little html file to the app's assets.
  2. Next you have to create some Java-Javascript binding if you want to handle events like onStart, onStop in Java code.
  3. If you only want to control the player from Java code, you have to call Javascript methods from the Java code, with the evaluateJavascript() method, which takes a String argument that pass to the called Javascript method. After the Javascript method completed his job, you are able to pass the result (in string format) to the Java caller.

More: https://developer.android.com/guide/webapps/webview.html

With these technics, you are able to calculate the buffer size in seconds for example: (VideoLoadedFraction - (current_time / video_length) * 100) / 100) * video_length or something like that. Then you pass back the result from Javascript as a string and parse it to float or double in Java.

Upvotes: 1

Related Questions