Code to Play Video on Android

Screen Shot 2014-12-30 at 5.45.08 PM

There is plenty of multimedia API in the Android development kits. You can use any class or method that suit your project and apps development. Android is based on linux, the multimedia API is documented in the Google Android SDK website.

You can use VideoView class to play the video on Android devices, set the setVideoURI string, put the MP4 video in /res/raw folder and finally use start() method to play the video. Here is the code snippet to play the video on Android.

 

 

public class PlayVideo extends Activity {


privatestaticfinalintREQUEST_CODE = 0;



VideoView vv;


@Override


public void onCreate(Bundle savedInstanceState) {


   


        super.onCreate(savedInstanceState);


       


        setContentView(R.layout.playvideo);


       


        LinearLayout layout = (LinearLayout) findViewById(R.id.layout);


   


   


   


    VideoView vv = (VideoView)this.findViewById(R.id.videoView1);


    String uri = "android.resource://" + "gnu.yourdomain.android" + "/" + R.raw.scare;


    vv.setVideoURI(Uri.parse(uri));


    vv.start();


   


    }

Code to Play Video on Android Code to Play Video on Android Reviewed by Admin on 1:45 AM Rating: 5

No comments:

Powered by Blogger.