Mr.Sandy
Mr.Sandy

Reputation: 4349

How to upload video to youtube in android?

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.

In e-mail, Facebook, Skype, etc upload works perfect, but when I select YouTube, it does not upload my video.

Here is the code I use for video sharing.

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

Upvotes: 14

Views: 7814

Answers (8)

user5071155
user5071155

Reputation: 121

        ContentValues content = new ContentValues(4);
        content.put(MediaStore.Video.VideoColumns.DATE_ADDED,
                System.currentTimeMillis() / 1000);
        content.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
        content.put(MediaStore.Video.Media.DATA, path);
        ContentResolver resolver = getActivity().getContentResolver();
        Uri uri1 =  Uri.fromFile(new File(path)); 

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("video/*");
        sharingIntent.setPackage("com.google.android.youtube");
        sharingIntent.putExtra(Intent.EXTRA_TITLE, "Title");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Desc");
        sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri1);
        startActivity(Intent.createChooser(sharingIntent, "Share to"));

Upvotes: 0

Tarek Mowafy
Tarek Mowafy

Reputation: 45

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

Upvotes: 1

Ibrahim Ulukaya
Ibrahim Ulukaya

Reputation: 12877

Another good solution is to implement your own upload mechanism without leaving your app. You can use Google Java and Android libraries with YouTube java libraries.

Here's a full app utilizing this: https://github.com/youtube/yt-direct-lite-android

Upvotes: 0

danghis khan
danghis khan

Reputation: 176

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/*");

Upvotes: 7

user2126788
user2126788

Reputation:

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.

Upvotes: 18

Mr.Sandy
Mr.Sandy

Reputation: 4349

This code is working for me fine.

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title_text");
//sharingIntent.setType("video/*");
File newFile = new File(path_var);
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Where you want to share?")); 

Upvotes: 0

Mr.Sandy
Mr.Sandy

Reputation: 4349

This code is working for me fine.

I try to Implement and get best result.

so,if anyone face this type of problem try this code.

I'm sure It's also works perfect for you.

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, "path_of_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.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title_text");
//sharingIntent.setType("video/*");
//File newFile = new File(path_var);
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Where you want to share?")); 

this code is pitting in your share button's onClick() method and get result.

Upvotes: 0

AndroidEnthusiastic
AndroidEnthusiastic

Reputation: 931

please add this line in android manifest

     <intent-filter>
     <action android:name="android.intent.action.SEND" />
     <category android:name="android.intent.category.DEFAULT" />              
     <data android:host="www.youtube.com" android:mimeType="text/*" /> 
     </intent-filter>

Upvotes: 1

Related Questions