机器人的WebView HTML5视频派生的MediaPlayer,生活永远在三星S4 [乱砍找到答案] [英] Android WebView HTML5 Video Spawns MediaPlayer that lives forever on Samsung S4 [Hacked answer found]

查看:385
本文介绍了机器人的WebView HTML5视频派生的MediaPlayer,生活永远在三星S4 [乱砍找到答案]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我已经能够找到,这似乎是具体到近期的三星设备。在S4将做到这一点。 Nexus的7不会。

From what I have been able to find out, this seems to be specific to recent Samsung devices. The S4 will do this. The Nexus 7 will not.

如果有WebChromeClient一个的WebView开始播放的HTML5视频,它会创建一个MediaPlayer的实例。一旦视频结束,但似乎没有一种方法杀死System.exit的MediaPlayer的短(0)。

If a WebView with a WebChromeClient begins to play an HTML5 video, it creates a MediaPlayer instance. Once the video is over, there doesn't seem to be a way to kill the MediaPlayer short of System.exit(0).

这是我整个MainActivity.java

This is my entire MainActivity.java

package com.test.webviewtest;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class MainActivity extends Activity {
    WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        webView = new WebView(this);
        webView.setWebChromeClient(new WebChromeClient());
        String html = "<video width=\"320\" height=\"240\" controls autoplay>" +
                "<source src=\"http://www.w3schools.com/html/movie.mp4\" " +
                "type=\"video/mp4\"></video>";
        webView.loadData(html, "text/html", null);
        setContentView(webView);
    }

    @Override
    protected void onPause(){
        super.onPause();
        // attempt to kill the MediaPlayer here...
    }

}

和自然这是需要在清单

<uses-permission android:name="android.permission.INTERNET"/>

只要你点击视频,logcat的开始吐出MediaPlayer的消息,它从不停止。有有用的,而在视频播放,但在那之后,它只是记录

As soon as you click the video, logcat starts spitting out MediaPlayer messages and it NEVER STOPS. There are useful ones while the video is playing but after that, it just logs

02-25 17:13:19.395     220-8584/? V/MediaPlayerService﹕ [470] notify (0x51b7aa00, 3, 100, 0)
02-25 17:13:19.395    8532-8610/? V/MediaPlayer﹕ message received msg=3, ext1=100, ext2=0
02-25 17:13:19.395    8532-8610/? V/MediaPlayer﹕ buffering 100
02-25 17:13:19.395    8532-8610/? V/MediaPlayer﹕ callback application
02-25 17:13:19.405    8532-8610/? V/MediaPlayer﹕ back from callback
02-25 17:13:20.406     220-8584/? V/MediaPlayerService﹕ [470] notify (0x51b7aa00, 3, 100, 0)
02-25 17:13:20.406    8532-8544/? V/MediaPlayer﹕ message received msg=3, ext1=100, ext2=0
02-25 17:13:20.406    8532-8544/? V/MediaPlayer﹕ buffering 100
02-25 17:13:20.406    8532-8544/? V/MediaPlayer﹕ callback application
02-25 17:13:20.406    8532-8544/? V/MediaPlayer﹕ back from callback
02-25 17:13:21.407     220-8584/? V/MediaPlayerService﹕ [470] notify (0x51b7aa00, 3, 100, 0)
02-25 17:13:21.407    8532-8611/? V/MediaPlayer﹕ message received msg=3, ext1=100, ext2=0
02-25 17:13:21.407    8532-8611/? V/MediaPlayer﹕ buffering 100
02-25 17:13:21.407    8532-8611/? V/MediaPlayer﹕ callback application
02-25 17:13:21.417    8532-8611/? V/MediaPlayer﹕ back from callback

和这种重复永远不会结束,直到你强制关闭或卸载或别的东西激烈。 我已经尝试过:

And this repetition never ends until you force close or uninstall or something else drastic. I have already tried:

  • webView.onPause(); 这可以暂停视频,以便停止在后台播放,但不杀的MediaPlayer
  • webView.destroy(); 仍然不停止僵尸的MediaPlayer
  • web视图= NULL; 没了
  • web视图=新的WebView(本); 还是没了
  • 结束();
  • 我也试着得到一个保留的WebChromeClient,并摧毁它的各种方法,但没有任何工程。
  • webView.onPause(); This pauses the video so it stops playing in the background, but does not kill the MediaPlayer.
  • webView.destroy(); Still doesn't stop that zombie MediaPlayer
  • webView = null; nope
  • webView = new WebView(this); still nope
  • finish();
  • I've also tried various ways of getting a hold of the WebChromeClient and destroying it, but nothing works.

我尝试更多的东西,我会更新这个列表。鸭preciate的帮助。

I'll update this list as I try more things. Appreciate the help.

  • 我现在也尝试重定向web视图非视频内容 webView.loadData(喜,text / html的,NULL); 还活着。 ..
  • I've now also tried redirecting the webView to non video content with webView.loadData("hi", "text/html", null); still alive...

HACKED答案

嗯,这是最好的我能找到。如果有人有一个更好的解决方案,请还是让我知道。

Well this is the best I can find. If someone has a better solution, please still let me know.

为了获得的MediaPlayer 停止,我告诉它进入页面有一个&LT;视频&GT; 标记,指出除视频以外的其他。

In order to get the MediaPlayer to stop, I told it to go to page with a <video> tag that pointed to something other than a video.

String html = "<video width=\"320\" height=\"240\" controls>" +
    "<source src=\"http://www.w3schools.com/html/NOT_A_MOVIE.mp4\" " +
    "type=\"video/mp4\"></video>";
webView.loadData(html, "text/html", null); 

当我做到这一点,我在屏幕上看到一个视频播放器,当我点击播放按钮,它会记录

When I do this, I see a video player on screen and when I click the play button, it logs

02-26 12:26:37.112    220-11354/? V/MediaPlayerService﹕ [576] notify (0x47fa92b8, 100, 1, -1004)
02-26 12:26:37.112  11264-11325/com.test.webviewtest V/MediaPlayer﹕ message received msg=100, ext1=1, ext2=-1004
02-26 12:26:37.112  11264-11325/com.test.webviewtest E/MediaPlayer﹕ error (1, -1004)
02-26 12:26:37.112  11264-11325/com.test.webviewtest V/MediaPlayer﹕ callback application
02-26 12:26:37.112  11264-11325/com.test.webviewtest V/MediaPlayer﹕ back from callback
02-26 12:26:37.122  11264-11264/com.test.webviewtest E/MediaPlayer﹕ Error (1,-1004)

从这点上来说,的MediaPlayer 似乎主要死亡(仅略活着)。它停止所有的日志活动,这是所希望的结果。它剩下的唯一痕迹是当你强行关闭应用程序,你还是会看到这一点。

From this point on, the MediaPlayer seems to be mostly dead (only slightly alive). It ceases all logging activity, which is the desired result. The only trace of it remaining is when you force close the app, you will still see this.

02-26 12:29:35.826      220-738/? V/MediaPlayerService﹕ Client(576) destructor pid = 11264
02-26 12:29:35.836      220-738/? V/MediaPlayerService﹕ disconnect(576) from pid 11264
02-26 12:29:35.836      220-738/? W/MediaPlayerService﹕ native_window_api_disconnect returned an error: Broken pipe (-32)

我确定与而是一个真正的解决方案将是很好。我明明丝打不好的视频自动播放这样的碰撞可以在后台发生,但是这是框架。

I'm ok with that but a real solution would be nice. I'll obviously wire up the bad video with autoplay so the crash can happen in the background, but that's the framework.

更新14年2月27日 虽然三星的设备这个修复的问题,它断裂等设备,所以这不是一个很好的解决方案。在其他设备上(的Nexus 7测试),这code将呈现的WebView没用任何未来的呼叫。我会更新这个时候我发现更多的信息。如果你从来没有需要渲染另一个的WebView对应用程序的生命周期的其余部分,我想这是好的,但我需要它能够在稍后加载其他页面。

UPDATE 2-27-14 While this 'fixes' the issue on Samsung devices, it does breaks other devices, so this is not a good solution. On other devices (Nexus 7 tested), this code will render the WebView useless to any future calls. I'll update this when I find more information. If you never need to render another WebView for the rest of the app's lifespan, I guess that's ok, but I need it to be able to load another page later.

推荐答案

对于我来说没有其他解决办法的工作比其他:

For me no other solution worked other than:

android.os.Process.killProcess(android.os.Process.myPid());

这附带了你无法创建内部活动的麻烦,但我已经克服了第二个进程。

This comes with the hassle that you can't actually create the activity from inside, but I've overcome that with a second process.

这篇关于机器人的WebView HTML5视频派生的MediaPlayer,生活永远在三星S4 [乱砍找到答案]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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