案例:我需要设计一个视图,其中一个视频应该在背景中,另一个视频应该在前景中,并且它们之间具有透明的视图。 (附有图片)multi-layer video playing view
我的实现:我已经在后台(全屏视频)和前景中的Exoplayer(小视频)中添加了Android VideoView。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.jumman.videoplayer.player.FullScreenVideoView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/VideoView" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_transparent">
</LinearLayout>
<FrameLayout
android:layout_width="200dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:orientation="vertical"
android:background="@android:color/transparent">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="match_parent"
app:use_controller="false"/>
<ImageButton
android:id="@+id/VideoPlayButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="@drawable/video_play_button"
android:background="@null"/>
</FrameLayout>
</FrameLayout>
videoView.setVideoPath("https://storage.googleapis.com/exoplayer-test-media-1/mkv/android-screens-lavf-56.36.100-aac-avc-main-1280x720.mkv");
videoView.setOnPreparedListener(
new MediaPlayer.OnPreparedListener()
{
@Override
public void onPrepared(MediaPlayer mp)
{
mp.setVolume(0f, 0f);
}
}
);
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
playerView.setPlayer(player);
DataSource.Factory dataSourceFactory =
new DefaultDataSourceFactory(this, Util.getUserAgent(this, "Player"));
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("https://storage.googleapis.com/exoplayer-test-media-1/mkv/android-screens-lavf-56.36.100-aac-avc-main-1280x720.mkv"),
dataSourceFactory, extractorsFactory, null, null);
player.prepare(mediaSource);
在上述实现中,我需要同时向VideoView和播放器提供流URL。但是,如果我可以从单个URL流传输,但视频将以两种不同的视图播放,那会更好。我该如何处理,请给我分享更好的解决方案。