url来自raw文件中,自己放进去的Mp4;
视屏可以拖动进度条;
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@drawable/dj">
<TextView
android:id="@+id/text_3"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="迪迦奥特曼片尾曲 迪迦奥特曼片尾曲 迪迦奥特曼片尾曲 迪迦奥特曼片尾曲"
android:textColor="#E91E63"
android:textSize="50dp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"/>
<VideoView
android:id="@+id/switch_1"
android:layout_below="@id/text_3"
android:layout_marginTop="250dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Java逻辑页面:
package com.example.myapplication3;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
public class ButtonActivity extends AppCompatActivity {
private VideoView tv_1;
private TextView mbimageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button);
tv_1 = findViewById(R.id.switch_1);
mbimageView=findViewById(R.id.text_3);
mbimageView.setSelected(true);
tv_1.setMediaController(new MediaController(this));
tv_1.setOnCompletionListener(new MyPlayerOnCompletionListener());
String uri1 = "android.resource://" + getPackageName() + "/" + R.raw.dijiaaoteman;
tv_1.setVideoURI(Uri.parse(uri1));
tv_1.start();
}
//setMediaController控制进度
class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {
@Override
public void onCompletion(MediaPlayer mp) {
Toast.makeText(ButtonActivity.this, "结束", Toast.LENGTH_SHORT).show();
}
}
}