2

I am developing a ChromeCast app that instances a YoutubeSupportFragment in the presentation display.

My problem is, when the app goes background, Youtube video is stopped. I've traced that YoutubeSupportFragment's onPause pauses the video.

Is there a way to somehow attach the fragment lifecycle to the CastRemoteDisplayLocalService so fragment's onPause is not called?

I've tried to set the fragment as retained with setRetainInstance but no luck :(

rupps
  • 9,712
  • 4
  • 55
  • 95

2 Answers2

1

I dont think there's a way of disabling onPause as it is at the core of the Anroid lifecycle.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • Yes, I guess, but given the deep stuff involved in launching a persistent chromecast session (strong references to objects, services, singletons, interaction with internal google play libraries ...) maybe Google has some magic deep inside that somebody here knows about. – rupps Nov 01 '16 at 04:54
0

I believe @noogui is correct in that you can't disable onPause. Making it easy to bind the state of fragments/activities to a persistent service would defeat the purpose of having fragments/activities; Android wants to be able to kill the YoutubeSupportFragment if memory runs low.

I haven't tried this, but there may be an alternative route. You can display an iframe in a receiver app per this answer, and there is an API for embedding the Youtube video player in an iframe. So instead of using the Cast RemoteDisplayAPI, why not write a custom receiver app to hold the video player? This should allow you to continue playing video whether or not the Android app is backgrounded.

Community
  • 1
  • 1
plátano plomo
  • 1,672
  • 1
  • 18
  • 26