How to upload video to youtube in android?

后端 未结 8 1266
栀梦
栀梦 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:18

    Try this code.

    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:")); 
    

    this code is add in your share button's onClick() method and get result. pass the value in EXTRA_STREAM as an URI not as file.

    0 讨论(0)
  • 2020-12-08 06:21

    I don't have enough reputation to comment, but I lost an hour or so trying to get user2126788's code to work because I forgot to set the type on the intent.

    sharingIntent.setType("video/*");
    
    0 讨论(0)
提交回复
热议问题