Android Studio: Video Player URL Sederhana 4
Jump to navigation
Jump to search
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
MainActivity.java
import android.net.Uri; import android.os.Bundle; import android.widget.MediaController; import android.widget.VideoView; import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// Your Video URL
String videoUrl = "https://onnocenter.or.id/pustaka/VIDEO/internetofflineinstallmoodle.mp4";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// finding videoview by its id
VideoView videoView = findViewById(R.id.videoView);
// Uri object to refer the
// resource from the videoUrl
Uri uri = Uri.parse(videoUrl);
// sets the resource from the
// videoUrl to the videoView
videoView.setVideoURI(uri);
// creating object of
// media controller class
MediaController mediaController = new MediaController(this);
// sets the anchor view
// anchor view for the videoView
mediaController.setAnchorView(videoView);
// sets the media player to the videoView
mediaController.setMediaPlayer(videoView);
// sets the media controller to the videoView
videoView.setMediaController(mediaController);
// starts the video
videoView.start();
}
}