I want to open youtube videos in a webview. In a webview I go to the page of a video in youtube and when I try to play the video, it doesnot start. Is it possible to play youtube videos in a webview? If it is not, how can I direct my application to open the video with native media player of the phone.
Asked
Active
Viewed 895 times
-1
-
take a look at this SO post. http://stackoverflow.com/questions/2292086/play-youtube-video-in-webview – Orlymee Jul 06 '12 at 10:58
1 Answers
0
Try with this code:
myWebView = (WebView) findViewById( R.id.webview);
String playVideo= "<html><body>Youtube video .. <br> <iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/bIPcobKMB94\" frameborder=\"0\"></body></html>";
myWebView.loadData(playVideo, "text/html", "utf-8");
And yes dont forget to add permission into your manifest:
<uses-permission android:name="android.permission.INTERNET"/>
I hope this will help you.

AkashG
- 7,868
- 3
- 28
- 43
-
Thank you, I think it's gonna help, I just should find how to trigger this when the video is clicked. – user1488918 Jul 06 '12 at 11:48
-
loadData on click event will help you to trigger this when the video is clicked – AkashG Jul 06 '12 at 11:52
-
@AkasG this helped me alot. Thank you. By the way is it possible to get the video id when i click on it in webview and then use this method to play the video? – Adnan Zahid Aug 17 '12 at 03:59
-
-
Try this link http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url – AkashG Aug 17 '12 at 04:29