7

I am getting ActivityNotFoundException error when i am trying to run youtube api StandAlonePlayerActivity on ginger bread. Where as it runs fine on ICS

here is my log cat

01-23 15:34:28.071: E/AndroidRuntime(3378): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.android.youtube.api.StandalonePlayerActivity.START (has extras) }
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1515)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.Activity.startActivityForResult(Activity.java:2988)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:701)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.support.v4.app.Fragment.startActivity(Fragment.java:787)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at com.example.demo.TipsFragment$2.onClick(TipsFragment.java:143)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.view.View.performClick(View.java:2533)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.view.View$PerformClick.run(View.java:9320)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.os.Handler.handleCallback(Handler.java:587)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.os.Looper.loop(Looper.java:150)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.ActivityThread.main(ActivityThread.java:4389)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at java.lang.reflect.Method.invokeNative(Native Method)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at java.lang.reflect.Method.invoke(Method.java:507)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at dalvik.system.NativeStart.main(Native Method)

and here is the code which i have used for starting Player

String vid=getYoutubeVideoId(vlink);
Intent intent=YouTubeStandalonePlayer.createVideoIntent(getActivity(),DEVELOPER_KEY, vid, 0,true,false);
startActivity(intent);

I am getting error on startActivity

Here is getYoutubeVideoID() code :

/*
     * Getting id of video from url
     */
    public static String getYoutubeVideoId(String youtubeUrl)
    {
        String video_id="";
        if (youtubeUrl != null && youtubeUrl.trim().length() > 0 && youtubeUrl.startsWith("http"))
        {

            String expression = "^.*((youtu.be"+ "\\/)" + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; // var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
            CharSequence input = youtubeUrl;
            Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);
            Matcher matcher = pattern.matcher(input);
            if (matcher.matches())
            {
                String groupIndex1 = matcher.group(7);
                if(groupIndex1!=null && groupIndex1.length()==11)
                    video_id = groupIndex1;
            }
        }
        return video_id;
    }
Manoj
  • 2,799
  • 5
  • 30
  • 49
  • 1
    do u got developer key ?? Can you give me the id of video you are using?? Post the code of getYoutubeVideoId(vlink); – edwin Jan 23 '13 at 10:35
  • @edwin yes i have developer key. I mentioned in my question that its running on ICS. I have tried with SimplePlayerView From youtube api – Manoj Jan 23 '13 at 10:44

6 Answers6

19

First check if the youtube service is available on your device, then try to launch that activity. YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(mContext). Also try installing the youtube app from Google play.

Tiny note from the documentation: Note: Users need to run version 4.2.16 of the mobile YouTube app (or higher) to use the API.

Edit: This is how you use it:

if(YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(mContext).equals(YouTubeInitializationResult.SUCCESS)){
   //This means that your device has the Youtube API Service (the app) and you are safe to launch it. 

}else{
   // Log the outcome, take necessary measure, like playing the video in webview :)  
}

See the YouTubeInitializationResult enums here https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeInitializationResult

Also the philosophy about the aforementioned class: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeApiServiceUtil

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • can you paste a snippet for YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(Context context) – Manoj Jan 23 '13 at 11:05
1

The devices should have the latest YouTube app installed.

tasomaniac
  • 10,234
  • 6
  • 52
  • 84
0

Are you running the app on the emulator? It might not work on the emulator as youtube player is not installed by default. Try running it on an actual device.

Rajitha Siriwardena
  • 2,749
  • 1
  • 18
  • 22
0

In order to use YouTube api for android you need 3 Parameters

1) YouTube Developer Key

2)Video Id

3)Latest official YouTube Android App (version 4.2.16)

By looking on you log cat i think one among this is missing

Refer

Community
  • 1
  • 1
edwin
  • 7,985
  • 10
  • 51
  • 82
  • its running fine on Ics. I have downloaded Latest version of youtube api from [here](https://developers.google.com/youtube/android/player/downloads/) – Manoj Jan 23 '13 at 10:38
  • 1
    ok, i tested the demo app on Android 2.1 ,it works fine for me .. youtube api need latest version of youtube official app for playing video . is your youtube app in phone is latest version ? – edwin Jan 23 '13 at 10:45
0

you have to install YouTube Android App on your device, it's worked for me !

AHmedRef
  • 2,555
  • 12
  • 43
  • 75
0

I would suggest some improvements to @Nikola answer. It's possible to show localised dialog getErrorDialog() to handle some user-recoverable errors isUserRecoverableError. For example, when YouTube app is disabled in Settings.

val result = YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(context)
when {
    result == YouTubeInitializationResult.SUCCESS -> startYouTubeActivity()
    result.isUserRecoverableError -> result.getErrorDialog(activity, 0).show()
    else -> toast("Something went wrong!")
}
Artem
  • 896
  • 1
  • 11
  • 16