2016-06-30 17 views
1

Ich habe eine Liste von Videos auf meiner Android TV App. Wenn ich versuche, ein Video abzuspielen, wird der YouTube Player eingeblendet und abgespielt. Der Player stürzt jedoch kurz vor dem Versuch ab, ein Video abzuspielen.Warum stürzt Android TV YouTube Player ab, wenn ich versuche, ein Video in meiner App abzuspielen?

Der Absturz geschieht so schnell, dass ich den Player nicht sehen kann, bevor die App auf meine Hauptvideoseite abstürzt.

Kann mir jemand einen Einblick geben?

Hier ist so ziemlich der einzige einfache Code, den ich habe:

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, die Manifest-Datei enthält bereits die Berechtigungen <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 

ich dieses Tutorial folgenden wurde: http://android-coding.blogspot.com/2013/04/create-intent-to-specified-video-or.html

+0

und sehen Sie irgendwelche Absturzprotokolle? –

+0

@Vlad, das kann nicht auf einem Simulator getestet werden, so dass kein Absturz protokolliert – Pangu

+0

Und warum kann es nicht sein? –

Antwort

3

YouTube auf Mobil ist nicht das gleiche wie YouTube auf Android TV. Als solches versucht es wahrscheinlich, eine App zu öffnen, die nicht existiert. Kannst du ein Absturzprotokoll posten?

Als Workaround können Sie mit der YT for ATV-App interagieren, indem Sie eine Absicht verwenden, die Sie mit der YouTube-URL verknüpft. Wenn du damit beginnst, sieht YouTube den Link und öffnet die App für das 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); 
} 
+0

Das funktioniert, aber warum stürzt der Code, den ich benutze, ab? Ich möchte das Youtube-Video in meiner eigenen App spielen, anstatt es über das ATV YouTube spielen zu müssen, ist das möglich? .... Ich habe den Logcat aktualisiert. – Pangu

+0

Ihre App versucht, auf die YouTube App zuzugreifen, diese existiert jedoch nicht. Android TV verfügt über eine separate App "YouTube für Android TV" mit einem anderen Paketnamen. Sie können mithilfe eingebetteter WebView- und YouTube-Iframe-APIs Videos in der App wiedergeben. –

+0

@Pangu überprüfen [diese Antwort] (https://Stackoverflow.com/a/41744544/2614364) –