0

I want to play YouTube videos in my application. I already tried following code: but this shows a complete action using YouTube but I don't want this. I would like to play videos directly. How can I achieve this?

context.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=CUuBdtsQx6U"))); 
Kirk
  • 4,957
  • 2
  • 32
  • 59

2 Answers2

0

You can create your own Activity and MediaPlayer to play the video, like :

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(FILE_PATH);
mp.prepare();
mp.start();

FILE_PATH is the path of file - may be url(youtube) stream or local file path.

Or else open the webview in your application:

WebView webview = new WebView(this); 

String htmlString = "<html> <body> <embed src=\"youtube link\"; type=application/x-shockwave-flash width="+widthOfDevice+" height="+heightOfDevice+"> </embed> </body> </html>";

webview.loadData(htmlString ,"text/html", "UTF-8");

Hope this helps !!!

Shraddha
  • 1,052
  • 11
  • 22
0

You've to use the Youtube Player API, and play it in VideoView.

Check out this SO Post . It works correctly.

Community
  • 1
  • 1
sanjeev mk
  • 4,276
  • 6
  • 44
  • 69