机器人(三星S4)HTML5视频暂停机器人、视频

2023-09-04 04:03:55 作者:萌哒哒

我使用Android的web视图播放HTML5视频,包括YouTube视频(我自己的标签和YouTube嵌入iFrame中)。 我与三星Galaxy S4中遇到的问题,对以下情形:

I am using Android Webview to play html5 videos, including Youtube videos (my own tags and Youtube embedded iFrames). I encountered an issue with Samsung Galaxy S4, on the following scenario:

播放视频。 preSS'回',而/视频播放之后(查看关闭) 再次打开视图和preSS'玩'。 在视频开始播放,并立即暂停。从这一时刻同样会发生的每个视频,我会尽力发挥。

我想这对一个测试环境,两种Webviews的:常规Android的web视图和 HTML5 web视图

I tried this on a test environment with two kind of Webviews: "regular" Android Webview and HTML5 webview

唯一的可疑的事情,我看到的是,而pressing的'回'(Android的错误)的错误:

The only "suspicious" thing I see is an error while pressing the 'back' (Android error):

sendUserActionEvent() mView == null

难道是银河S4的问题?一个Android的问题?你知道吗?

Is it a Galaxy S4 issue? An Android issue? Any idea?

TNX, 亚尼夫

推荐答案

看来,如果 AudioService 没有焦点,当您关闭 web视图,它不会暂停。这将导致几个问题(另一个球员无法开始播放等。)

It appears that if the AudioService does not have focus when you close the Webview, it is not paused. This causes several issues (another player cannot start playing etc.)

这工作对我来说,唯一的解决办法是:

The only solution that worked for me is:

@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);
}

这将导致当前玩家被暂停/杀死(不知道这)当下去,解决所有的经验问题/问题。

This will cause the current player to be paused/killed (not sure which) when going down and solve all of the experienced issues/problems.