我正在测试一个简单的应用程序,它使用 VideoView 从互联网播放 http/rtsp 视频。该应用程序在 3.3 之前的 2.2 版本中运行良好,但是当我在 4.0 及更高版本上对其进行测试时,崩溃!!!(在模拟器和真实手机上都测试过:-/)
谁能给我一个提示为什么?
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText android:id="@+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<VideoView android:id="@+id/surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<ImageButton android:id="@+id/play"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/play"/>
</LinearLayout>
</LinearLayout>
.java文件:
public class Video extends Activity {
private static final String TAG = "VideoViewDemo";
private VideoView mVideoView;
private EditText mPath;
private ImageButton mPlay;
private Uri current;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.video);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mPath = (EditText) findViewById(R.id.path);
mPath.setText("http://daily3gp.com/vids/747.3gp");
playVideo();
mPlay = (ImageButton) findViewById(R.id.play);
mPlay.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
playVideo();
}
});
runOnUiThread(new Runnable(){
public void run() {
playVideo();
}
});
}
private void playVideo() {
try {
//final String path = mPath.getText().toString();
Uri path = Uri.parse(mPath.getText().toString());
Log.v(TAG, "path: " + path);
if (path == null) {
Toast.makeText(Video.this, "File URL/path is empty",
Toast.LENGTH_LONG).show();
} else {
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = path;
mVideoView.setVideoURI(path);
mVideoView.start();
mVideoView.requestFocus();
}
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
if (mVideoView != null) {
mVideoView.stopPlayback();
}
}
}
}
这里是带有错误的 Logcat 文件:
11-09 17:25:32.582: E/WindowManager(538): Activity com.testing.interacciones.Video has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@413fb820 that was originally added here
11-09 17:25:32.582: E/WindowManager(538): android.view.WindowLeaked: Activity com.testing.interacciones.Video has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@413fb820 that was originally added here
11-09 17:25:32.582: E/WindowManager(538): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:343)
11-09 17:25:32.582: E/WindowManager(538): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:245)
11-09 17:25:32.582: E/WindowManager(538): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193)
11-09 17:25:32.582: E/WindowManager(538): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118)
11-09 17:25:32.582: E/WindowManager(538): at android.view.Window$LocalWindowManager.addView(Window.java:537)
11-09 17:25:32.582: E/WindowManager(538): at android.app.Dialog.show(Dialog.java:274)
11-09 17:25:32.582: E/WindowManager(538): at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
11-09 17:25:32.582: E/WindowManager(538): at android.widget.VideoView$4.onError(VideoView.java:382)
11-09 17:25:32.582: E/WindowManager(538): at android.widget.VideoView.openVideo(VideoView.java:240)
11-09 17:25:32.582: E/WindowManager(538): at android.widget.VideoView.access$2000(VideoView.java:49)
11-09 17:25:32.582: E/WindowManager(538): at android.widget.VideoView$6.surfaceCreated(VideoView.java:465)
11-09 17:25:32.582: E/WindowManager(538): at android.view.SurfaceView.updateWindow(SurfaceView.java:562)
11-09 17:25:32.582: E/WindowManager(538): at android.view.SurfaceView.access$000(SurfaceView.java:82)
11-09 17:25:32.582: E/WindowManager(538): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:171)
11-09 17:25:32.582: E/WindowManager(538): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
11-09 17:25:32.582: E/WindowManager(538): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1596)
11-09 17:25:32.582: E/WindowManager(538): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
11-09 17:25:32.582: E/WindowManager(538): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 17:25:32.582: E/WindowManager(538): at android.os.Looper.loop(Looper.java:137)
11-09 17:25:32.582: E/WindowManager(538): at android.app.ActivityThread.main(ActivityThread.java:4340)
11-09 17:25:32.582: E/WindowManager(538): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 17:25:32.582: E/WindowManager(538): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 17:25:32.582: E/WindowManager(538): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-09 17:25:32.582: E/WindowManager(538): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-09 17:25:32.582: E/WindowManager(538): at dalvik.system.NativeStart.main(Native Method)
11-09 17:25:38.494: D/ExchangeService(421): Received deviceId from Email app: androidc259148960
11-09 17:25:38.494: D/ExchangeService(421): Reconciling accounts...
11-09 17:25:40.621: W/ThrottleService(93): unable to find stats for iface rmnet0
11-09 17:28:46.553: D/dalvikvm(177): GC_CONCURRENT freed 458K, 6% free 10347K/10951K, paused 7ms+8ms
11-09 17:28:48.562: I/dalvikvm(93): Jit: resizing JitTable from 4096 to 8192
11-09 17:30:29.982: I/Process(538): Sending signal. PID: 538 SIG: 9
11-09 17:30:30.122: I/ActivityManager(93): Process com.testing.interacciones (pid 538) has died.
11-09 17:30:30.132: W/InputDispatcher(93): channel '41650408 com.testing.interacciones/com.testing.interacciones.Splash (server)' ~ Consumer closed input channel or an error occurred. events=0x8
11-09 17:30:30.132: E/InputDispatcher(93): channel '41650408 com.testing.interacciones/com.testing.interacciones.Splash (server)' ~ Channel is unrecoverably broken and will be disposed!
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testing.interacciones"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Video"
android:label="@string/app_name" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
手机上的崩溃错误只是说“不幸的是,Test VideoView 已停止”
提前谢谢!