Opening an activity with a webview containing a HTML5 video for a second time
Asked Answered
C

1

1

I am serving video's in a webview in Android using Appcelerator Titanium. On iOS this works like a charm. But on Android this gives some problems. It goes wrong the second time an activity is opened with a webview that holds a html5 video element.

Steps to reproduce:

(Also see this youtube video: http://www.youtube.com/watch?v=0MpSpfJNyOk )

The first time opening a video/activity with html5 video it shows the video and I am able to play it. When I close the window/activity and open a new window with another video the webview loads and the html5 video play loads as well. But playing it is not possible. When pressing the fullscreen button and pressing the play/pause button twice the video begins to play in fullscreen.

When pausing the video before closing the activity/window the video in the next window is able to play.

The youtube video shows the behavior on a Samsung Galaxy Tab 3 10.1" running Android 4.2 using this test project https://dl.dropboxusercontent.com/u/1849335/WebviewTest.zip

You can understand it took me a while to understand this pattern :)

Context:

I am using the 3.2.GA Titanium SDK with this fix (https://github.com/appcelerator/titanium_mobile/pull/5150) merged. In that change they fixed that the onPause() method should always be called on the webview when closing a activity otherwise the plugin processes will continue to play.

The files that are responsible for this behavior are: https://github.com/wienke/titanium_mobile/tree/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview https://github.com/wienke/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java

Curious if people also see this behavior without Titanium.

Cherida answered 28/12, 2013 at 13:5 Comment(0)
C
0

The solution was eventually provided in this question:

Android (Samsung S4) HTML5 video pauses

Adding this:

pause();
((AudioManager)activity.getSystemService(
                activity.AUDIO_SERVICE)).requestAudioFocus(
                        new OnAudioFocusChangeListener() {
                            @Override
                            public void onAudioFocusChange(int focusChange) {}
                        }, AudioManager.STREAM_MUSIC, 
                        AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

to the SDK onPause method here:

https://github.com/wienke/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java#L427

fixed the problem.

I filed a defect to Appcelerator. Hope they include this soon in their SDK.

Cherida answered 30/12, 2013 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.