VideoView control Android
************************ Main.xml *********************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<VideoView
android:layout_width="fill_parent"
android:layout_height="300dp"
android:id="@+id/video"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Play"
android:id="@+id/btn"/>
</LinearLayout>
***************************** Main .java ******************************
package com.example.videoview;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
Button play;
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play=(Button) findViewById(R.id.btn);
videoView=(VideoView)findViewById(R.id.video);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
videoView.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.a));
videoView.start();
}
});
}
}
0 Comments