1

I have a list of videos on my Android TV app. When I attempt to play a video, the YouTube Player is suppose to pop up and play. However, the player crashes just before it tries to play a video.

The crash happens so quickly that I dont get to see the player in view before the app crashes to my main video page.

Can someone give me some insight into this?

Here's pretty much the only simple code I have:

public class MainActivity extends Activity
{
    private static final String VIDEO_ID = "fhWaJi1Hsfo";
    private static final String TAG = "MyActivity";

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intentStartYoutube =
                YouTubeIntents.createPlayVideoIntent(getApplicationContext(), VIDEO_ID);
        startActivity(intentStartYoutube);
    }

    ....
}

FYI, the manifest file already contains the permissions <uses-permission android:name="android.permission.INTERNET" />.

UPDATE Logcat:

FATAL EXCEPTION: main
Process: com.example.vietmytv_androidtv, PID: 20663
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vietmytv_androidtv/com.example.vietmytv_androidtv.ui.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.youtube.com/watch?v=fhWaJi1Hsfo pkg=com.google.android.youtube (has extras) }
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.youtube.com/watch?v=fhWaJi1Hsfo pkg=com.google.android.youtube (has extras) }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1781)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
    at android.app.Activity.startActivityForResult(Activity.java:3745)
    at android.app.Activity.startActivityForResult(Activity.java:3706)
    at android.app.Activity.startActivity(Activity.java:4016)
    at android.app.Activity.startActivity(Activity.java:3984)
    at com.ui.MainActivity.onCreate(MainActivity.java:54)
    at android.app.Activity.performCreate(Activity.java:5990)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
    at android.app.ActivityThread.access$800(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5257) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372

I was following this tutorial: http://android-coding.blogspot.com/2013/04/create-intent-to-specified-video-or.html

Pangu
  • 3,721
  • 11
  • 53
  • 120

1 Answers1

3

YouTube on mobile is not the same as YouTube on Android TV. As such, it's probably trying to open an app that doesn't exist. Can you post a crash log?

As a workaround, you can interact with the YT for ATV app by using an intent linking you to the YouTube URL. When you start that, YouTube will see the link and opens up the app to the video.

public void OpenYT() {
    Intent youtube = new Intent();
    youtube.setAction(Intent.ACTION_VIEW);
    youtube.setData(Uri.parse("http://youtube.com/watch?v=dQw4w9WgXcQ"));
    getActivity().startActivity(youtube);
}
Nick Felker
  • 11,536
  • 1
  • 21
  • 35
  • That does work, but why does the code I use crash? I'd like to play the youtube video within my own app instead of having to play it through the ATV YouTube, is this possible?....I updated the logcat. – Pangu Jul 02 '16 at 19:23
  • Your app is trying to access the YouTube app but that doesn't exist. Android TV has a separate "YouTube for Android TV" app with a different package name. You can look at using an embedded WebView and YouTube's iframe APIs to play videos inside the app. – Nick Felker Jul 03 '16 at 06:36
  • @Pangu check [this answer](https://stackoverflow.com/a/41744544/2614364) – Bertrand Martel Jul 18 '17 at 07:53