Create the Video Player like application, code to create video player in android - android programming

No comments
//AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   
package="com.example.arpit.p6">

    <
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
    <
uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <
application
       
android:allowBackup="true"
       
android:icon="@mipmap/ic_launcher"
       
android:label="@string/app_name"
       
android:supportsRtl="true"
       
android:theme="@style/AppTheme">
        <
activity android:name=".MainActivity">
            <
intent-filter>
                <
action android:name="android.intent.action.MAIN" />

                <
category android:name="android.intent.category.LAUNCHER" />
            </
intent-filter>
        </
activity>
    </
application>

</
manifest>


                                      //strings.xml

<resources>
    <
string name="app_name">P6</string>
</
resources>
activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:id="@+id/activity_main"
   
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="com.example.arpit.p6.MainActivity">

    <
VideoView
       
android:layout_width="match_parent"
       
android:layout_height="match_parent"
       
android:id="@+id/vv_1"
       
android:layout_alignParentTop="true"
       
android:layout_alignParentLeft="true"
       
android:layout_alignParentStart="true" />
</
RelativeLayout>

                                     //MainActivity.java

package com.example.arpit.p6;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

    VideoView
vv;
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);
       
vv=(VideoView)findViewById(R.id.vv_1);
       
//vv.setVideoPath("http://www.ebookfrenzy.com/android_book/movie.mp4");
        //vv.setVideoPath("android.resource://"+getPackageName()+"/"+R.raw.amfk);
       
vv.setVideoPath("file:///sdcard/Download/Abc.mp4");
       
//vv.setVideoPath(Environment.getExternalStorageDirectory().getPath()+"/Download/Abc.mp4");
       
MediaController mc= new MediaController(this);
       
vv.setMediaController(mc);
       
vv.requestFocus();
       
vv.start();
    }
}
                                                  
                                                            //Output

video player in android

No comments :

Post a Comment