YouTube API - Best workaround

80 views
Skip to first unread message

invide...@gmail.com

unread,
May 31, 2014, 8:05:18 AM5/31/14
to codenameone...@googlegroups.com
I am trying to integrate a YouTube player in my app.

I have learnt so far that I have to use native integration where I program the player integration separately for Android and for iOS (etc.).

For the Android part, I started to put the JAR of the YouTubePlayer API from Google into my native source directory. The CD1 builder correctly produces an APK, but I am not able to get it running.

The reason is, that the YouTubePlayer API needs the YouTubePlayerView embedded in a YouTubeBaseActivity (a class extending the Android Activity class).

And here is the problem: When I get the YouTubePlayerView out of the native part of my implementation, I am not able to build a YouTubeBaseActivity on the non-native side of my app. Is there a possibility to trick around that thing?

As I expect the answer to be "no, unfortunately not": What "workaround" would be the best, most neat, technically most robust to  achieve an embedding of YouTube videos in CD1? I need to  programmatically change videos being shown, without the native playlist functionality of the YouTube API.

I do developping in this context:
NetBeans
OS X (10.9.3)

Shai Almog

unread,
May 31, 2014, 10:53:54 AM5/31/14
to codenameone...@googlegroups.com, invide...@gmail.com
Up until now we mostly used HTML to support youtube. Chen might have an idea on that.

invide...@gmail.com

unread,
May 31, 2014, 1:27:44 PM5/31/14
to codenameone...@googlegroups.com, invide...@gmail.com
Hello Shai,

thanks for your fast response! I would love to hear thoughts about best practices - and if they are not yet existent inside of CD1, perhaps you could give me an idea how to implement a "CD1 youtube integration jar". I would put some effort in that, but I need some directions.

For my tests right now, I tried the BrowserComponent.

On a Fujitsu M532 with Android 4.0.3 I can see the preview image of a YouTube video (which looks absolutely correct). When I start the video, I can hear the audio, but the component canvas goes black. I see a pause icon in the lower left corner of the video canvas and a "do the fullscreen" icon in the lower right.

The HTML in the component is:

<!DOCTYPE html>
<html>
 
<body>
   
<iframe type="text/html" width="420" height="315" src="http://www.youtube.com/embed/5fhOz61QeoU?wmode=opaque" frameborder="0" allowfullscreen></iframe>
 
</body>
</html>

If Chen could put some thoughts in here, where to go - probably also regarding a path for the CD1 community in general -, I would be very happy.

Shai Almog

unread,
Jun 1, 2014, 2:28:39 AM6/1/14
to codenameone...@googlegroups.com, invide...@gmail.com
Hi,
according to some stack overflows this should work:
http://stackoverflow.com/questions/3458765/how-to-embed-a-youtube-clip-in-a-webview-on-android
http://stackoverflow.com/questions/5817805/how-can-we-play-youtube-embeded-code-in-an-android-application-using-webview

But I've noticed they don't have the allowfullscreen or the wmode=opaque flags. Maybe that's affecting the result.

mzie...@invidea-media.de

unread,
Jul 6, 2014, 2:39:24 PM7/6/14
to codenameone...@googlegroups.com, invide...@gmail.com
Hello Shai,

thanks for your hints so far.I tried around some things and found out that the android youtube integration is not very stable with older android versions like 4.0.3.

I have a webpage now with an iframe youtube javascript solution. I get that thing running on desktop browsers, on android browsers but when I use the sourcecode in CN1 WebBrowser component, then I just hear audio and get black video.

As other android (and non CN1 developers) also experience something like that, I wonder if you could tell me if the following things are considered inside CN1 (see the answer with baseURL and WebChromeClient):


Do you know about these issues and can we manipulate something like these things inside of CN1?

Thanks and regards,

+manuel-

Shai Almog

unread,
Jul 7, 2014, 1:34:38 AM7/7/14
to codenameone...@googlegroups.com, invide...@gmail.com, mzie...@invidea-media.de
Hi,
I assume you mean the lower ranked answer about hardware acceleration?
Right now its off by default for compatibility but you can use the build argument android.asyncPaint=true which should enable that.
Reply all
Reply to author
Forward
0 new messages