我正在编写一个具有介绍视频的 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)