我正在创建一个应用程序来录制视频并将其上传到 YouTube 和其他社交网站。
对于上传,我使用 Droid 共享功能并且效果很好。
在电子邮件、Facebook、Skype 等中上传效果很好,但当我选择 YouTube 时,它不会上传我的视频。
这是我用于视频分享的代码。
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"SUBJECT_NAME");
sharingIntent.setType("video/*");
File newFile = new File(video_path);
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,Uri.fromFile(newFile));
startActivity(Intent.createChooser(sharingIntent,"Where you want to share?"));
最佳答案
试试这段代码。
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "video_path");
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"share:"));
此代码是添加到您的分享按钮的onClick()方法中并得到结果。 将 EXTRA_STREAM 中的值作为 URI 而不是文件传递。
关于android - 如何在android中将视频上传到youtube?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15965246/