Android的 - 解雇网页视图与HTML5视频 [英] Android - dismissing Webview with html5 video

查看:108
本文介绍了Android的 - 解雇网页视图与HTML5视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是网页视图,扮演不同的HTML5视频(内部变量和YouTube视频)。

I'm using a Webview, playing different html5 videos (internal tag and Youtube videos).

在最后,我试图加载一个空白页+隐藏视图+暂停的WebView web视图。 web视图似乎是正确关闭,视频停止播放。

When closing the Webview I tried loading a blank page + hiding the view + pausing the webview. The Webview seems to be closed correctly and the video stops playing.

问题是银河S4 + S2,再次打开网页视图和播放其他视频时。正在播放后,立即新的视频被暂停。当我preSS玩了,视频会自动再次暂停。这将与每一个视频,我会尝试加载(YouTube和内部),直到我就杀了我的应用程序发生。杀死我的应用程序后,一切都将重新正常工作。
有没有可能是第一个视图/视频无法终止,每一个新的视频将自动暂停,以prevent两个在同一时间玩?

The problem is on Galaxy S4 + S2, when opening the Webview again and playing another video. The new video is been paused immediately after being played. When I press "play" again, the video is automatically paused again. This will happen with every video that I'll try to load (Youtube and internal ), until I'll kill my app. After killing my app everything will work normally again. Is it possible that the first view/video is not terminated so each new video will automatically be paused, in order to prevent the two to play at the same time?

TNX!

亚尼夫

推荐答案

这个问题了几天的挣扎后,我找到了解决办法。看来,在关闭网页视图时,可能无限灵没有焦点,其中prevented他从暂停/解聘。这prevented所有其他网页视图与Mediaplayers从玩(每次自动暂停试图播放,没有能力恢复)。

After struggling with this issue for few days, I found the solution. It appears that when closing the Webview, the Mediaplay probably did not have focus, which prevented him from pausing/dismissing. This prevented all other Webviews with Mediaplayers from playing (automatically paused each time trying to play, with no ability to resume).

在添加此code:

@Override
protected void onPause() {
    super.onPause();

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

问题得到彻底解决。该媒体播放器被驳回/暂停(不知道它,必须检查),并用​​新的媒体播放器一个新的网页视图能够获得焦点和正常播放。

The problem was completely solved. The Mediaplayer was dismissed/paused (not sure which, have to check), and a new Webview with a new Mediaplayer can gain focus and play normally.

希望它可以帮助其他人有这个问题苦苦挣扎。

Hope it could help other people struggling with this issue..

这篇关于Android的 - 解雇网页视图与HTML5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆