Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTubePlayerView reloads the video on screen orientation change

I launch a youtube video from my app using the following activity. When the activity is launched, youtube video is played. But when I change the orientation of the screen, the video is not resuming but started from the beginning. What's the issue here?

package com.example.blahblah;

import android.content.res.Configuration;
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.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

public class YTPlayActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {


       static private String yt_sk;
       static private final String DEVELOPER_KEY = "my-api-key";

       @Override

       protected void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              setContentView(R.layout.yt_player);
              Bundle extras = getIntent().getExtras();
             yt_sk = extras.getString("yt_sk");

              YouTubePlayerView youTubeView = (YouTubePlayerView)
findViewById(R.id.youtube_view);

           youTubeView.initialize(DEVELOPER_KEY, this);

          }

         @Override

         public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {

                Toast.makeText(this, "Oh no! "+error.toString(),
Toast.LENGTH_LONG).show();

       }
       @Override

       public void onInitializationSuccess(Provider provider, YouTubePlayer player,
boolean wasRestored) {

              player.loadVideo(yt_sk);

       }



}
like image 657
nizam.sp Avatar asked Oct 17 '13 20:10

nizam.sp


1 Answers

Added the configChanges in the AndroidManifest file and it worked.

Eg:

 <activity android:label=Activity Name" 
  android:configChanges="keyboardHidden|orientation|screenSize"
  android:name="com.example.blahblah"> 
like image 155
nizam.sp Avatar answered Oct 17 '22 05:10

nizam.sp