Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play YouTube video in my Android application?

Tags:

android

How do I play YouTube videos in my application? I want to play video by streaming it directly from YouTube without downloading. Also, while playing videos, I want provide menu options. I don't want to play video using default intent. How can I do this?

like image 367
user446366 Avatar asked Jan 11 '11 06:01

user446366


People also ask

Can I use YouTube videos in my Android app?

You can play youtube videos in the app itself using android-youtube-player. Intent intent = new Intent(null, Uri. parse("ytv://"+v), this, OpenYouTubePlayerActivity. class); startActivity(intent);


2 Answers

This is the btn click event

btnvideo.setOnClickListener(new OnClickListener() {  public void onClick(View v) {      startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=Hxy8BZGQ5Jo")));     Log.i("Video", "Video Playing....");      } });  

this type it opened in another page with the youtube where u can show your video

like image 113
Parag Chauhan Avatar answered Sep 29 '22 12:09

Parag Chauhan


Steps

  1. Create a new Activity, for your player(fullscreen) screen with menu options. Run the mediaplayer and UI in different threads.

  2. For playing media - In general to play audio/video there is mediaplayer api in android. FILE_PATH is the path of file - may be url(youtube) stream or local file path

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

Also check: Android YouTube app Play Video Intent have already discussed this in detail.

like image 38
Naresh Avatar answered Sep 29 '22 12:09

Naresh