Menu

1 / 2

how i got real picture-in-picture in a 1.17 mb webview player without shipping a native lib

DEV Community: android·hammi·10 days ago
#P8wz6qqx
#devtoandroid#devto#dev#android#webview
Reading 0:00
15s threshold

hammi

Posted on Nov 6

Edited on Nov 6

i'm the developer of rkmovies, a 4k media player that runs as a web app inside a thin android webview shell. the whole apk is 1.17 mb because it bundles zero native media libraries. playback uses the system's mediacodec decoders through artplayer.

one feature people asked for constantly: picture-in-picture. you open whatsapp mid-episode and the video keeps playing in a floating window.

in a webview you can't call an android api directly. you only get what the browser engine exposes. so the pip toggle in the settings menu is a four-layer fallback chain:

if document.pictureInPictureElement is set, the video is already in pip. call exitPictureInPicture() to toggle off.

otherwise try art.video.requestPictureInPicture(). that's the w3c api, and chrome supports it from android 8.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.