【问题标题】:android youtube upload using intent使用意图的android youtube上传
【发布时间】:2011-08-18 13:14:37
【问题描述】:
Intent intent = new Intent();

intent.setAction(Intent.ACTION_SEND);
intent.setType("video/3gpp");
intent.putExtra(Intent.EXTRA_STREAM, videoURI);
startActivity(Intent.createChooser(intent,"Upload video via:"));

我使用上面的代码通过触发意图将 3gp 视频上传到 youtube

但它会引发以下异常。

我不明白日期异常和媒体上传有什么关系

05-04 13:04:59.315: ERROR/AndroidRuntime(10671): FATAL EXCEPTION: Thread-12
05-04 13:04:59.315: ERROR/AndroidRuntime(10671): java.lang.NullPointerException
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.util.Calendar.setTime(Calendar.java:1325)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:536)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.text.SimpleDateFormat.format(SimpleDateFormat.java:818)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.text.DateFormat.format(DateFormat.java:376)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity.a(SourceFile:183)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at com.google.android.apps.uploader.clients.SettingsActivity.b(SourceFile:43)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at com.google.android.apps.uploader.clients.j.run(SourceFile:348)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.lang.Thread.run(Thread.java:1019)

【问题讨论】:

  • 我也有这个问题,找不到解决办法。这真的让我很烦。

标签: android


【解决方案1】:

当我使用Uri.fromFile() 获取视频的 URI 时,我遇到了同样的错误。解决方案是使用 ContentProvider 创建 URI:

ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.TITLE, "Test");
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "/sdcard/myvideo.mp4");
ContentResolver resolver = getContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);

【讨论】:

  • 我还发现指定大小有帮助:content.put(MediaStore.Video.VideoColumns.SIZE, fileSizeInBytes);
  • 我只收到“没有应用程序可以执行此操作”,为什么?
  • @Patrick 可能是因为设备没有安装 youtube 应用?
猜你喜欢
  • 1970-01-01
  • 2015-02-15
  • 2013-04-27
  • 1970-01-01
  • 2013-03-12
  • 2015-12-25
  • 2010-10-09
  • 2014-12-26
相关资源
最近更新 更多