大家好今天我面临一个意想不到的崩溃我的Android应用程序代码适用于所有设备,除了Micromax A250。我用来播放原始文件夹中的视频的代码如下所示:
if (mediaControls == null) {
mediaControls = new MediaController(AndroidVideoViewExample.this);
}
myVideoView = (VideoView) findViewById(R.id.video_view);
try {
myVideoView.setMediaController(mediaControls);
Uri uri=Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.samplevideo);
Log.d("URI", uri.toString());
myVideoView.setVideoURI(uri);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
myVideoView.start();
}
});
logcat痕迹是:
12-28 15:08:30.547:E / AndroidRuntime(21939):致命异常:主要 12-28 15:08:30.547:E / AndroidRuntime(21939): java.lang.StringIndexOutOfBoundsException:length = 11; regionStart = 0; regionLength = -1 12-28 15:08:30.547:E / AndroidRuntime(21939):at java.lang.String.startEndAndLength(String.java:583)12-28 15:08:30.547:E / AndroidRuntime(21939):at java.lang.String.substring(String.java:1464)12-28 15:08:30.547: E / AndroidRuntime(21939):at android.widget.VideoView.openVideo(VideoView.java:407)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.widget.VideoView $ 6.surfaceCreated(VideoView.java:727)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.SurfaceView.updateWindow(SurfaceView.java:606)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.SurfaceView.access $ 000(SurfaceView.java:88)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.SurfaceView $ 3.onPreDraw(SurfaceView.java:183)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:692) 12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123) 12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:4879) 12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.Choreographer $ CallbackRecord.run(Choreographer.java:776) 12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.Choreographer.doCallbacks(Choreographer.java:579)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.Choreographer.doFrame(Choreographer.java:548)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:762) 12-28 15:08:30.547:E / AndroidRuntime(21939):at android.os.Handler.handleCallback(Handler.java:725)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.os.Handler.dispatchMessage(Handler.java:92)12-28 15:08:30.547:E / AndroidRuntime(21939):at android.os.Looper.loop(Looper.java:153)12-28 15:08:30.547: E / AndroidRuntime(21939):at android.app.ActivityThread.main(ActivityThread.java:5297)12-28 15:08:30.547:E / AndroidRuntime(21939):at java.lang.reflect.Method.invokeNative(Native Method)12-28 15:08:30.547:E / AndroidRuntime(21939):at java.lang.reflect.Method.invoke(Method.java:511)12-28 15:08:30.547: E / AndroidRuntime(21939):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:833) 12-28 15:08:30.547:E / AndroidRuntime(21939):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)12-28 15:08:30.547:E / AndroidRuntime(21939):at dalvik.system.NativeStart.main(原生方法)
和URI的日志跟踪是:
URI android.resource://com.samplePlayVideo/2130968576
我不知道为什么会发生这种情况......帮助是值得赞赏的!提前致谢。
答案 0 :(得分:0)
在某些Micromax设备中存在问题,videoview
不受支持,因此我找到了一个解决方案,而不是使用videoview
我正在使用SurfaceView
,并且它可以在所有设备中使用。