Dealing With Interruptions on Android Devices

How can I minimize my app and resume streaming or deal with other interruptions on an Android device?

ANSWER:

Here is a guide of how you could potentially write the code to allow the Android app to deal with interruptions. Please note this is intended as a basic guide and will need some custom work in order to integrate it into your application. If you have any issues getting this to work, please feel free to contact the support team.

Pausing and Resuming Recording on Android InterruptionsIn this guide, we will show how to resume a broadcast from an Android Interruption, such as a Phone Call or Minimizing App.

Scenario 2: Return from Interrupt resumes broadcast session*Given* I have started a broadcast session*And* I receive an interrupt in my App (e.g., Phone Call, Minimizing App)*When* I return from the interrupt (e.g., Decline of Phone Call)*Then* My recording is resumed from the point of interruption

Scenario 3: Return from Background does not resume broadcast session*Given* I have started a broadcast session*And* I receive an interrupt in my App (e.g., Phone Call, Minimizing App)*When* I enter my App into the background (e.g., Accept of Phone Call)*And* I re-launch the App*Then* A new broadcast session is started

ImplementationIn order to implement the expectations of our feature specification, we need to first establish the Givens in of our scenarios which describe the creation of a broadcast session.

BaseWe will use an R5VideoViewController from the Red5 Pro SDK as the base for our broadcast session and logic for maintaining our interrupt and background recording feature specifications.

For additional information on creating a ViewController for streaming on Android, visit the documentation.

resume:streamNameThe resume:streamName method is relatively similar to the start:streamName method, however in resume: we do not assign the class-local streamName (using its value already defined) and specify the R5RecordTypeAppend type:

When your Android device enters an "interrupt", your application is still active - meaning not in the background - and is waiting for a response to the interrupt. Such interruptions can be a Phone Call or Minimizing the App. During such interruptions, the User action will determine the following state and notification.

If you chose, for instance, to Decline a phone call, the subsequent method triggered will be onResume. If you chose to Accept the phone call, the subsequent method triggered will be onStop and your App will be put into the background.

onPauseThe onPause method is triggered on the observer when the device enters an "interrupt". In such a case, we want to stop or broadcast session, but retain the possibility of resuming the broadcast if the user declines or dismisses the "interrupt" without the application going into the background. A most common case is the Decline of an incoming Phone Call.

We first check if we have a stream established and are currently in a publishing session. If so, then we can consider the app in an isResumable state if we were to come back from an "interrupt" without the app going into the background.

onResumeThe onResume method is triggered in two cases:* User has declined an interrupt* The App is launched from the background

In the first case, we have defined the App in an isResumable state in case we return from an "interrupt" without sending the App into the background. In such as case, we want to invoke the resume:streamName method:

In the second case, we do not want to consider the broadcast resumable. As such, we need to handle when the App does go into the background following an "interrupt".

onStop

@Overridepublic void onStop () { isResumable = false; stop();}

ConclusionIn this example, we created a resumable broadcast from an Android interrupt - such as from a Decline from Phone Call. We used the R5RecordTypeAppend option for R5Stream:publish:type when the App was considered in an isResumable state following an "interrupt" without sending the App into the background.