4

我正在编写一个具有介绍视频的 android 应用程序,该视频是首先播放的 mp4 文件。用户可以触摸屏幕跳过它。

当我尝试在 android 模拟器上运行我的应用程序时,我得到一个“活动已泄漏窗口.. 最初添加”异常。在stackoverflow上有一篇关于它的大帖子说如果我的东西在完成后试图启动一个对话框。也许在我的情况下,播放器正在尝试启动一个对话框,说明播放器不支持我的视频格式。

好的..所以我只想跳过视频。没有它抛出错误和异常。

这是我的介绍活动:

package com.tuxin.findasmile;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
//import android.view.Menu; 
import android.view.MotionEvent;
import android.widget.VideoView;

public class IntroActivity extends Activity {

private VideoView video;
private boolean isMenuStarted=false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_intro);

    video = (VideoView) findViewById(R.id.videoView1);
    video.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        public boolean onError(MediaPlayer mp, int what, int extra) {
            Intent menu = new Intent(IntroActivity.this,MenuActivity.class);
            startActivity(menu);
            finish();
            return false;
        }
    });
    video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            if (!isMenuStarted) { 
                isMenuStarted=true;
            Intent menu = new  Intent(IntroActivity.this,MenuActivity.class);
            startActivity(menu);
            finish();
            }

        }
    });
    Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.seaofbuttons);
    video.setVideoURI(videoUri);
    video.start();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (video.isPlaying()) {
        video.stopPlayback();
    }
    if (!isMenuStarted) {
    isMenuStarted=true;
    Intent menu = new Intent(IntroActivity.this,MenuActivity.class);
    startActivity(menu);
    finish();
    }
    return false;

}


}

我知道模拟器不支持视频。但我想支持手机不支持这种视频格式的情况。我不希望抛出异常。

04-01 16:32:38.675: E/WindowManager(533): Activity com.tuxin.findasmile.IntroActivity has     leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052b9b0 that was originally added here
04-01 16:32:38.675: E/WindowManager(533): android.view.WindowLeaked: Activity com.tuxin.findasmile.IntroActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052b9b0 that was originally added here
04-01 16:32:38.675: E/WindowManager(533):   at android.view.ViewRoot.<init>(ViewRoot.java:258)
04-01 16:32:38.675: E/WindowManager(533):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-01 16:32:38.675: E/WindowManager(533):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-01 16:32:38.675: E/WindowManager(533):   at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-01 16:32:38.675: E/WindowManager(533):   at android.app.Dialog.show(Dialog.java:241)
04-01 16:32:38.675: E/WindowManager(533):   at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
04-01 16:32:38.675: E/WindowManager(533):   at android.widget.VideoView$4.onError(VideoView.java:386)
04-01 16:32:38.675: E/WindowManager(533):   at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1341)
04-01 16:32:38.675: E/WindowManager(533):   at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 16:32:38.675: E/WindowManager(533):   at android.os.Looper.loop(Looper.java:123)
04-01 16:32:38.675: E/WindowManager(533):   at android.app.ActivityThread.main(ActivityThread.java:3683)
04-01 16:32:38.675: E/WindowManager(533):   at java.lang.reflect.Method.invokeNative(Native Method)
04-01 16:32:38.675: E/WindowManager(533):   at java.lang.reflect.Method.invoke(Method.java:507)
04-01 16:32:38.675: E/WindowManager(533):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-01 16:32:38.675: E/WindowManager(533):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-01 16:32:38.675: E/WindowManager(533):   at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

3

尽管我认为这个问题的答案会很复杂。我需要做的就是在 onError 函数中返回 true。

问题是它试图显示一个对话框,其中包含无法查看视频的错误消息。我没有看到它,因为我已经转到下一个活动,所以这个对话框被泄露了,我看到了这个异常。

将 onError 返回从 false 更改为 true 将更改 VideoView 的行为,而不是创建带有消息的对话框,因此不会泄漏任何内容。

Android 移除 videoview 弹出消息

于 2013-04-01T13:58:59.347 回答