@@ -82,7 +82,7 @@ public class MediaPlayerFragment extends BaseFragment {
82
82
public Button jumpButton ;
83
83
public CheckBox loopingButton ;
84
84
85
- public static LaunchSession launchSession ;
85
+ public LaunchSession launchSession ;
86
86
87
87
public TextView positionTextView ;
88
88
public TextView durationTextView ;
@@ -97,14 +97,14 @@ public class MediaPlayerFragment extends BaseFragment {
97
97
98
98
public boolean mSeeking ;
99
99
public Runnable mRefreshRunnable ;
100
- public static final int REFRESH_INTERVAL_MS = (int ) TimeUnit .SECONDS .toMillis (1 );
100
+ public final int REFRESH_INTERVAL_MS = (int ) TimeUnit .SECONDS .toMillis (1 );
101
101
public Handler mHandler ;
102
102
public long totalTimeDuration ;
103
103
public boolean mIsGettingPlayPosition ;
104
104
105
105
106
- static boolean isPlayingImage = false ;
107
- static boolean isPlaying = false ;
106
+ boolean isPlayingImage = false ;
107
+ boolean isPlaying = false ;
108
108
109
109
private MediaControl mMediaControl = null ;
110
110
private PlaylistControl mPlaylistControl = null ;
@@ -317,21 +317,13 @@ private void playAudio() {
317
317
318
318
@ Override
319
319
public void onError (ServiceCommandError error ) {
320
- Log .d ("LG" , "Error playing audio" );
321
- if (launchSession != null ) {
322
- launchSession .close (null );
323
- launchSession = null ;
324
- testResponse = new TestResponseObject (false , error .getCode (), error .getMessage ());
325
- stopUpdating ();
326
- disableMedia ();
327
- isPlaying = isPlayingImage = false ;
328
- }
320
+ Log .d ("LG" , "Error playing audio" , error );
321
+ stopMediaSession ();
329
322
}
330
323
331
324
@ Override
332
325
public void onSuccess (MediaLaunchObject object ) {
333
326
Log .d ("LG" , "Started playing audio" );
334
-
335
327
launchSession = object .launchSession ;
336
328
testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode , TestResponseObject .Play_Audio );
337
329
mMediaControl = object .mediaControl ;
@@ -340,8 +332,6 @@ public void onSuccess(MediaLaunchObject object) {
340
332
stopUpdating ();
341
333
enableMedia ();
342
334
isPlaying = true ;
343
- disconnectWebAppSession ();
344
-
345
335
}
346
336
});
347
337
}
@@ -358,14 +348,8 @@ private void playM3U() {
358
348
359
349
@ Override
360
350
public void onError (ServiceCommandError error ) {
361
- Log .d ("LG" , "Error playing audio" );
362
- if (launchSession != null ) {
363
- launchSession .close (null );
364
- launchSession = null ;
365
- stopUpdating ();
366
- disableMedia ();
367
- isPlaying = isPlayingImage = false ;
368
- }
351
+ Log .d ("LG" , "Error playing audio" , error );
352
+ stopMediaSession ();
369
353
}
370
354
371
355
@ Override
@@ -377,7 +361,6 @@ public void onSuccess(MediaLaunchObject object) {
377
361
stopUpdating ();
378
362
enableMedia ();
379
363
isPlaying = true ;
380
- disconnectWebAppSession ();
381
364
}
382
365
});
383
366
}
@@ -391,32 +374,24 @@ private void showImage() {
391
374
String description = "Blender Open Movie Project" ;
392
375
String icon = "http://ec2-54-201-108-205.us-west-2.compute.amazonaws.com/samples/media/photoIcon.jpg" ;
393
376
394
- getMediaPlayer ().displayImage (imagePath , mimeType , title , description , icon , new MediaPlayer .LaunchListener () {
377
+ getMediaPlayer ().displayImage (imagePath , mimeType , title , description , icon , new
378
+ MediaPlayer .LaunchListener () {
379
+
380
+ @ Override
381
+ public void onError (ServiceCommandError error ) {
382
+ Log .e ("Error" , "Error displaying Image" , error );
383
+ stopMediaSession ();
384
+ }
395
385
396
386
@ Override
397
387
public void onSuccess (MediaLaunchObject object ) {
398
388
launchSession = object .launchSession ;
399
389
closeButton .setEnabled (true );
400
- testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode , TestResponseObject .Display_image );
390
+ testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode ,
391
+ TestResponseObject .Display_image );
401
392
closeButton .setOnClickListener (closeListener );
402
393
stopUpdating ();
403
394
isPlayingImage = true ;
404
- disconnectWebAppSession ();
405
-
406
- }
407
-
408
- @ Override
409
- public void onError (ServiceCommandError error ) {
410
- Log .e ("Error" , "Error displaying Image" );
411
- if (launchSession != null ) {
412
- launchSession .close (null );
413
- launchSession = null ;
414
- testResponse = new TestResponseObject (false , error .getCode (), error .getMessage ());
415
- stopUpdating ();
416
- disableMedia ();
417
- isPlaying = isPlayingImage = false ;
418
-
419
- }
420
395
}
421
396
});
422
397
}
@@ -441,31 +416,37 @@ private void playVideo() {
441
416
442
417
getMediaPlayer ().playMedia (mediaInfo , shouldLoop , new MediaPlayer .LaunchListener () {
443
418
419
+ @ Override
420
+ public void onError (ServiceCommandError error ) {
421
+ Log .e ("Error" , "Error playing video" , error );
422
+ stopMediaSession ();
423
+ }
424
+
444
425
public void onSuccess (MediaLaunchObject object ) {
445
426
launchSession = object .launchSession ;
446
- testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode , TestResponseObject .Play_Video );
427
+ testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode ,
428
+ TestResponseObject .Play_Video );
447
429
mMediaControl = object .mediaControl ;
448
430
mPlaylistControl = object .playlistControl ;
449
431
stopUpdating ();
450
432
enableMedia ();
451
433
isPlaying = true ;
452
- disconnectWebAppSession ();
453
- }
454
-
455
- @ Override
456
- public void onError (ServiceCommandError error ) {
457
- if (launchSession != null ) {
458
- launchSession .close (null );
459
- launchSession = null ;
460
- testResponse = new TestResponseObject (false , error .getCode (), error .getMessage ());
461
- stopUpdating ();
462
- disableMedia ();
463
- isPlaying = isPlayingImage = false ;
464
- }
465
434
}
466
435
});
467
436
}
468
437
438
+
439
+ private void stopMediaSession () {
440
+ // don't call launchSession.close() here, currently it can close
441
+ // a different web app in WebOS
442
+ if (launchSession != null ) {
443
+ launchSession = null ;
444
+ stopUpdating ();
445
+ disableMedia ();
446
+ isPlaying = isPlayingImage = false ;
447
+ }
448
+ }
449
+
469
450
@ Override
470
451
public void disableButtons () {
471
452
mSeekBar .setEnabled (false );
@@ -854,14 +835,6 @@ private String formatTime(long millisec) {
854
835
return time ;
855
836
}
856
837
857
- private void disconnectWebAppSession () {
858
- if (WebAppFragment .mWebAppSession != null ) {
859
- WebAppFragment .mWebAppSession .setWebAppSessionListener (null );
860
- WebAppFragment .mWebAppSession .close (null );
861
- WebAppFragment .isLaunched = false ;
862
- }
863
- }
864
-
865
838
private class DownloadImageTask extends AsyncTask <String , Void , Bitmap > {
866
839
ImageView bmImage ;
867
840
0 commit comments