5

我有以下代码来查看远程托管的视频文件:

startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(article.getLink())));

wheregetLink()返回与文章关联的视频的 URL。

这种方法在直到 Gingerbread 的设备上运行良好,但我最近一直在 ICS 上测试该应用程序并发现了一个问题。ICS 浏览器开始加载 URL,我在导航栏中看到它,但随后浏览器几乎立即关闭,我又回到了我的应用程序的活动中。

当它发生时,我得到以下堆栈跟踪:

11-28 10:24:44.488: E/SurfaceTexture(116): [com.mypackage.myapp/com.mypackage.myapp.MyVideoActivity] connect: already connected (cur=2, req=2)
11-28 10:24:44.488: E/ViewRootImpl(25384): IllegalArgumentException locking surface
11-28 10:24:44.488: E/ViewRootImpl(25384): java.lang.IllegalArgumentException
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.Surface.lockCanvasNative(Native Method)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.Surface.lockCanvas(Surface.java:76)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.ViewRootImpl.draw(ViewRootImpl.java:1924)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1613)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.os.Looper.loop(Looper.java:137)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at android.app.ActivityThread.main(ActivityThread.java:4340)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at java.lang.reflect.Method.invokeNative(Native Method)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at java.lang.reflect.Method.invoke(Method.java:511)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-28 10:24:44.488: E/ViewRootImpl(25384):  at dalvik.system.NativeStart.main(Native Method)

有没有其他人看到这种行为/知道修复?

4

2 回答 2

5

我尝试了一些事情,发现在意图工作中明确设置数据的数据类型。

Intent videoIntent =new Intent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(Uri.parse(article.getLink()), "video/*");
startActivity(videoIntent);

注意:我在 Gingerbread 2.3.6 中也遇到了类似的错误。

于 2011-12-02T13:58:41.710 回答
0

没有看到这一点,但解决方法可能是显式调用 youtube 应用程序(如果已安装)而不是让浏览器处理它。

/**
 * @param context
 * @param url To display, such as http://www.youtube.com/watch?v=t_c6K1AnxAU
 * @return an Intent to start the YouTube Viewer. If it is not found, will
 *         return a generic video-play intent, and system will display a
 *         chooser to ther user.
 */
public static Intent getYouTubeIntent(Context context, String url) {
  Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  final PackageManager pm = context.getPackageManager();
  List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0);
  for (int i = 0; i < activityList.size(); i++) {
    ResolveInfo app = activityList.get(i);
    if (app.activityInfo.name.contains("youtube")) {
      videoIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name);
      return videoIntent;
    }
  }
  return videoIntent;
}

来自@Guy 的代码-> https://stackoverflow.com/a/6674637/31751

于 2011-12-01T08:21:45.637 回答