我已经使用Fire base数据库存储了视频链接,总共有3个链接。并可以连续播放视频,而无需触摸代码,前提是您可以演示如何连续播放歌曲。对不起,代码也可能会出错。
private FirebaseDatabase firebaseDatabase;
private DatabaseReference song1;
private DatabaseReference song2;
private DatabaseReference song3;
private VideoView videoView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
firebaseDatabase = FirebaseDatabase.getInstance();
song1 = firebaseDatabase.getReference().child("Song").child("1");
song2 = firebaseDatabase.getReference().child("Song").child("2");
song3 = firebaseDatabase.getReference().child("Song").child("3");
videoView = findViewById(R.id.videoView);
total = firebaseDatabase.getReference().child("Song");
------------------------------------------------------------------------
total.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
List<Uri> list = new ArrayList<>();
for (DataSnapshot child : dataSnapshot.getChildren()) {
list.add(child.getValue(Uri.class));
Uri uri=Uri.parse(dataSnapshot.getValue().toString());
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
}
答案 0 :(得分:3)
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mplayer) {
mplayer.setLooping(true);
}
});
您可以创建一个方法并将不同的URL传递给它。
playVideo(String uri) {
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
并在调用playVideo方法时检查以下情况-
if (videoView.isPlaying()) {
}
else {
playVideo(uri);
}