binding.videoSurface.setVideoURI(Uri.parse(uri));
binding.videoSurface.setOnPreparedListener(mp -> {
binding.videoSurface.requestFocus();
binding.videoSurface.start();
});
}
@Override
protected void onDestroyFrame() {
super.onDestroyFrame();
binding.videoSurface.suspend();
}
- 使用SurfaceView+MediaPlayer
<SurfaceView
android:id=“@+id/surface_view”
android:layout_width=“250dp”
android:layout_height=“250dp”
app:layout_constraintRight_toRightOf=“parent”
app:layout_constraintTop_toTopOf=“parent” />
private String uri = “rtsp://192.168.1.10:554/user=admin_password=nTBCS19C_channel=1_stream=0.sdp?real_stream”;
@Override
protected void onDestroyFrame() {
super.onDestroyFrame();
if (mediaPlayer.isPlaying()) {