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?
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);
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
Steps
Create a new Activity, for your player(fullscreen) screen with menu options. Run the mediaplayer and UI in different threads.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With