use of com.google.android.youtube.player.YouTubeInitializationResult in project DraggablePanel by pedrovgs.
the class YoutubeSampleActivity method initializeYoutubeFragment.
/**
* Initialize the YouTubeSupportFrament attached as top fragment to the DraggablePanel widget and
* reproduce the YouTube video represented with a YouTube url.
*/
private void initializeYoutubeFragment() {
youtubeFragment = new YouTubePlayerSupportFragment();
youtubeFragment.initialize(YOUTUBE_API_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
youtubePlayer = player;
youtubePlayer.loadVideo(VIDEO_KEY);
youtubePlayer.setShowFullscreenButton(true);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult error) {
}
});
}
use of com.google.android.youtube.player.YouTubeInitializationResult in project Habba18 by chiragsastry1996.
the class YoutubeFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_youtube, container, false);
backbutton = (Button) rootView.findViewById(R.id.back);
tName = (TextView) rootView.findViewById(R.id.name);
tCaption = (TextView) rootView.findViewById(R.id.caption);
VIDEO_ID = getArguments().getString("url");
Name = getArguments().getString("name");
Caption = getArguments().getString("caption");
tName.setText(Name);
tCaption.setText(Caption);
YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.youtube_layout, youTubePlayerFragment).commit();
youTubePlayerFragment.initialize(API_KEY, new OnInitializedListener() {
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
player.loadVideo(VIDEO_ID);
player.play();
}
}
@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult error) {
// YouTube error
String errorMessage = error.toString();
Log.d("errorMessage:", errorMessage);
}
});
backbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getFragmentManager().popBackStack();
}
});
return rootView;
}
use of com.google.android.youtube.player.YouTubeInitializationResult in project Reader by TheKeeperOfPie.
the class FragmentComments method loadYoutubeVideo.
private void loadYoutubeVideo(final String id, final int timeInMillis) {
if (youTubePlayer != null) {
toggleYouTubeVisibility(View.VISIBLE);
if (!id.equals(currentYouTubeId)) {
youTubePlayer.loadVideo(id);
currentYouTubeId = id;
}
return;
}
youTubeFragment = new YouTubePlayerSupportFragment();
layoutYouTube.setId(youTubeViewId);
getFragmentManager().beginTransaction().add(youTubeViewId, youTubeFragment, String.valueOf(youTubeViewId)).commit();
youTubeFragment.initialize(ApiKeys.YOUTUBE_API_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean b) {
FragmentComments.this.youTubePlayer = player;
youTubePlayer.setManageAudioFocus(false);
youTubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
boolean isLandscape = displayMetrics.widthPixels > displayMetrics.heightPixels;
if (isLandscape) {
youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
@Override
public void onFullscreen(boolean fullscreen) {
isFullscreen = fullscreen;
if (!fullscreen) {
releaseYouTube();
toggleYouTubeVisibility(View.GONE);
}
}
});
} else {
youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
@Override
public void onFullscreen(boolean fullscreen) {
isFullscreen = fullscreen;
}
});
}
youTubePlayer.setPlayerStateChangeListener(new YouTubePlayerStateListener(youTubePlayer, timeInMillis, isLandscape));
toggleYouTubeVisibility(View.VISIBLE);
youTubePlayer.loadVideo(id);
currentYouTubeId = id;
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
}
use of com.google.android.youtube.player.YouTubeInitializationResult in project EdenYouTube by Glurt.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Only add the toolbar if we are on Honeycomb and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
// Check for any issues
final YouTubeInitializationResult result = YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(this);
if (result != YouTubeInitializationResult.SUCCESS) {
// If there are any issues we can show an error dialog.
result.getErrorDialog(this, 0).show();
}
}
Aggregations