Embedding a youtube video into android app using eclipse? - android

I'm trying to figure out how to embed youtube videos into android using eclipse. I would prefer to use the chromeless player, but at this point it's not necessary.
Any help on how to do this would be greatly appreciated.

The easiest way to embed a Youtube video is to use an intent to fire the Youtube application, like this:
String video_path = "http://www.youtube.com/watch?v=opZ69P-0Jbc";
Uri uri = Uri.parse(video_path);
// With this line the Youtube application, if installed, will launch immediately.
// Without it you will be prompted with a list of the application to choose.
uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

YouTube API for Android is availible now. Following this link, you will find a sample how to use YouTube API under Android.
Using YouTubePlayerView you can play video from youtube in your activity. But it is not possible to change default controls.

If you want to play the video from inside the application to really embed it you can use WebView and load it with just iframe of that youtube video.
WebView webview;
webview.getSettings().setJavaScriptEnabled(true);
webview.loadData("<iframe src=\"http://www.youtube.com/watch?v=hZ4sDn89P04\"></iframe>","text/html","utf-8");

Related

Android playing videos based on url

I got a problem related to playing videos based on Url i get. I made 2 cases, but each one has its problem.
1) using android VideoView
videoPlayer.setVideoURI(Uri.parse(videoUrl));
videoPlayer.setMediaController(new MediaController(this));
videoPlayer.requestFocus();
videoPlayer.start();
The problem is that it doesn't open such types of video url
https://www.facebook.com/zloishkolnik/videos/462625797256094/
https://www.youtube.com/watch?v=YVkUvmDQ3HY
2) using android WebView
videoPlayer.setWebViewClient(new WebViewClient());
videoPlayer.getSettings().setJavaScriptEnabled(true);
videoPlayer.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
videoPlayer.getSettings().setPluginState(WebSettings.PluginState.ON);
videoPlayer.setWebChromeClient(new WebChromeClient());
videoPlayer.loadUrl(videoUrl);
Webview opens the links above, but doesnt open such type of links
http://www.db.cartosnet.com/videos/EU5beThfNI.mp4
Am i doing something wrong or there is any library that reads any video url given?
To play videos through your way (setting a url to Videoview), your endpoint must be the video as itself. Example of a valid endpoint: https://ia600404.us.archive.org/1/items/popeye_patriotic_popeye/popeye_patriotic_popeye_512kb.mp4
If you want to play videos, in your case, embedded videos, you should use a API (like Youtube, Facebook...)

How to make it so it asks you what video player you'd like to use when trying to play a video in a Web View?

I'm trying to make it so when you try to play a video in a web view it asks you what video player you'd like to use. Such as MX Player, or the default video player in android. I'm trying to do that so you don't have to play it inside the web view. If you could help me that'd be great!
You don't have to do anything, android handles this. Android finds all relevant video player applications and shows a choice dialog to user.
You can try with this code(put a movieUrl, maybe it is stored in your sd card):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
startActivity(intent);
What I did was just make it play the video inside the web view. Thanks a lot though guys.

play youtube video in full screen mode in my android app

I am using the following code to play youtube videos in my app.
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=videoid")));
I would like the youtube videos to open in full screen mode. Is there any way to achieve this?
Found this solution today:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=VIDEOID"));
intent.putExtra("force_fullscreen",true);
startActivity(intent);
Try using
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + video_id);
startActivity(intent);
The reason is the different Uri. The one you are currently using is just supplying content via http: that happens to be video and get's resolved to youtube. The one with "vnd.youtube" is actually telling the system that you have video content you would like one of the native apps to take care of.
Ahh, if you want to actually play full screen video without using the youtube app (which you can not control) you don't you try to just make your own VideoView?
Check out this link
playback video full screen
Although I failed at this initially, I eventually succeeded by following the instructions at this linkc
http://keyeslabs.com/joomla/projects/youtube-player/244-open-youtube-activity-project-launched-by-keyes-labs
Here you create your own video player and the video gets played in it

Play Video by staying in the same Activity

I have referred the answers of
android-youtube-app-play-video-intent
how-to-play-youtube-video-in-my-android-application
and many more.All those are playing videos by using Intent which creates a new Window and to be more precise by creating a new Activity.
But,I am having a scenario in which I want to play a Video on click of a Button by staying in the same Activity
refer this video tutorial:
http://mfarhan133.wordpress.com/2010/10/13/using-audio-video-files-tutorial-for-android/
Use a VideoView
http://developer.android.com/reference/android/widget/VideoView.html
If you want to play a video file from phone storage or streaming, you can use VideoView.
If you want to open youtube video, you can use a WebView in your activity and open the youtube link.
See this WebView Tutorial.

How to open my custom video player when i click a you-tube link in android?

I have installed a video player in my Android box. Currently i am not able to play the you-tube videos in my browser. So i would like to open my player when the user clicks a you-tube link. Then the video will be played in my browser.
Please guide me with some pointers on how i can do this?
You can use this code on your click on code:
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));// url is your URL for YouTube video
view.getContext().startActivity(intent);

Categories

Resources