Hi, try the following code:
VideoPlaying.java
public class VideoPlaying extends Activity { private MediaController mc; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); VideoView vd = (VideoView) findViewById(R.id.VideoView); Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.VideoName); mc = new MediaController(this); vd.setMediaController(mc); vd.requestFocus(); vd.setVideoURI(uri); vd.start(); } }
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" android:gravity="center"> <VideoView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/VideoView"></VideoView> </LinearLayout>
put the video in a raw folder and run the code. Sometimes the video does not display correctly on the emulator, try also checking it on the device itself.
Basil source share