@@ -20,7 +20,9 @@ public class YouTubePlayerView extends FrameLayout implements NetworkReceiver.Ne
2020 @ NonNull private final NetworkReceiver networkReceiver ;
2121
2222 @ NonNull private final YouTubePlayer youTubePlayer ;
23+
2324 @ NonNull private final View playerControls ;
25+ @ NonNull private final PlayerControlsWrapper playerControlsWrapper ;
2426
2527 @ NonNull private final PlaybackResumer playbackResumer ;
2628
@@ -44,14 +46,14 @@ public YouTubePlayerView(Context context, AttributeSet attrs, int defStyleAttr)
4446 youTubePlayer = new YouTubePlayer (context );
4547 addView (youTubePlayer , new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT ));
4648 playerControls = inflate (context , R .layout .player_controls , this );
47- PlayerControlsWrapper playerControlsLogic = new PlayerControlsWrapper (this , playerControls );
49+ playerControlsWrapper = new PlayerControlsWrapper (this , playerControls );
4850
4951 playbackResumer = new PlaybackResumer (this );
5052
5153 fullScreenListeners = new HashSet <>();
52- fullScreenListeners .add (playerControlsLogic );
54+ fullScreenListeners .add (playerControlsWrapper );
5355
54- youTubePlayer .addListener (playerControlsLogic );
56+ youTubePlayer .addListener (playerControlsWrapper );
5557 youTubePlayer .addListener (playbackResumer );
5658
5759 networkReceiver = new NetworkReceiver (this );
@@ -169,29 +171,37 @@ public void call() {
169171 * See {@link YouTubePlayer#loadVideo(String, float)}
170172 */
171173 public void loadVideo (String videoId , float startSecond ) {
172- if (!initialized )
173- throw new IllegalStateException ("the player has not been initialized" );
174+ if (!initialized ) {
175+ Log .e ("YouTubePlayerView" , "the player has not been initialized" );
176+ return ;
177+ }
174178
175179 youTubePlayer .loadVideo (videoId , startSecond );
180+ playerControlsWrapper .onNewVideo ();
176181 }
177182
178183 /**
179184 * See {@link YouTubePlayer#cueVideo(String, float)}
180185 */
181186 public void cueVideo (String videoId , float startSeconds ) {
182- if (!initialized )
183- throw new IllegalStateException ("the player has not been initialized" );
187+ if (!initialized ) {
188+ Log .e ("YouTubePlayerView" , "the player has not been initialized" );
189+ return ;
190+ }
184191
185192 youTubePlayer .cueVideo (videoId , startSeconds );
193+ playerControlsWrapper .onNewVideo ();
186194 }
187195
188196 /**
189197 * Calls {@link WebView#destroy()} on the player. And unregisters the broadcast receiver (for network events), if registered.
190198 * Call this method before destroying the host Fragment/Activity
191199 */
192200 public void release () {
193- if (!initialized )
194- throw new IllegalStateException ("the player has not been initialized" );
201+ if (!initialized ) {
202+ Log .e ("YouTubePlayerView" , "the player has not been initialized" );
203+ return ;
204+ }
195205
196206 youTubePlayer .destroy ();
197207 getContext ().unregisterReceiver (networkReceiver );
@@ -201,8 +211,10 @@ public void release() {
201211 * See {@link YouTubePlayer#seekTo(int)}
202212 */
203213 public void seekTo (int time ) {
204- if (!initialized )
205- throw new IllegalStateException ("the player has not been initialized" );
214+ if (!initialized ) {
215+ Log .e ("YouTubePlayerView" , "the player has not been initialized" );
216+ return ;
217+ }
206218
207219 youTubePlayer .seekTo (time );
208220 }
@@ -211,8 +223,10 @@ public void seekTo(int time) {
211223 * See {@link YouTubePlayer#play()}
212224 */
213225 public void playVideo () {
214- if (!initialized )
215- throw new IllegalStateException ("the player has not been initialized" );
226+ if (!initialized ) {
227+ Log .e ("YouTubePlayerView" , "the player has not been initialized" );
228+ return ;
229+ }
216230
217231 youTubePlayer .play ();
218232 }
@@ -221,8 +235,10 @@ public void playVideo() {
221235 * See {@link YouTubePlayer#pause()}
222236 */
223237 public void pauseVideo () {
224- if (!initialized )
225- throw new IllegalStateException ("the player has not been initialized" );
238+ if (!initialized ) {
239+ Log .e ("YouTubePlayerView" , "the player has not been initialized" );
240+ return ;
241+ }
226242
227243 youTubePlayer .pause ();
228244 }
0 commit comments