0

我用两个 Activity 制作了一个应用程序 android。我的第二个活动包含一个 youtube 视频嵌入。当我启动此活动并运行此视频时,它可以工作。但是当我关闭我的活动时,如果我的视频正在播放,我的活动已关闭,但我会听到视频的声音。我认为我的视频并没有真正关闭,她正在后台播放。

你能帮助我吗?

谢谢 !

编辑:我在我的 MyActivity 中建立了一个测试,我有同样的问题。

public class MyActivity extends Activity implements MBAdListener{

private FrameLayout layout;

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    RelativeLayout adViewContainer = (RelativeLayout) findViewById(R.id.adView);
    layout = new FrameLayout(this);

    layout.setLayoutParams(new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT,
            Gravity.CENTER)
    );
    layout.setBackgroundColor(Color.BLUE);
    setContentView(layout);
    WebView content = new WebView(this);
    content.setLayoutParams(new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT,
            Gravity.CENTER
    ));
    content.setHorizontalScrollBarEnabled(false);
    content.setVerticalScrollBarEnabled(false);
    content.getSettings().setJavaScriptEnabled(true);
    content.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    content.getSettings().setBuiltInZoomControls(false);
    content.getSettings().setSupportZoom(true);
    content.getSettings().setUseWideViewPort(true);
    content.getSettings().setPluginsEnabled(true);
    content.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    content.getSettings().setSavePassword(true);
    content.getSettings().setSaveFormData(true);
    content.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    layout.addView(content);

    content.loadData("<iframe width=\"320\" height=\"200\" src=\"http://www.youtube.com/embed/vCXRt0kQvUE?autoplay=1\" frameborder=\"0\" allowfullscreen></iframe>", "text/html", "UTF-8");

}
4

1 回答 1

1

我找到了这个,它有效!!!!请参阅以下有关如何停止在 Android webview 中播放 youtube 视频的帖子?

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

  try {
    Class.forName("android.webkit.WebView")
      .getMethod("onPause", (Class[]) null)
      .invoke(webview, (Object[]) null);
  } catch(ClassNotFoundException cnfe) {
      ...
  } catch(NoSuchMethodException nsme) {
      ...
  } catch(InvocationTargetException ite) {
      ...
  } catch (IllegalAccessException iae) {
      ...
  }
}
于 2013-04-05T16:16:41.110 回答