0

I need to play some videos in my application. I am using the following bit code for the same:

vid="0ee3R3tfdd4"; //the video id of the youtube video
url="vnd.youtube:"+vid;
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

The video works well on a normal device. However, it gives "Activity not found" exception on an emulator. I think the reason being that youtube app may not be installed on the emulator.

I would like to know:

  1. Can this be a problem on an actual device. I have seen that every device has a youtube app
  2. How to ensure that the app works well on a device irrespective of whether youtube is installed or not.
RivieraKid
  • 5,923
  • 4
  • 38
  • 47
ambit
  • 1,099
  • 2
  • 28
  • 43
  • Emulator has not inbuilt youtube application installed. Check whether Youtube is installed on device or not if not ask user to install it with start market application using intent with youtube app uri. – user370305 May 17 '12 at 06:43
  • have you defined activity in AndroidManifest.xml ? – Lucifer May 17 '12 at 06:46
  • @user370305, Can i check it programatically whether youtube is installed on device and ask the user to install it if not done?..Thanks.. – ambit May 17 '12 at 06:50
  • @Lucifer, The activity is defined in the manifest file.. Thanks.. – ambit May 17 '12 at 06:50
  • 1
    Yes, you can using Intent and package manager.. – user370305 May 17 '12 at 06:52
  • 1
    Look at these SO questions [Download app if intent not installed](http://stackoverflow.com/questions/4240077/download-app-if-intent-not-installed) and [how to download adobe reader programatically if not exists](http://stackoverflow.com/questions/9480045/how-to-download-adobe-reader-programatically-if-not-exists) – user370305 May 17 '12 at 06:54

1 Answers1

0

You can run this video in two ways.

using YouTube app:

try {   
   vid="0ee3R3tfdd4"; //the video id of the youtube video
   url="vnd.youtube:"+vid;
   startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch(ActivityNotFoundExcepiton e) {
   Toast.makeText(this, "Plase install Youtube before running the app", Toast.LENGTH_SHORT).show();
}

or you can use YouTube Data API to get the video url by using id and you can play video

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
Krishna Prasad
  • 693
  • 1
  • 6
  • 19