install android studio

How to embed/integrate Youtube in Android App

Embed Youtube :

In Today’s world, all products who wish to enter the market need a strong presentation to the people who are interested in that product. And today’s best way to present anything behind the world is to make an effective video in which the product is fully described with entertainment. The biggest platform in today’s world to show and spread the product, message, education, etc with a video is YOUTUBE which has billions of users for surfing to see the videos.

In many android apps, many times there is a requirement of the users to show the video presentation which can be related to any of topics like education, technical, products etc. For this, we can embed or integrate youtube in our android app to show the videos within the app.

implementation:

For implementing the integration of youtube in android apps, follow the steps below carefully :

1.Permissions:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

2. activity_youtube.xml :

< view
android:id="@id/view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
class="com.google.android.youtube.player.YouTubePlayerView" />

3. Youtube.java :


public class MainActivity extends YouTubeBaseActivity {
    Button button;
    OnInitializedListener onInitializedListener;
    TextView textView;
    YouTubePlayerView youTubePlayerView;

   public class youtube implements OnClickListener {
        youtube() {
        }

        public void onClick(View v) {
            MainActivity.this.youTubePlayerView.initialize(projectConfig.API_KEY, MainActivity.this.onInitializedListener);
        }
    }

 
    public class static implements OnInitializedListener {
        youtube() {
        }

        public void onInitializationSuccess(Provider provider, YouTubePlayer youTubePlayer, boolean b) {
            youTubePlayer.loadVideo("iaqigx-glXk");
        }

        public void onInitializationFailure(Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
        }
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.button = (Button) findViewById(R.id.button2);
        this.youTubePlayerView = (YouTubePlayerView) findViewById(R.id.view);
        this.onInitializedListener = new Listener();
        this.button.setOnClickListener(new View());
    }

 

 

About the author

Generic Bytes

Hi! we are from Generic Bytes an aspiring bloggers with an obsession of things tech.This blog is dedicated to people who want to learn the technology.

View all posts

Leave a Reply

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