public class abc extends Activity implements OnPreparedListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
}
}
}
Intent videoClient = new Intent(Intent.ACTION_VIEW);
videoClient.setData("VALID YOUTUBE LINK WITH HTTP");
videoClient.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
startActivity(videoClient);
/**
* Intent to open a YouTube Video
*
* @param pm
* The {@link PackageManager}.
* @param url
* The URL or YouTube video ID.
* @return the intent to open the YouTube app or Web Browser to play the video
*/
public static Intent newYouTubeIntent(PackageManager pm, String url) {
Intent intent;
if (url.length() == 11) {
// youtube video id
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + url));
} else {
// url to video
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}
try {
if (pm.getPackageInfo("com.google.android.youtube", 0) != null) {
intent.setPackage("com.google.android.youtube");
}
} catch (NameNotFoundException e) {
}
return intent;
}
public void playVideo(String key){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + key));
// Check if the youtube app exists on the device
if (intent.resolveActivity(getPackageManager()) == null) {
// If the youtube app doesn't exist, then use the browser
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=" + key));
}
startActivity(intent);
}
Uri uri = Uri.parse( "https://www.youtube.com/watch?v=bESGLojNYSo" );
uri = Uri.parse( "vnd.youtube:" + uri.getQueryParameter( "v" ) );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );