Download youtube video from android studio | youtube downloader in android

Hey, guys here is another useful article Download youtube video from android studio . in this article i will show you the example how to make youtube downloader for android phone. that will work in both Wi-fi connection and work with the mobile connection.Download youtube video from android studio. youtube downloader in android


Download youtube video from android studio

youtube downloader in android

Add into your gradle file

 allprojects {
        repositories {
            maven { url "https://jitpack.io" }
        }
    }

And dependencies

 compile 'com.github.Commit451.YouTubeExtractor:youtubeextractor:2.1.0'

Xml file

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:id=”@+id/activity_main”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.bicubic.youtubedownload.MainActivity”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Hello World!” />
</RelativeLayout>

 

java file

 

package com.bicubic.youtubedownload;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.commit451.youtubeextractor.YouTubeExtractionResult;
import com.commit451.youtubeextractor.YouTubeExtractor;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

private static final String YOUTUBE_ID = “ea4-5mrpGfE”;

private final YouTubeExtractor mExtractor = YouTubeExtractor.create();

private Callback<YouTubeExtractionResult> mExtractionCallback = new Callback<YouTubeExtractionResult>() {
@Override
public void onResponse(Call<YouTubeExtractionResult> call, Response<YouTubeExtractionResult> response) {
bindVideoResult(response.body());
}

@Override
public void onFailure(Call<YouTubeExtractionResult> call, Throwable t) {
onError(t);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// For android youtube extractor library com.github.Commit451.YouTubeExtractor:youtubeextractor:2.1.0′

mExtractor.extract(YOUTUBE_ID).enqueue(mExtractionCallback);

}

chek this also 

cant play this video Media player error in android studio solvedDownload youtube video from android studio

private void onError(Throwable t) {
t.printStackTrace();
Toast.makeText(MainActivity.this, “It failed to extract. So sad”, Toast.LENGTH_SHORT).show();
}

private void bindVideoResult(YouTubeExtractionResult result) {

Log.d(“OnSuccess”, “Got a result with the best url: ” + result.getBestAvailableQualityVideoUri());

Toast.makeText(this, “result : ” + result.getSd360VideoUri(), Toast.LENGTH_SHORT).show();
}
}

 

final word:- 

if you have any doubt or problem regarding  Download youtube video from android studio. Then you can feel free to ask the question. So, write your problem in the comment box. Because we are here to solve your all doubt.

Leave a Reply

Your email address will not be published. Required fields are marked *