Share:
Hey, we were doing fine before this happened
So, around the same time, one of our clients in the Edtech industry came up with an unusual request. They wanted to provide their users with editable notes which can be accessed while watching the video lectures. Their current process required the users to switch frequently between the apps and, let’s just say, it was not as fancy as it sounds.The course is too much and there’s an issue, it’s not okay
As much as reasonable the problem was, the solution was not easy. We knew the PIP feature was godsent for this, but it was used by a few popular apps only. We talked to the client about it and they were pretty excited. In fact, the client said that if this works out, they will scale it up and add notes for all the sessions. Their users have asked for the same quite often and PIP might just be the answer to everything. We researched around the feature and it was one of the projects where things looked easy from far. Excited and scared, we went ahead and planned the development process. It was about to be a fun ride, or so we hoped!Hey, can you tell your friends we need it sooner
We began with the project and planned sprints. This was going to be one of those projects where things either worked or they tanked, no in-betweens. Even though Android launched a complete guide on how you can include the feature in your app, significant things had to be planned. The app’s primary service was to provide the lectures and under no circumstance, the efficiency of the same could be compromised.And I hope it’s gonna be fine and working again
We started stepping up the ladder with basic functions including: Declaring PIP Support: The system does not automatically support PIP for apps. We had to register the video activity by settingandroid:supportsPictureInPicture
and android:resizeableActivity
to true. We had to also include room for layout changes in the code so that the activity doesn’t relaunch when layout changes happen in PIP transitions.
Switching Activities: To enter the PIP mode we called a function enterPictureInPictureMode()
and further added a logic that switches an activity into PIP mode instead of running in the background.
UI during PIP Mode: When the function enters the PIP mode the system calls Activity.onPictureInPictureModeChanged()
or Fragment.onPictureInPictureModeChanged()
. We overrode these callbacks to redraw the UI elements in the activity.
Adding these basic functions got the PIP mode running. The client was not completely sure and hence, went ahead with initial testing. The application worked fine, at least prima facie. But there was a small problem. When the users tapped the back button to switch to the app from the pinned video, the app unexpectedly closed. In short, the user couldn’t restore the app.
So can we pull over and get rid of this once and for ever
It took a while for us to figure this out. The thing is, when you switch to the PIP mode, Android moves only the PIP activity into a new task. This causes a problem if the user stays within the app after restoring the PIP window back to full screen and tapping back. The app must re-create the back-stack to accomplish this. We understood what was happening within the whole process and why the user can’t restore the app. Due to application’s current architecture, back-stack recreation was happening automatically. To resolve the problem we went through many tests to find out where we were losing the back-stack process. This was our gateway. We added a link after the notes which redirected the student to the video. Another problem popped up when we were at our final stages of testing. The video playback in the PIP mode was causing audio intervention for other apps. To manage the video playback and other apps, we called a functionrequestAudioFocus()
and supplied a parameter AudioFocusRequest. Further, we used this parameter to request and abandon focus.