How to upload video to youtube in android?

后端 未结 8 1307
栀梦
栀梦 2020-12-08 05:27

I am Creating an application which records video and uploads it on YouTube and others Social sites.

For upload I use Droid share functionality and it works good.

8条回答
  •  独厮守ぢ
    2020-12-08 06:16

    After several hours of trying to find out how to make it work for uploading and sharing video on facebook, youtube, instagram and whatsapp. this is the code that worked for me. Uploading recorded video from your application to social media applications

    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, "your_path_to_video");
                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.setType("video/*");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
                sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
                startActivity(Intent.createChooser(sharingIntent,"share:")); 
    

提交回复
热议问题