@@ -260,15 +260,9 @@ private VideoStreamingParameters tryStartVideoStream(boolean isEncrypted, VideoS
260260 videoServiceStartResponseReceived = false ;
261261 videoServiceStartResponse = false ;
262262
263- session .startService (SessionType .NAV , session .getSessionId (), isEncrypted );
264263 addVideoServiceListener ();
265- FutureTask <Void > timeoutTask = new FutureTask <>(new TimeoutCallable (RESPONSE_WAIT_TIME ));
266- ScheduledExecutorService scheduler = Executors .newSingleThreadScheduledExecutor ();
267- scheduler .execute (timeoutTask );
264+ session .startService (SessionType .NAV , session .getSessionId (), isEncrypted );
268265
269- //noinspection StatementWithEmptyBody
270- while (!videoServiceStartResponseReceived && !timeoutTask .isDone ()) ;
271- scheduler .shutdown ();
272266 }
273267
274268 if (videoServiceStartResponse ) {
@@ -288,6 +282,8 @@ private void addVideoServiceListener() {
288282 videoServiceListener = new ISdlServiceListener () {
289283 @ Override
290284 public void onServiceStarted (SdlSession session , SessionType type , boolean isEncrypted ) {
285+ videoServiceStartResponseReceived = true ;
286+ videoServiceStartResponse = true ;
291287 }
292288
293289 @ Override
@@ -314,29 +310,20 @@ public void onServiceError(SdlSession session, SessionType type, String reason)
314310 * @return true if the video service is closed successfully, return false otherwise
315311 */
316312 @ Override
317- boolean endVideoStream () {
313+ void endVideoStream () {
318314 if (session == null ) {
319315 DebugTool .logWarning ("SdlSession is not created yet." );
320- return false ;
316+ return ;
321317 }
322318 if (!session .getIsConnected ()) {
323319 DebugTool .logWarning ("Connection is not available." );
324- return false ;
320+ return ;
325321 }
326322
327323 videoServiceEndResponseReceived = false ;
328324 videoServiceEndResponse = false ;
329325 session .stopVideoStream ();
330326
331- FutureTask <Void > timeoutTask = new FutureTask <>(new TimeoutCallable (RESPONSE_WAIT_TIME ));
332- ScheduledExecutorService scheduler = Executors .newSingleThreadScheduledExecutor ();
333- scheduler .execute (timeoutTask );
334-
335- //noinspection StatementWithEmptyBody
336- while (!videoServiceEndResponseReceived && !timeoutTask .isDone ()) ;
337- scheduler .shutdown ();
338-
339- return videoServiceEndResponse ;
340327 }
341328
342329 @ Override
@@ -358,49 +345,18 @@ void startAudioService(boolean isEncrypted) {
358345 * @return true if the audio service is closed successfully, return false otherwise
359346 */
360347 @ Override
361- boolean endAudioStream () {
348+ void endAudioStream () {
362349 if (session == null ) {
363350 DebugTool .logWarning ("SdlSession is not created yet." );
364- return false ;
351+ return ;
365352 }
366353 if (!session .getIsConnected ()) {
367354 DebugTool .logWarning ("Connection is not available." );
368- return false ;
355+ return ;
369356 }
370357
371358 audioServiceEndResponseReceived = false ;
372359 audioServiceEndResponse = false ;
373360 session .stopAudioStream ();
374-
375- FutureTask <Void > timeoutTask = new FutureTask <>(new TimeoutCallable (RESPONSE_WAIT_TIME ));
376- ScheduledExecutorService scheduler = Executors .newSingleThreadScheduledExecutor ();
377- scheduler .execute (timeoutTask );
378-
379- //noinspection StatementWithEmptyBody
380- while (!audioServiceEndResponseReceived && !timeoutTask .isDone ()) ;
381- scheduler .shutdown ();
382-
383- return audioServiceEndResponse ;
384- }
385-
386- /**
387- * This is a small class that's only purpose is to be a waiting type callable.
388- */
389- private class TimeoutCallable implements Callable <Void > {
390- private final long waitTime ;
391-
392- public TimeoutCallable (int timeInMillis ) {
393- this .waitTime = timeInMillis ;
394- }
395-
396- @ Override
397- public Void call () {
398- try {
399- Thread .sleep (waitTime );
400- } catch (InterruptedException e ) {
401- e .printStackTrace ();
402- }
403- return null ;
404- }
405361 }
406362}
0 commit comments