question

Chris avatar image
Chris asked

Whisperplay Service Lifecycle

1. What is the exact lifecycle of the whisperplay service implementation (when implementing it with a fire tv app written in android studio)?

2. When the app is closed, the whisperplay service is still running. Hence the service must handle activity starts, doesn't it?

3. What can i do to ensure that all status listeners are handled correctly and no status update is sent twice (or even more) when connecting and disconnecting from whisperplay multiple times (in the mobile app)?

Thanks for your answers!

fire tvandroidamazon fling
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Levon@Amazon avatar image
Levon@Amazon answered

Hi Chris,

Thanks for posting!

1. WhisperPlay starts on Fire OS startup and should always be available.

2. Yes.

3. You might need to clarify your question. The functionality of status listeners depends on your application needs. The most common implementation would keep a list of the listeners and loop through them when sending out status updates. When disconnecting from your service, on the client side you should remove status listeners associated with that connection using the removeStatusListener API on RemoteMediaPlayer.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Chris avatar image
Chris answered

Thanks for the response!

1. Then what does the createServiceImplementation() and the onDisconnectedFromWhisperplay() listener functions mean?

3. I had a problem with the status listeners. The listener should simply send status updates of whether the music playback is running or not. At first the listener was only called the first time a sender device connected (after createServiceImplementation() was called) and if the device disconnected and then reconnected to the fire tv app, no status updates where sent. Then after changing some code (listeners where registered when sending play command - old listener was unregistered before registering a new one - and not when connected to the fire tv in the android app and only 1 listener is saved in the fire tv app), the listener was called twice or more times, depending on how often i reconnected with the sender device. I was wondering if the whisperplay service was instantiated more than one time or if there might be a problem with the service running the MediaHostService?

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Levon@Amazon avatar image
Levon@Amazon answered

1. About createServiceImplementation() and onDisconnectedFromWhisperplay()

- createServiceImplementation() It is needed when creating a service on FireTV that will talk to the controller app on your client device. It should return your implementation of CustomMediaPlayer. See https://developer.amazon.com/public/apis/experience/fling/docs/integrating-amazon-fling-into-your-fire-tv-app for a guide.

- onDisconnectedFromWhisperplay() - This is extremely unlikely to happen. It is there in case there is a problem in the underlying library which causes the service to not be able to be seen by clients and keeps clients from communicating with the service.

3. The issue looks like is with registering - either in controller app or in the service app

- On the controller app listeners need to be unregistered using the removeStatusListener API before the connection is terminated.

- On the FireTV service/app you need to implement addStatusListener/removeStatusListener [ suggestion - use the Whisperplay based built in DefaultMediaReceiver to test your controller app and to figure out where is the issue]

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@Levon How should developers handle onDisconnectedFromWhisperplay() events? My guess is that the MediaPlayerHostService should kill itself by calling stopSelf()? Any other recommendations?

0 Likes 0 ·