Blog purpose for android basic example for android app developer. any query please my contact

Saturday, 26 August 2023

Android Program how to play Demonstrate a Video View in android

 Android Program how to play Demonstrate a Video View  in android


In this Tutorial Today Learn Android Program how to play Demonstrate a Video View

In Android Follow The Steps How to Play Demonstrate a Video View in android.


1.Main Activity.java:


import android.app.Activity;

import android.net.Uri;

import android.os.Bundle;

import android.view.Menu;

import android.widget.MediaController;

import android.widget.VideoView;

 

public class MainActivity extends Activity {

    private MediaController mc;

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

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

 

        Uri uri = Uri.parse("android.resource://"+getPackageName() + "/"+R.raw.movie);;

 

        mc = new MediaController(this);

        vd.setMediaController(mc);

 

        vd.setVideoURI(uri);

        vd.start();

    }

 

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.main, menu);

        return true;

    }

 

}


2.actvity_main:


<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_alignParentTop="true" />

 

</RelativeLayout>

No comments:

Post a Comment