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
Related
I'm developing an android app and I wanted to do something like that:
I have simple button and when I press it, the android native player pops with video up
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(Path to video file);
intent.setDataAndType(data, "video/mp4");
startActivity(intent);
use this if you don't want to use videoview
I try to play a mp4 video from url sending the video intent - intent.setDataAndType(pathuri, "video/*"); but I get the dialog Can't play the video due to android network error.I have the internet permission in manifest file and the url of the video is good.Also I cant play the video in my app using videoview for video urls. Please help.
Intent in=new Intent();
Uri vidUri = Uri.parse(feedob);
in.setDataAndType(vidUri, "video/*");
Log.e(TAG, "On CLICK, VIDEO URL " + feedob);
startActivity(in);
Now the feedob is https://scontent.cdninstagram.com/t50.2886-16/12796233_1731088863793436_102464613_n.mp4
The process is not allowed to run in the main thread, so you need a second one. Would be helpfull if you post the code + error log
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("")));
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
I've written a small app to parse some RSS feeds from YouTube and launch videos selected by the user. To play the video, I'm using an intent:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(videoAddress);
In order to call the YouTube app, if installed on the device.
The problem I'm having is that, of the population of videos I am using in my app, about 90% of them display a 'Cannot play video' error message: "Sorry, this video cannot be played.". A few of them work just fine from my app. The videos that do not work will play fine in the YouTube app if searched for and launched entirely from within the YouTube app.
Has anybody seen this behavior, or does anybody have any ideas for things to try? Obviously the YouTube app launches videos in a slightly different way internally than it does from an Intent request, but I haven't a clue how to get to the bottom of it.
I have the same issue. Are you sure that all of the video play correctly from the youtube app? In my case, on an old G1, the videos I can't play from my app won't play even if searched from within the youtube app.
I think the video encoding is not supported in some case and/or the combination of a slow cpu and slow network make the video not playable.
I've read about people just refreshing many times untill the video starts playing... I guess in thier care it was a network/buffering issue.
More discussion here:
http://www.google.com.tw/support/forum/p/android/thread?tid=3a62cdf7188384af&hl=en
For this reason my App (similar to yours) got a lot of bed comments. I republished it only for Android >=2.1 and I now I have fewer bad feedback.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(YOUTUBE_URL)));
The above line of code works for my App.
What it basically does is lets Android handle the startActivity with available installed software on the device. Android in turn opens the IntentChooser and lets the user decide which appropriate software to use in this case a Browser and Youtube App to open the video.
Try it out and let me knwo if it works for you or f you have any other issues.
The most reliable method I have found for accessing youtube from an application is using the mobile site, try this instead (eg for searching):
String videoUrl = "http://m.youtube.com/#/results?q=ciaconna+bach";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(videoUrl)));
This solved the "Cannot play video' error message" that I was receiving.
I use this code:
String vid= Uri.parse(urlVideo).getQueryParameter("v");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + vid));
try{
startActivity(intent);
}
catch (ActivityNotFoundException ex){
Log.e(TAG, "Couldn't find activity to view this video");
}
May be works for you.
I have got the same problem only with HTC Hero 2.1. You can force the intent to launch the htc flash player instead of the Youtube app. With the flash player app I have not had any problem:
Uri uri = Uri.parse("vnd.youtube:" + videoUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
String availableFlashPlayer = availableFlashPlayer();
if (availableFlashPlayer != null) {
// launch the intent with the available flash player
intent.setPackage(availableFlashPlayer);
}
startActivity(intent);
The availableFlashPlayer method:
public String availableFlashPlayer() {
String availableFlashPlayer = null;
String FLASH_PLAYER = "com.htc.flash";
PackageManager pm = getPackageManager();
try {
ApplicationInfo ai = pm
.getApplicationInfo(FLASH_PLAYER, 0);
if (ai != null) {
availableFlashPlayer = FLASH_PLAYER;
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
return availableFlashPlayer;
}
You can also check the Adobe Flash Player:
String FLASH_PLAYER = "com.adobe.flashplayer";
Alternatively, you can force the intent to launch the Android Browser as follows:
Uri uri = Uri.parse(videoUrl);
String packageName = "com.android.browser";
String className = "com.android.browser.BrowserActivity";
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setClassName(packageName, className);
startActivity(intent);