Multiple YouTubePlayerFragment's in a ViewPager - android

I am working on an App which shows a bunch of contents and each content is a View managed by a ViewPager. Some of these contents may include a youtube video. For that, I place an instance of YouTubePlayerFragment inside the page. It works fine and I see videos, but the issue is this:
Let's assume there are three pages in the ViewPager, namely P1, P2, and P3. Each page contains a youtube video, V1, V2, and V3 respectively. If I am on page P2 and swipe left and then back to P2, I see the content of page P2, but the loaded video is V1. If I swipe right to P3 and back to P2, then the content of P2 is correct, except that it shows V3.
I added an extra line in onLoaded(String s) in my listener for testing purpose, and I detected that the Video ID that I give to player.cueVideo() as input differs from 's' which is the Video ID that is loaded to the player and this is basically the problem. But I am not sure why this happens. Below is all the relevant part of the code:
protected void addYourTubeFragment() {
youtubeVideoID = getYoutubeVideoID();
FragmentTransaction fragmentTransaction = ((Activity) getContext()).getFragmentManager().beginTransaction();
YouTubePlayerFragment youtubeFragment = YouTubePlayerFragment.newInstance();
fragmentTransaction.add(R.id.video_entity_layout, youtubeFragment);
fragmentTransaction.commit();
youtubeFragment.initialize(Util.DEVELOPER_KEY, this);
}
public void onInitializationSuccess(Provider provider, YouTubePlayer ytPlayer, boolean wasRestored) {
if ( !wasRestored ) {
YouTubePlayer player = ytPlayer;
Log.d(TAG, "Card ID: " + card.getId() + " Youtube Video ID: " + videoLinkToPlay);
player.cueVideo(youtubeVideoID);
player.setOnFullscreenListener(new OnFullscreenListener() {
public void onFullscreen(boolean full) {
playingFull = full;
}
});
player.setPlayerStateChangeListener(new YouTubePlayer.PlayerStateChangeListener() {
#Override
public void onLoading() {
}
#Override
public void onLoaded(String s) {
if (!youtubeVideoID.equals(s)) {
DialogBuilder.showSimpleAlert(getContext(), "ERROR", "This is different from the original Video ID");
}
}
#Override
public void onAdStarted() {
}
#Override
public void onVideoStarted() {
TrackingUtil.logTimed(TrackingUtil.EVENT_WATCHES_CARD_VIDEO);
}
#Override
public void onVideoEnded() {
FlurryAgent.endTimedEvent(TrackingUtil.EVENT_WATCHES_CARD_VIDEO);
}
#Override
public void onError(YouTubePlayer.ErrorReason errorReason) {
}
});
}
}
Can anyone help me figure this out? Is it an Android/YourtubePlayer issue? or is it something I am not doing right?

Related

Minimizing/Maximizing youTube video in YouTubePlayerView

I have a container where I show a GIF video.On click of the GIF it opens the same video in YouTube. YouTubePlayerView has maximize and minimize icon, when I click on that video is just restarting instead of minimizing it and get back to the same container. I am not sure how to minimize the video which is playing in YouTubePlayerView.
I have created a separate Activity called YouTubeACtivity:
public class YoutubeActivity extends AppCompatActivity {
String shortCode = "";
public static void show(Activity activity, String shortCode)
{
Intent intent = new Intent(activity, YoutubeActivity.class);
intent.putExtra(Constants.YOUTUBE_VIDEO, shortCode);
activity.startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_youtubeplayer);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
shortCode = getIntent().getStringExtra(Constants.YOUTUBE_VIDEO);
YouTubePlayerFragment mYoutubePlayerFragment = new YouTubePlayerFragment().newInstance();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.youtubeContainer, mYoutubePlayerFragment);
ft.commit();
if (mYoutubePlayerFragment != null) {
mYoutubePlayerFragment.initialize(getResources().getString(R.string.google_api_key), new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean restored) {
//youTubePlayer.setFullscreen(true);
youTubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE| YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);
// youTubePlayer. setShowFullscreenButton(false);
youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
#Override
public void onFullscreen(boolean fullscreen) {
// onBackPressed();
}
});
Log.e("shortcode ", "reached" + shortCode);
if (shortCode != null) {
if (restored) {
youTubePlayer.play();
} else {
youTubePlayer.loadVideo("" + shortCode + "");
}
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.e("youtube initialization ", "initialisation fails");
}
});
}
}
}
The GIF video is showing in a FrameLayout which implements SurfaceHolder callback.
I just wanted to know is there anyway we can make minimize the video and comeback to the container layout.
First I suggest to use the player object to go or exit fullscreen
youtubeplayer.setFullScreen(true/false);
then add config changes in manifest of the activity containing the container
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout"
as far as i can understand your problem your activity is getting restarted

Appodeal Rewarded ads failed to Load

Im solving this issue for about 3 days. Im implementing Rewarded Ads of Appodeal. When I first start my app It works fine . Appodeal onRewardedVideoLoaded function called and it works fine. But After closing the app and running it again. It always calls onRewardedVideoFailedToLoad function and ads do not load. Below is my code.
Please check this code. Thankyou
/** Set up button to show an ad when clicked */
show_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//ad.show();
if (Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
Appodeal.show(getActivity(), Appodeal.REWARDED_VIDEO);
}
}
});
//appodeal
Appodeal.setAutoCache(Appodeal.REWARDED_VIDEO, false);
Appodeal.initialize(getActivity(), appKey, Appodeal.REWARDED_VIDEO);
// Appodeal.setTesting(true);
Appodeal.setLogLevel(com.appodeal.ads.utils.Log.LogLevel.verbose);
Appodeal.cache(getActivity(), Appodeal.REWARDED_VIDEO);
if (Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
progress.setVisibility(View.INVISIBLE);
System.out.println("Is loaded so enable");
show_button.setText("Earn Reward");
}
Appodeal.setRewardedVideoCallbacks(new RewardedVideoCallbacks() {
private Toast mToast;
#Override
public void onRewardedVideoLoaded() {
System.out.println("onRewardedVideoLoaded");
show_button.setEnabled(true);
progress.setVisibility(View.INVISIBLE);
show_button.setText("Earn Reward");
}
#Override
public void onRewardedVideoFailedToLoad() {
System.out.println("onRewardedVideoFailedToLoad");
progress.setVisibility(View.INVISIBLE);
}
#Override
public void onRewardedVideoShown() {
System.out.println("onRewardedVideoShown");
show_button.setEnabled(false);
show_button.setText("Not Avalible");
progress.setVisibility(View.VISIBLE);
}
#Override
public void onRewardedVideoFinished(int amount, String name) {
System.out.println(String.format("onRewardedVideoFinished. Reward: %d %s", amount, name));
SharedPref.putIntPref("rewards_count", SharedPref.getIntPref("rewards_count", getContext()) + amount, getContext());
// watcher.RemainingRewards(SharedPref.getIntPref("rewards_count", getContext()));
UpdateRewards();
}
#Override
public void onRewardedVideoClosed(boolean finished) {
System.out.println(String.format("onRewardedVideoClosed, finished: %s", finished));
}
void showToast(final String text) {
if (mToast == null) {
mToast = Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT);
}
mToast.setText(text);
mToast.setDuration(Toast.LENGTH_SHORT);
mToast.show();
}
});
return view;
}
I had a similar issue, but actually it was connected with framework I used (it turned out after I contacted them), so I'd suggest asking their support directly, usually they respond rather quick + u can message them from LiveChat window on the homepage, right bottom corner. This would be the best way to solve your provlem imo. Not sure that my case will solve your problem, but still it might help you somehow.
i wanted to show skippable and non skippable videos in several projects.
All in all using skippable videos was simple, i only needed to implement GdxAppodeal.VIDEO while initializing.
so to show videos I used GdxAppodeal.getInstance().show(GdxAppodeal.VIDEO);
+
Video callbacks:
GdxAppodeal.getInstance().setVideoCallbacks(new VideoCallback() {
#Override
public void onVideoLoaded() { }
#Override
public void onVideoFailedToLoad() { }
#Override
public void onVideoShown() { }
#Override
public void onVideoFinished() { }
#Override
public void onVideoClosed() { }
});
important nuance was that u can't set reward settings on site for skippable video.
This only works for rev vids.
So, User will get reward on RewardedVideoFinished callback

What to change in my app (no AD within it) to avoid violation of the YouTube API Terms of Service?

I have a basic app for kids that allows them to click on icon to perform a youtube search (link to amazon app store).
Although I have done a lot of changes in the app, its removed from the Google Play store for "violation of the YouTube Terms of Service or YouTube API Terms of Service" (the full text is attached below).
I did a research here and it seems that my app dosen't have the problems that i have seen in other applications. the app dosen't have AD's and i think its not interfiring to the youtube Ad's and not playing videos in background.
In addition, I filed an appeal to Google Play. Their response was that my app streams copyrighted content from YouTube. I had a search for cartoons, so i removed it and resubmited and the app rejected again for the same reason.
when i asked for further assistance they answer: "Unfortunately, as much as we'd like to help, we aren't able to provide additional information for your inquiry".Very frustrating.
I'd appreciate your help. Perhaps i made a mistake in the code that implements the YoutubePlayer, Other ideas are welcome to.
the full Notification from Google Play:
This is a notification that your application, KidoTube, for package ID com.elelad.kidstube, has been removed from Google Play.
Please address the issue described below and submit a compliant update. Once approved, your application will again be available with all installs, ratings and reviews intact.
REASON FOR REMOVAL:Violation of section 4.4 of the Developer Distribution Agreement.
After a regular review, we have determined that your app downloads, monetizes, or otherwise accesses YouTube videos in violation of the YouTube Terms of Service or YouTube API Terms of Service. Accessing content, a product, or service in an unauthorized manner is a violation of the Developer Distribution Agreement, and is not allowed on Google Play.
All removals are tracked. Repeated removals will result in app suspension, at which point this app will count as a strike against the good standing of your developer account and no longer be available on Google Play.
This notification also serves as notice for other apps in your catalog. You can avoid future removals and/or app suspensions by immediately ensuring that no other apps in your catalog are in violation of (but not limited to) the above policy. Before publishing applications, please ensure your apps’ compliance with the Developer Distribution Agreement and Content Policy.
If you feel we have made this determination in error, you can visit this Google Play Help Center article.
The Google Play Team
My YoutubeActivity Class:
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
private final static String TAG = YoutubeActivity.class.getSimpleName();
YouTubePlayer player;
public static String YOUTUBE_VIDEO_ID = null;
LayoutInflater mLayoutInflater;
private FragmentActivity myContext;
public TextView textToast;
public View toastLayout;
ProgressBar cycleProgressBar;
Search search = new Search();
List<Video> mVideoList;
private static boolean initialize = false;
GetRandomInBackground getRandomInBackground;
YouTubePlayerView youTubePlayer;
ImageView waitLogo;
AnimationDrawable frameAnimation2;
ImageButton play;
public static void setYoutubeVideoId(String youtubeVideoId) {
YOUTUBE_VIDEO_ID = youtubeVideoId;
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);}
}
#Override
public void onCreate(Bundle savedInstanseState) {
super.onCreate(savedInstanseState);
ContentResolver mContentResolver = getContentResolver();
setContentView(R.layout.youtube_player);
waitLogo = (ImageView) findViewById(R.id.player_logo);
play = (ImageButton) findViewById(R.id.play);
try {
startLogoAnimation();
}catch (Exception e){
waitLogo.setImageResource(R.mipmap.kidotube);
}
youTubePlayer = (YouTubePlayerView) findViewById(R.id.vYouTubePlayer);
if (Setting.isStartRandomVideo()) {
getRandomInBackground = new GetRandomInBackground();
getRandomInBackground.execute();
}
youTubePlayer.initialize(Search.getGoogleApiKey(), this);
youTubePlayer.setVisibility(View.INVISIBLE);
}
#Override
protected void onPause() {
super.onPause();
BaseActivity.myLifecycleHandler.onActivityPaused(this);
}
#Override
protected void onResume() {
super.onResume();
BaseActivity.myLifecycleHandler.onActivityResumed(this);
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult result) {
Toast.makeText(this, "Cant initialize YouTube Player", Toast.LENGTH_LONG).show();
finish();
}
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer mplayer,
boolean wasRestored) {
this.player = mplayer;
player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
player.setPlayerStateChangeListener(playerStateChanageListener);
player.setPlaybackEventListener(playBackEvaentListener);
if (!Setting.isStartRandomVideo()) {
player.loadVideo(YOUTUBE_VIDEO_ID);
}
}
private YouTubePlayer.PlaybackEventListener playBackEvaentListener = new YouTubePlayer.PlaybackEventListener() {
public void onBuffering(boolean arg0) {
Log.v(TAG, "onBuffering");
}
#Override
public void onPaused() {
Log.v(TAG, "onPaused");
}
#Override
public void onPlaying() {
Log.v(TAG, "onPlaying");
}
#Override
public void onSeekTo(int arg0) {
Log.v(TAG, "onSeekTo");
}
#Override
public void onStopped() {
Log.v(TAG, "onStopped");
}
};
private YouTubePlayer.PlayerStateChangeListener playerStateChanageListener = new YouTubePlayer.PlayerStateChangeListener() {
#Override
public void onAdStarted() {
}
#Override
public void onError(YouTubePlayer.ErrorReason arg0) {
Log.v(TAG, "onError" );
Toast.makeText(YoutubeActivity.this, getString(R.string.Video_Error), Toast.LENGTH_LONG).show();
finish();
}
#Override
public void onLoaded(String arg0) {
Log.v(TAG, "onLoaded" + arg0);
}
#Override
public void onLoading() {
Log.v(TAG, "onLoading" );
}
#Override
public void onVideoEnded() {
Log.v(TAG, "onVideoEnded" );
finish();
}
#Override
public void onVideoStarted() {
Log.v(TAG, "onVideoStarted");
play.setVisibility(View.INVISIBLE);
waitLogo.setVisibility(View.INVISIBLE);
frameAnimation2.stop();
youTubePlayer.setVisibility(View.VISIBLE);
}
};
public class GetRandomInBackground extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
search.SearchNow(MainActivity.getSearchFor());
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
if (search.getVideoList() == null || search.getVideoList().size() == 0) {
Toast.makeText(YoutubeActivity.this, getString(R.string.No_results_found), Toast.LENGTH_LONG).show();
Intent intent = new Intent(YoutubeActivity.this, MainActivity.class);
startActivity(intent);
} else {
mVideoList = search.getVideoList();
setYoutubeVideoId(search.playRand(mVideoList));
player.loadVideo(YOUTUBE_VIDEO_ID);
Search.setNumberOfVideosReturned(20);
}
}catch (Exception e){
finish();
}
}
}
public void startLogoAnimation(){
waitLogo.setBackgroundResource(R.drawable.wait_icon);
frameAnimation2 = (AnimationDrawable) waitLogo
.getBackground();
frameAnimation2.start();
}
public int animationDuration(AnimationDrawable animationDrawable){
int duration = 0;
int frames = animationDrawable.getNumberOfFrames();
for (int i = 0; i<frames; i++){
duration = duration + animationDrawable.getDuration(i);
}
return duration;
}
Thanks in advance!
well, it was one of my settings.
I made an option to click on icon and play a random video, apparently it's violation of the API terms.
When I removed the option the application is approved.
I hope this is the end..

YouTube Player plays for 2 seconds and stop in full screen

I'm currently facing 2 major problems,
I'm using a youtube player and when it gets on full screen, It plays for 1-2 seconds and stop.
When I click the "Play" button in the middle, it's buffering all over again. even if the gray bar filled to it's center.
those problems aren't occurring in portrait mode.
here is my class, like the youtube api demo with a bit defference
public class Video extends YouTubeFailureRecoveryActivity implements YouTubePlayer.OnFullscreenListener, Utils.OnGetUrlListener, View.OnClickListener {
static int AUTO_PLAY_DELAY = 1000;
static final int PORTRAIT_ORIENTATION = Build.VERSION.SDK_INT < 9
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
private LinearLayout mRootLayout;
/**
* * Youtube ***
*/
YouTubePlayerView mPlayerView;
YouTubePlayer mPlayer;
boolean mIsFullscreen;
String urlID;
/**
* * My ***
*/
RelativeLayout mContainer;
ImageView mBtPlay;
boolean mIsNeedSetFlags;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.getInstance().setActivity(this);
setContentView(R.layout.video_main);
mIsNeedSetFlags = true;
mRootLayout = (LinearLayout) findViewById(R.id.video_root_layout);
mContainer = (RelativeLayout) findViewById(R.id.container);
mBtPlay = (ImageView) findViewById(R.id.video_play);
mBtPlay.setVisibility(View.INVISIBLE);
mPlayerView = (YouTubePlayerView) findViewById(R.id.player);
Intent intent = getIntent();
doLayout();
}
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
mPlayer = player;
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
player.setOnFullscreenListener(this);
if (mIsNeedSetFlags) {
mIsNeedSetFlags = false;
int controlFlags = player.getFullscreenControlFlags();
setRequestedOrientation(PORTRAIT_ORIENTATION);
controlFlags |= YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
player.setFullscreenControlFlags(controlFlags);
}
if (!wasRestored) {
player.cueVideo(urlID);
}
}
#Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return mPlayerView;
}
private void doLayout() {
LinearLayout.LayoutParams playerParams = (LinearLayout.LayoutParams) mPlayerView.getLayoutParams();
if (mIsFullscreen) {
playerParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
playerParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
mParallaxScrollView.setVisibility(View.GONE);
} else {
mParallaxScrollView.setVisibility(View.VISIBLE);
if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
ViewGroup.LayoutParams otherViewsParams = mParallaxScrollView.getLayoutParams();
playerParams.width = otherViewsParams.width = MATCH_PARENT;
playerParams.height = WRAP_CONTENT;
mRootLayout.setOrientation(LinearLayout.VERTICAL);
}
}
mPlayerView.setLayoutParams(playerParams);
}
#Override
public void onFullscreen(boolean isFullscreen) {
mIsFullscreen = isFullscreen;
showPlayerAndPlay();
doLayout();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
doLayout();
}
#Override
public void onGetUrlFinished(String videoUrl) {
urlID = videoUrl;
mBtPlay.setVisibility(View.VISIBLE);
mBtPlay.setOnClickListener(this);
mPlayerView.initialize(Utils.YOU_TUBE_DEV_KEY, this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.video_play:
showPlayerAndPlay();
break;
}
}
private void showPlayerAndPlay() {
mPlayerView.setVisibility(View.VISIBLE);
mBtPlay.setVisibility(View.INVISIBLE);
if (!mPlayer.isPlaying())
new android.os.Handler().postDelayed(new Runnable() {
#Override
public void run() {
mPlayer.play();
}
}, AUTO_PLAY_DELAY);
}
}
YouTube does not allow other views to be overlayed on top of its player view.
If you check the logs, you will also see a warning message that specifies this very limitation, plus more information on which view (its ID) and the overlapping region.
A good alternative is to used Exoplayer, to overlay your video with view. It is not part of the android sdk, but it's recommended by google and included in android developer documentation :
http://google.github.io/ExoPlayer/ https://developer.android.com/guide/topics/media/exoplayer.html
Exoplayer allow you to stream any kind of video, not only Youtubes videos.
It's also good to mention that Exoplayer is used in Youtube application.
As the answer marked as correct explained: the problem is overlaying a view over the Youtube player view. If you need to keep those views will the Youtube is initializing then this will do the trick.
I was doing a loading animation with crossfade for the involved views. Setting alpha to 0 won't fix the issue because the view is still there. But setting visibility to GONE or INVISIBLE does work. For what I understand a View is not computed if is not VISIBLE, well at least it will not be taken into consideration after the visibility changed. Finally, I did something like this:
myView.animate().alpha(0).setDuration(800).setListener(
new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animator) {
}
#Override
public void onAnimationEnd(Animator animator) {
myView.setVisibility(View.GONE);
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
}).start();

which file to render and play in android youtube player

I am successfully integrate YouTube Android Player API for my apps. I am curious to know about which file is rendered in the player. Every single video file may have several formats like 320dpi,720dpi & etc.
If my users, is in lower bandwidth; can i choose the file format or the API automatically detects which version would be played in that situation and vice-verse. My code:
public class YoutubeVideoActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener, YouTubePlayer.OnFullscreenListener {
Activity activity = YoutubeVideoActivity.this;
public static final String API_KEY = "AIzaSyDN6Q9Pv4seQZqIcjB*********Po5k";
// public static final String VIDEO_ID = "psY0Botpi84";
public String new_id;
private boolean fullscreen;
private YouTubePlayerView playerView;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
// Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_youtube_video);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Intent intent = getIntent();
String video_link = intent.getExtras().getString("video_link");
try {
new_id = video_link.substring("http://www.youtube.com/watch?v="
.length());
if (new_id.equals("")) {
IndepententTVUtils.showCustomAlert(activity,
"Data is not availble. Press back key",
R.drawable.ic_new_launcher);
} else {
playerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
playerView.initialize(API_KEY, this);
}
} catch (Exception e) {
IndepententTVUtils.showCustomAlert(activity,
"Data is not availble", R.drawable.ic_new_launcher);
}
}
#Override
public void onInitializationFailure(Provider arg0,
YouTubeInitializationResult arg1) {
Toast.makeText(getApplicationContext(),
"To See this Video, Install Latest YouTube Application",
Toast.LENGTH_LONG).show();
}
#Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer player,
boolean wasRestored) {
player.setOnFullscreenListener(this);
if (!wasRestored && new_id != null) {
player.cueVideo(new_id);
}
}
#Override
public void onFullscreen(boolean isFullscreen) {
fullscreen = isFullscreen;
}
}
The player sets video quality automatically according to the users bandwidth or internet speed, if it was not so there would be an option specifying the setPlaybackQuality in player.
There are only restricted options to change the player settings that are
here

Categories

Resources