我在安卓电视应用程序上有一个视频列表。当我试图播放视频时,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);
}
....
}
仅供参考,manifest文件已经包含权限<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
手机上的YouTube与Android电视上的YouTube不一样。因此,它可能试图打开一个不存在的应用程序。你能发布崩溃日志吗?
作为一种变通方法,你可以通过使用一个链接到YouTube URL的意图来与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);
}