0

I've got the new YouTube Player API for Android working on a Nexus 4 without much problems. Now I'd like to combine this with the multi-screen API that comes in Android 4.2 (i.e. Presentation and MediaRouter class).

However, it doesn't seem to be possible to combine this as the YouTubePlayerView needs to be initialized with context that has extended YouTubeBaseActivity. Since the Context instance you get in the Presentation class that draws on the remote screen doesn't extend this I can't instantiate a new YouTubePlayerView or any other class that requires a YouTubeBaseActivity as its constructor parameter.

This makes it impossible for me to show a YouTube player on a secondary screen using the new APIs in Andorid 4.2.

Any workaround for this or plans to release an updated API that supports Android 4.2 and the new multi-screen API?

Thanks, Erik

Erik Hellman
  • 529
  • 4
  • 11

1 Answers1

0

Disregard everything written in small characters in this post. I don't know anything about the Android API...

Here is something I think is possible but that I haven't tried so I'm not sure it will work.

Disclaimer: I'm a Java developer but have never developed an Android app. Take everything I say with a pinch of salt.

Try to create your own class that extends the YouTubeBaseActivity class, and also wraps the Context instance retrieved from the Presentation class. So you'd have a final "wrappedContext" field of type Context, and in the constructor you'd have a Context parameter that initializes this field.

Then you define/overload every needed method (abstract methods of all the superclasses and maybe some non-abstract ones) by calling the wrapped object's methods when possible.

Let me know if you manage to do that. I'm very interested because since I bought my Nexus 4 and a SlimPort adapter, I've been wondering if mirroring was the only possibility or if it was possible to display something else on the secondary display, and if the resolution could be higher than 1280x768 on the secondary display. I haven't seen any app using the new 4.2 API for multiple displays yet...

Edit: The wrapped Context can probably be non-final and there can be a setter (setWrappedContext) too.

Edit2: Actually there is already a wrapped Context in every Activity object (see ContextWrapper) and ContextWrapper also extends Context.

So I don't really know what you are supposed to do here. Maybe it's indeed impossible...

Edit3: Maybe this page can help if you haven't read it yet.

Edit4: Have you tried using YouTubePlayerFragment instead of YouTubePlayerView? It seems it could help as you don't need to extend YouTubeBaseActivity then...

Floflo
  • 31
  • 3