Upload video to Youtube via android studio
Asked Answered
R

2

8

I'm a new programmer in Android studio.

I am trying to create a button that gets a file location and uploads it to my youtube account:

I succeeded to get a video file's directory in my android code:

File mediaFile = 
    new File(Environment.getExternalStorageDirectory().getAbsolutePath()....)

I added a button that calls UploadToYoutube function.

Now I would like to upload it to my youtube account through the file path I have.

Can someone direct me?

Any help appreciated!

Rintoul answered 6/4, 2015 at 19:19 Comment(1)
I think it was answered before please check this How to Answer[1] [1]: #10246712Aplenty
N
16

My suggestion:

Get Start

Obtaining authorization credentials

Implementing OAuth 2.0 Authentication

YouTube API: Client Libraries

Using google-api-java-client:

Use YouTube Data API (v3)

Sources Examples in

Post a channel bulletin

Create and manage YouTube video caption tracks

Add a featured video

Retrieve my uploads

Create a playlist

Search by keyword

Search by topic

Search by geolocation

Add a channel subscription

Upload a video thumbnail image

Upload a video << Example code in java : )

Update a video

Nobility answered 15/4, 2015 at 1:24 Comment(2)
For the detailed answer and references, +1Anamorphism
@Anamorphism can you give me full code to upload video to static username and password using oauth2, from my android application?Purse
S
0

Here is my working code

        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"));
Schorl answered 12/11, 2020 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.