• TekArt

    TekArt is an Organisation where people develop Android App through innovative ideas. App for the next Generation....

Sunday 6 April 2014

Posted by Unknown
2 comments | 00:07
Hello Guys , How are you?? Its Super Sunday, hope you guys enjoying your weekend.

Today we will see how to Play Videos in Android. So lets get started.



1) First of all create an Android Application Project.

2) Go to "res/layout/activity_main.xml" and create a VideoView. The code looks like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <VideoView  
        android:id="@+id/videoView1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_alignParentLeft="true"  
        android:layout_centerVertical="true" />  

</RelativeLayout>



3) Next go to "src/your_package_name/MainActivity.java" and create set the MediaController for VideoView.

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        VideoView videoView = (VideoView) findViewById(R.id.videoView1);

        // Creating MediaController
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);

        // specify the location of media file
        Uri uri = Uri.parse("android.resource://com.example.videoplayer_blog/"
                + R.raw.video1);

        // Setting MediaController and URI, then starting the videoView
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();
    }

}

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

2 comments:

  1. benjamin moore titanium | Titanium Arts
    The Company Profile of the babyliss pro nano titanium straightener BATON HORN COMPANY ford focus titanium hatchback of TIGERONHOUNGE MUSEUM is titanium nipple barbells a company incorporated and operated by the BATON titanium quartz crystal HORN COMPANY of TIGERONHOUNGE MUSEUM. thaitanium

    ReplyDelete