How to play YouTube video via Intent? - android

In my app I want to click on a particular button and jump to the youtube app and show a youtube user .Eg http://www.youtube.com/user/punjabiradiousa . How is this possible please suggest some technique?

Do it like this:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/user/punjabiradiousa")));
Taken from here: Android YouTube app Play Video Intent

This code i have used to play youtube video
Matcher matcher = Pattern.compile("http://www.youtube.com/embed/").matcher(mVideoId);
matcher.find()
Intent lVideoIntent = new Intent(
null,
Uri.parse("ytv://" + mVideoId),
MainScreen.mContext,
com.kids.youtube.OpenYouTubePlayerActivity.class);
startActivity(lVideoIntent);

Its Working
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("")));

Related

How to implement soundcloud share button

How can i implement share button of soundcloud which share a link of audio track and when user click on it open this track with soundcloud application.
I searched but i didn't find any thing all of them share audio or image or text or application, so any help of how can i do that.
Thanks in advance.
See this for adding sound from Soundcloud app.
See this for accessing Soundcloud to play song in Soundcloud
This code from enadun may help:
String id = "114143409"; //Track id
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("soundcloud://sounds:" + id));
startActivity(intent);

Android intent to enter a search query for google play music app

Hello i am trying to automatically fill the search bar on Google Play Music with a String that my app provides. I currently have the intent to open Google Play Music, but I have not been able to find the right params to fill the search bar on Google Play Music.
Here is my code
Intent intent = getApplicationContext().getPackageManager()
.getLaunchIntentForPackage("com.google.android.music");
startActivity(intent);
Would anyone know the right intent? Thanks in advance
I found the answer to my question.
The documentation can be found here.
I had to choose google play music as my default music player, but after that was done the songs were searched for/played automatically with the following code.
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, track.getArtistName());
intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, track.getName());
intent.putExtra(SearchManager.QUERY, track.getName());
startActivity(intent);
Below is the working code to play a song with given title.
String title = "Iridescent";
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,
MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE,title);
intent.putExtra(SearchManager.QUERY,title);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}

Play youtube video from URL in android

I want to play youtube video in my application. I am getting video URL from SAX Parsing. My question is how to play video from URL in VideoView, not in Webview or Browser.
I tried this code :
Intent lVideoIntent = new Intent(null, Uri.parse("VIDEO URL"));
startActivity(lVideoIntent);
It is displaying one popup screen with 'Internet' and 'YouTube' options. I want to play the video directly in youtube.
Please let me know your thoughts. Any code or any example is highly appreciated.
you can try below code for direct play in Youtube application.
Intent videoClient = new Intent(Intent.ACTION_VIEW);
videoClient.setData(Uri.parse("https://www.youtube.com/watch?v=EwSdmxyayx0&feature=youtube_gdata"));//you can try here your own video url
videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.PlayerActivity");
try{
startActivity(videoClient);
}catch(ActivityNotFoundException excp){
try{
videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
startActivity(videoClient);
}catch(ActivityNotFoundException exc){
exc.printStackTrace();
}
}
String videoUrl = "http://www.youtube.com/watch?v=cxLG2wtE7TM"
//split video url and get value of v ie cxLG2wtE7TM
String videoId = "cxLG2wtE7TM";
String action = Intent.ACTION_VIEW;
Uri uri = Uri.parse("vnd.youtube:" + videoId);
Intent videoIntent = new Intent(action, uri);
startActivity(videoIntent);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("video url"));
VideoActivity.this.startActivity(i);
It is displaying one popup screen with 'Internet' and 'YouTube'
because the ACTION_VIEW intent is written both in default browser and Youtube application. that's why whenever it catches the URL the Browser opens and whenever the Youtube URL is opened Both the browser and Youtube app.
I want to play the video directly in youtube
Take the embed link of Youtube video and set intent it will play the video.
ex:-http://www.youtube.com/embed/srMFb6zpx2Y

Android: Youtube Search Application for given Word

I want to create a android search application that can be used to search a video from youtube for given word.
how do I do that. please someone give me a tutorial link. Thanks
Please try the below code .
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
use this API for Searching a Video on Youtube
https://gdata.youtube.com/feeds/api/videos?q=india
where q is word you want to search related videos
for more detail see YouTube APIs

how to embed Video from Live website in Android app

here is a link!
This link has Video and i want to display only video in my Android app. I think this website haven't provided any xml service so that we can use it, Is there any way to show only Video from this link to android app.
Thanks
hii ali you want to play video in your android app it can be do by two ways .
you can use your default youtube app to play the video or you can play it in your browser by following way.
if (isAppInstalled("com.google.android.youtube")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse("vnd.youtube://" + b.getString("video")));
startActivity(intent);
finish();
} else {
// Toast.makeText(this,
// "To view this Video you must install the youtube application in your device..",
// Toast.LENGTH_SHORT).show();
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("http://m.youtube.com/watch?v="
+ b.getString("video"))));
finish();
}
It worked for me
If it worked please vote

Categories

Resources