Hay friends now you can do all thinks tricks and tips
Facebook hack
And Facebook page
How to Play Videos PLAYLIST YouTube using YouTube Android Player API in Android Studio
Create new project with Application name: Play YouTube Playlist; Minimum SDK: API 10 – Android 2.3.3 (Gingerbread).
Download YouTube Android Player API: https://developers.google.comCopy YouTubeAndroidPlayerApi.jar file to /libs folder in your project.
Add YouTubeAndroidPlayerApi.jar library in your project (see video tutorial from below).
In manifest->AndroidManifest.xml add the permission:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.toyo.playyoutubeplaylist">
<uses-permission android:name="android.permission.INTERNET" /><application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In app->res->layout->activity_main.xml add the code:
<?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: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.app.toyo.playyoutubeplaylist.MainActivity">
<com.google.android.youtube.player.YouTubePlayerView android:id="@+id/youtube_player" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff"/></RelativeLayout>
In app->java->MainActivity.java complete the code:
package com.app.toyo.playyoutubeplaylist;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.ErrorReason;
import com.google.android.youtube.player.YouTubePlayer.PlaybackEventListener;
import com.google.android.youtube.player.YouTubePlayer.PlayerStateChangeListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;
public class MainActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
public static final String API_KEY = "YOUR API KEY!!";
public static final String PlayList_ID = "YOUR PLAYLIST ID!!";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** Initializing YouTube Player View **/
YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
youTubePlayerView.initialize(API_KEY, this);
}
@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
Toast.makeText(this, "Failured to Initialize!", Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
/** add listeners to YouTubePlayer instance **/
player.setPlayerStateChangeListener(playerStateChangeListener);
player.setPlaybackEventListener(playbackEventListener);
/** Start buffering **/
if (!wasRestored) {
player.cuePlaylist(PlayList_ID);
}
}
private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {
@Override
public void onBuffering(boolean arg0) {
}
@Override
public void onPaused() {
}
@Override
public void onPlaying() {
}
@Override
public void onSeekTo(int arg0) {
}
@Override
public void onStopped() {
}
};
private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {
@Override
public void onAdStarted() {
}
@Override
public void onError(ErrorReason arg0) {
}
@Override
public void onLoaded(String arg0) {
}
@Override
public void onLoading() {
}
@Override
public void onVideoEnded() {
}
@Override
public void onVideoStarted() {
}
};
}
Obtain your API Key from Google APIs: https://code.google.com/apis/console (e.g. AIzaSyCe6tORd9Ch4lx-9Ku5SQ476uS9OtZYsWA) – see video tutorial from below.Get your Playlist ID from YouTube (e.g. PL1LAkZ-M7pNKwicHAlI3HGQMH0jofeXmd) – see video tutorial from below.
Run app in mobile device and use next and previous buttons to watch videos from youtube playlist in format portrait, landscape and full screen.
See the result of app in screenshot from mobile device:This doesn’t work on Emulator. It work only on mobile device!
Emulator can’t play YouTube videos, because YouTube have different formats (avi, mp4, mov, wmv etc) than emulator which supports only 3gp videos.
Watch the VIDEO TUTORIAL How to Play Videos PLAYLIST YouTube using YouTube Android Player API in Android Studio: