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);
}
}
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">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With