Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Bahi Hussien
PLUS
Bahi Hussien
Courses Plus Student 13,128 Points

Embedded Youtube video not working on WebView

My app is a simple android WebView for mobile websites. I have problem with playing youtube embedded video. It only shows blackscreen. I have also noticed that it works with some devices and many other doesn't. Here is github link for the AndroidManifest and mainactivity.java https://github.com/zulucoding/escapevelocity/ here is the full project link http://www.hus-art.com/support/escapevelocitysource/WorkSpaceforWebView.zip

3 Answers

There is a good answer to this on StackOverflow. Second answer should be what you're looking for! Find it here!

Bahi Hussien
PLUS
Bahi Hussien
Courses Plus Student 13,128 Points

Hi, Liam Peters.

I have been searching on StackOverflow for a month now. i think that there is very simple syntax error with my code but i couldn't get it.

My App setting is the same as the link you added mWebView.setHorizontalScrollBarEnabled(false); mWebView.setVerticalScrollBarEnabled(false); mWebView.setScrollbarFadingEnabled(true); mWebView.getSettings().setAllowFileAccess(true); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); mWebView.getSettings().getPluginState(); if (Build.VERSION.SDK_INT < 8) { mWebView.getSettings().setPluginsEnabled(true); } else { mWebView.getSettings().setPluginState(PluginState.ON); }

and my manifest has the application hardware accelerated true

thanks for help

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi Bahi,

I took a look at your code and nothing jumped out. Based on a little web research it sounds like this is a common problem when trying to use YouTube in a WebView. You may not like this suggestion, but your best bet would probably be to grab control of the whole experience by using the native YouTube APIs. That way you embed the video player in your app and load the content to it, which is a better user experience and more reliable than WebViews, which can have device-specific issues like this.

YouTube API: https://developers.google.com/youtube/android/player/

Bahi Hussien
Bahi Hussien
Courses Plus Student 13,128 Points

Thank you very much. I'm glad that you are teaching me