我的Android TV应用上有一个视频列表。当我尝试播放视频时,YouTube播放器会弹出并播放。但是,播放器在尝试播放视频之前就崩溃了。
崩溃发生的速度非常快,以至于在应用程序崩溃到主视频页面之前我无法看到播放器。
有人可以给我一些见解吗?
这几乎是我唯一的简单代码:
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);
}
....
}
仅供参考,清单文件已包含权限<uses-permission android:name="android.permission.INTERNET" />
。
更新 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
我正在学习本教程:http://android-coding.blogspot.com/2013/04/create-intent-to-specified-video-or.html
答案 0 :(得分:3)
移动版YouTube与Android TV上的YouTube不同。因此,它可能试图打开一个不存在的应用程序。你可以发布崩溃日志吗?
作为解决方法,您可以使用将您链接到YouTube网址的意图与YT for ATV应用互动。当您启动时,YouTube会看到该链接并打开该视频的应用。
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);
}