androidandroid-webviewandroid-configchanges

how to restore video play state in android webview


In my activity, I am loading you-tube video content into my web view like this:

webview.loadData("<iframe class=\"youtube-player\" " +
"type=\"text/html\" "+" src=\"http://www.youtube.com/embed/bIPcobKMB94\" frameborder=\"0\">", "text/html", "UTF-8");

which is loading you tube video. Upon clicking play button video is getting played. All this is working fine.

When I rotate the screen How can I restore the video state in web view means if video is played for 30 secs before rotation. I have to start from 31 sec after rotation. Applying

webview.saveState(bundle);
webview.restoreState(bundle); 

in onSave and onRestore life cycle methods doesn't work for me.


Solution

  • So far the best solution I found is - placing web view in Frame Layout and handling orientation changes by ourself. On Configuration changes, removing web view from Frame Layout and resetting main view after that adding web view to Frame Layout. link for working sample