Skip to content Skip to sidebar Skip to footer

How To Play A Video File From SD Card

I want to play a video file on android emulator that I have stored in sd card. This is my code.. public class AndroidVideoViewActivity extends Activity { private VideoView vid

Solution 1:

Please check this link

OR

Replace videoView.setVideoPath("mnt/sdcard/bmxskills.3gp");

with videoView.setVideoPath("/sdcard/bmxskills.3gp");


Solution 2:

Use below code for that.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"/>
    <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>
</LinearLayout>

MainActivity.java

public class MainActivity extends Activity {

    String SrcPath = "/sdcard/Video/Android in Spaaaaaace!_low.mp4";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
        myVideoView.setVideoPath(SrcPath);
        myVideoView.setMediaController(new MediaController(this));
        myVideoView.requestFocus();
        myVideoView.start();
    }
}

Solution 3:

You should not test running video on the emulator itself, if you have a device laying around, use that instead. The Android emulator is quite terrible when it coming to handling videos correctly, so you may get a lot of problems that wouldn't normally be there on any Android device.


Post a Comment for "How To Play A Video File From SD Card"