forked from PierfrancescoSoffritti/android-youtube-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IFramePlayerOptionsExampleActivity.java
83 lines (66 loc) · 3.12 KB
/
IFramePlayerOptionsExampleActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.iFramePlayerOptionsExample;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.Button;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.utils.YouTubePlayerUtils;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.options.IFramePlayerOptions;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.utils.VideoIdsProvider;
import com.pierfrancescosoffritti.aytplayersample.R;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
public class IFramePlayerOptionsExampleActivity extends AppCompatActivity {
private YouTubePlayerView youTubePlayerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_iframe_player_options_example);
youTubePlayerView = findViewById(R.id.youtube_player_view);
initYouTubePlayerView();
}
private void initYouTubePlayerView() {
youTubePlayerView.inflateCustomPlayerUi(R.layout.ayp_empty_layout);
IFramePlayerOptions iFramePlayerOptions = new IFramePlayerOptions.Builder()
.controls(0)
.rel(0)
.ivLoadPolicy(1)
.ccLoadPolicy(1)
.build();
getLifecycle().addObserver(youTubePlayerView);
youTubePlayerView.initialize(new AbstractYouTubePlayerListener() {
@Override
public void onReady(@NonNull YouTubePlayer youTubePlayer) {
setPlayNextVideoButtonClickListener(youTubePlayer);
YouTubePlayerUtils.loadOrCueVideo(
youTubePlayer, getLifecycle(),
VideoIdsProvider.getNextVideoId(),0f
);
}
}, true, iFramePlayerOptions);
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
youTubePlayerView.enterFullScreen();
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
youTubePlayerView.exitFullScreen();
}
}
/**
* Set a click listener on the "Play next video" button
*/
private void setPlayNextVideoButtonClickListener(final YouTubePlayer youTubePlayer) {
Button playNextVideoButton = findViewById(R.id.next_video_button);
playNextVideoButton.setOnClickListener(view ->
YouTubePlayerUtils.loadOrCueVideo(
youTubePlayer, getLifecycle(),
VideoIdsProvider.getNextVideoId(),0f
)
);
}
}