11/**
22 * Copyright (C) 2016 Toshiro Sugii
3- * <p>
3+ * <p/ >
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
7- * <p>
7+ * <p/ >
88 * http://www.apache.org/licenses/LICENSE-2.0
9- * <p>
9+ * <p/ >
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -111,22 +111,28 @@ protected void initObjects() {
111111 this .videoControlsView = inflater .inflate (R .layout .view_videocontrols , this , false );
112112 }
113113
114- RelativeLayout .LayoutParams params = new RelativeLayout .LayoutParams (RelativeLayout .LayoutParams .FILL_PARENT , RelativeLayout .LayoutParams .WRAP_CONTENT );
115- params .addRule (ALIGN_PARENT_BOTTOM );
116- addView (videoControlsView , params );
117-
118- this .seekBar = (SeekBar ) this .videoControlsView .findViewById (R .id .vcv_seekbar );
119- this .imgfullscreen = (ImageButton ) this .videoControlsView .findViewById (R .id .vcv_img_fullscreen );
120- this .imgplay = (ImageButton ) this .videoControlsView .findViewById (R .id .vcv_img_play );
121- this .textTotal = (TextView ) this .videoControlsView .findViewById (R .id .vcv_txt_total );
122- this .textElapsed = (TextView ) this .videoControlsView .findViewById (R .id .vcv_txt_elapsed );
114+ if (videoControlsView != null ) {
115+ RelativeLayout .LayoutParams params = new RelativeLayout .LayoutParams (RelativeLayout .LayoutParams .FILL_PARENT , RelativeLayout .LayoutParams .WRAP_CONTENT );
116+ params .addRule (ALIGN_PARENT_BOTTOM );
117+ addView (videoControlsView , params );
118+
119+ this .seekBar = (SeekBar ) this .videoControlsView .findViewById (R .id .vcv_seekbar );
120+ this .imgfullscreen = (ImageButton ) this .videoControlsView .findViewById (R .id .vcv_img_fullscreen );
121+ this .imgplay = (ImageButton ) this .videoControlsView .findViewById (R .id .vcv_img_play );
122+ this .textTotal = (TextView ) this .videoControlsView .findViewById (R .id .vcv_txt_total );
123+ this .textElapsed = (TextView ) this .videoControlsView .findViewById (R .id .vcv_txt_elapsed );
124+ }
123125
124- this .imgplay .setOnClickListener (this );
125- this .imgfullscreen .setOnClickListener (this );
126- this .seekBar .setOnSeekBarChangeListener (this );
126+ if (this .imgplay != null )
127+ this .imgplay .setOnClickListener (this );
128+ if (this .imgfullscreen != null )
129+ this .imgfullscreen .setOnClickListener (this );
130+ if (this .seekBar != null )
131+ this .seekBar .setOnSeekBarChangeListener (this );
127132
128133 // Start controls invisible. Make it visible when it is prepared
129- this .videoControlsView .setVisibility (View .INVISIBLE );
134+ if (this .videoControlsView != null )
135+ this .videoControlsView .setVisibility (View .INVISIBLE );
130136 }
131137
132138 @ Override
@@ -150,6 +156,9 @@ protected void stopCounter() {
150156 }
151157
152158 protected void updateCounter () {
159+ if (this .textElapsed == null )
160+ return ;
161+
153162 int elapsed = getCurrentPosition ();
154163 // getCurrentPosition is a little bit buggy :(
155164 if (elapsed > 0 && elapsed < getDuration ()) {
@@ -206,25 +215,28 @@ protected void tryToPrepare() {
206215 super .tryToPrepare ();
207216
208217 if (getCurrentState () == State .PREPARED || getCurrentState () == State .STARTED ) {
209- int total = getDuration ();
210- if (total > 0 ) {
211- seekBar .setMax (total );
212- seekBar .setProgress (0 );
213-
214- total = total / 1000 ;
215- long s = total % 60 ;
216- long m = (total / 60 ) % 60 ;
217- long h = (total / (60 * 60 )) % 24 ;
218- if (h > 0 ) {
219- textElapsed .setText ("00:00:00" );
220- textTotal .setText (String .format (Locale .US , "%d:%02d:%02d" , h , m , s ));
221- } else {
222- textElapsed .setText ("00:00" );
223- textTotal .setText (String .format (Locale .US , "%02d:%02d" , m , s ));
218+ if (textElapsed != null && textTotal != null ) {
219+ int total = getDuration ();
220+ if (total > 0 ) {
221+ seekBar .setMax (total );
222+ seekBar .setProgress (0 );
223+
224+ total = total / 1000 ;
225+ long s = total % 60 ;
226+ long m = (total / 60 ) % 60 ;
227+ long h = (total / (60 * 60 )) % 24 ;
228+ if (h > 0 ) {
229+ textElapsed .setText ("00:00:00" );
230+ textTotal .setText (String .format (Locale .US , "%d:%02d:%02d" , h , m , s ));
231+ } else {
232+ textElapsed .setText ("00:00" );
233+ textTotal .setText (String .format (Locale .US , "%02d:%02d" , m , s ));
234+ }
224235 }
225236 }
226237
227- videoControlsView .setVisibility (View .VISIBLE );
238+ if (videoControlsView != null )
239+ videoControlsView .setVisibility (View .VISIBLE );
228240 }
229241 }
230242
@@ -270,6 +282,8 @@ public void stop() throws IllegalStateException {
270282 }
271283
272284 protected void updateControls () {
285+ if (imgplay == null ) return ;
286+
273287 Drawable icon ;
274288 if (getCurrentState () == State .STARTED ) {
275289 icon = context .getResources ().getDrawable (R .drawable .fvl_selector_pause );
0 commit comments