android 如何在Micromax移动的中播放SD卡中的视频?

hgqdbh6s  于 2023-02-17  发布在  Android
关注(0)|答案(1)|浏览(121)

我开发了一个应用程序,其中有播放视频SD卡的任务。但它显示空指针异常...代码如下...

public class VideoPlayerActivity extends Activity {
VideoView video_player_view;
DisplayMetrics dm;
SurfaceView sur_View;
MediaController media_Controller;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    getInit();
    }

public void getInit() {
    try {
    video_player_view = (VideoView) findViewById(R.id.video_player_view);
    media_Controller = new MediaController(getApplicationContext());
    dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int height = dm.heightPixels;
    int width = dm.widthPixels;
    video_player_view.setMinimumWidth(width);
    video_player_view.setMinimumHeight(height);
    video_player_view.setMediaController(media_Controller);
    video_player_view.setVideoPath("/storage/sdcard0/baby.3gp");
    video_player_view.start();
    } catch(Exception exp) {
        Toast.makeText(getApplicationContext(), exp.getMessage(), 2).show();
    }
}}

我使用Micromax A210显示输出。我的Logcat如下

12-02 19:04:52.785: D/OpenGLRenderer(3950): Enabling debug mode 0
12-02 19:04:52.787: I/SurfaceView(3950): Changes: creating=true format=true size=true visible=true left=true top=true mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=true mVisible=false mRequestedVisible=true
12-02 19:04:52.788: I/SurfaceView(3950): Cur surface: Surface(name=null, identity=-1)
12-02 19:04:52.791: V/SurfaceView(3950): android.widget.VideoView{41688140 VFE..... .F....ID 0,0-1280,590 #7f06003d app:id/video_player_view} got resized: w=1280 h=590, cur w=-1 h=-1
12-02 19:04:52.793: I/SurfaceView(3950): New surface: Surface(name=null, identity=33), vis=true, frame=Rect(0, 130 - 1280, 720)
12-02 19:04:52.793: I/SurfaceView(3950): visibleChanged -- surfaceCreated
12-02 19:04:52.798: D/MediaPlayer(3950): mPlayerID = 2
12-02 19:04:52.799: D/MediaPlayer(3950): Don't notify duration to test.example.videoviewtesting!
12-02 19:04:52.799: I/SurfaceView(3950): finishedDrawing
12-02 19:04:52.799: E/MediaPlayer(3950): error (1, -2147483648)
12-02 19:04:52.802: D/AndroidRuntime(3950): Shutting down VM
12-02 19:04:52.802: W/dalvikvm(3950): threadid=1: thread exiting with uncaught exception (group=0x4139c9a8)
12-02 19:04:52.804: E/AndroidRuntime(3950): FATAL EXCEPTION: main
12-02 19:04:52.804: E/AndroidRuntime(3950): java.lang.NullPointerException
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.widget.VideoView.openVideo(VideoView.java:396)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.widget.VideoView$6.surfaceCreated(VideoView.java:730)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.SurfaceView.updateWindow(SurfaceView.java:606)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.SurfaceView.access$000(SurfaceView.java:88) 
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:692)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer.doCallbacks(Choreographer.java:579)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer.doFrame(Choreographer.java:548)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.os.Handler.handleCallback(Handler.java:725)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.os.Looper.loop(Looper.java:153)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.app.ActivityThread.main(ActivityThread.java:5297)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at java.lang.reflect.Method.invokeNative(Native Method)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at java.lang.reflect.Method.invoke(Method.java:511)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at dalvik.system.NativeStart.main(Native Method)
12-02 19:04:52.814: D/dalvikvm(3950): threadid=11: interp stack at 0x5e220000

我已经更新了我的main.xml文件。不知道在哪里可以调整视图的大小...

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="video.sample.videosample.MainActivity"
android:orientation="vertical"
tools:ignore="MergeRootFrame" >

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <VideoView
        android:id="@+id/myvideoview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>
mnemlml8

mnemlml81#

尝试使用.avi divx文件类型3gp不工作

相关问题