Difference between revisions of "Android Studio: Video Player Sederhana"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
Line 1: | Line 1: | ||
+ | ==activity_main.xml== | ||
+ | |||
+ | <?xml version="1.0" encoding="utf-8"?> | ||
+ | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
+ | xmlns:app="http://schemas.android.com/apk/res-auto" | ||
+ | xmlns:tools="http://schemas.android.com/tools" | ||
+ | android:layout_width="match_parent" | ||
+ | android:layout_height="match_parent" | ||
+ | tools:context=".MainActivity"> | ||
+ | |||
+ | <VideoView | ||
+ | android:id="@+id/vdVw" | ||
+ | android:layout_width="match_parent" | ||
+ | android:layout_height="match_parent" | ||
+ | android:layout_gravity="center" /> | ||
+ | </androidx.constraintlayout.widget.ConstraintLayout> | ||
+ | |||
==MainActivity.java== | ==MainActivity.java== |
Revision as of 11:40, 17 March 2022
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <VideoView android:id="@+id/vdVw" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" /> </androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity; import android.net.Uri; import android.os.Bundle; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); VideoView videoView =(VideoView)findViewById(R.id.vdVw); //Set MediaController to enable play, pause, forward, etc options. MediaController mediaController= new MediaController(this); mediaController.setAnchorView(videoView); //Location of Media File Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video1); //Starting VideView By Setting MediaController and URI videoView.setMediaController(mediaController); videoView.setVideoURI(uri); videoView.requestFocus(); videoView.start(); } }