Flash video keeps playing even after back button is pressed android

放肆的年华 提交于 2019-12-31 04:37:10

问题


So I've created a WebView and set the content to an html string like so (This gets called when a user presses a ListView Item):

String html = "<html>" +
    "<body style=\"padding:0px;margin:0px;border:0px none;\">" +
    "<embed type=\"application/x-shockwave-flash\"" +
    " id=\"stratos_embed\"" +
    " width=\"100%25\" height=\"100%25"\"" + //%25 = % (escaped)
    " src=\"myVideoSource.swf\"" +
     " pluginspage=\"http://www.macromedia.com/go/getflashplayer\"" +
     " allowfullscreen=\"true\" allowscriptaccess=\"always\">" +
     "</embed>" +
"</body></html>";


Intent intent = new Intent(getBaseContext(), VideoActivity.class);
intent.putExtra("VIDEO_CONTENT", html);
this.startActivity(intent);

I can watch the flash video in the web video and everything's dandy.

The problem is when I press the back button the video continues to play (I can hear the audio) but I don't want it to.

I've read about using finish() to kill the activity but I'm not sure where to use it. I put it in my VideoActivity class like so:

@Override
public void onPause(){
    finish();
}

But when I press the back button, an error occurs and the app is forced closed.


回答1:


For Honeycomb+ targets, you can add calls to the WebView's onPause() and onResume() in your activity's onPause() and onResume():

// assuming mWebView is assigned in onCreate() ..

@Override
public void onPause() {
    super.onPause();
    mWebView.onPause();
}

@Override
public void onResume() {
    super.onResume();
    mWebView.onResume();
}

Alternatively (and since those methods are hidden for earlier targets), the following should work too:

@Override
protected void onDestroy() {
    super.onDestroy();
    mWebView.loadUrl("about:blank");
}



回答2:


Above methods didn't work for me, I came across another post that did the business here.

try {
    Class.forName("android.webkit.WebView")
            .getMethod("onPause", (Class[]) null)
                        .invoke(webview, (Object[]) null);
} catch(Exception e) {}


来源:https://stackoverflow.com/questions/8074601/flash-video-keeps-playing-even-after-back-button-is-pressed-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!