我的应用程序中有以下导航结构:
MainActivity -> VideoListFragment -> VideoShowingFragment
(only activity, (shows a list of Video (gets the URL of the video to
container for items via a Recycler- show and plays the video via
all the other View, the URL of the ExoPlayer. From here, the user
fragments) Video is passed to can enter PiP mode)
next Fragment)
因此,当应用程序启动时,Video
会向用户显示一个项目列表。当用户单击一个项目时,URL 被传递给通过库向用户VideoShowingFragment
显示内容的 URL 。在 顶部,有一个图标,用户点击它可以进入画中画模式。Video
PlayerView
ExoPlayer
PlayerView
输入 PiP 可以正常工作,但我的问题是如何在进入 PiP 模式后显示视频列表?我的意思是:当用户在VideoShowingFragment
舞台上并决定Video
通过进入画中画模式来最小化内容时,我怎样才能向他显示Video
s ( VideoListFragment
) 的列表,以便他可以浏览列表,同时仍然在画中画模式下观看内容?
现在的情况如下:用户进入画中画模式,但用户看到他的设备的开始屏幕,而右下角的视频内容被最小化。
以下是我项目的一些相关部分:
<!-- AndroidManifest.xml -->
<application
...>
<activity
android:name=".MainActivity"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
如前所述,单击VideoListFragment
导航到ShowingVideoFragment
:
videoListFragmentViewModel.openVideoEvent.observe(viewLifecycleOwner, EventObserver{ videoUri -> findNavController().navigate(VideoListFragmentDirections.actionVideoListFragmentToVideoShowingFragment(videoUri))})
然后ShowingFragment
获取显示视频所需的数据。我不会深入研究,因为它只是典型的ExoPlayer
东西。
同样在 中ShowingFragment
,我们有进入画中画模式的逻辑:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = FragmentVideoShowingBinding.inflate(inflater, container, false)
// listener on icon with ID 'pipMode'
binding.pipMode.setOnClickListener{ enablePipMode() }
return binding.root
}
private fun enablePipMode() {
// set aspect ratio
picInPicParamsBuilder.setAspectRatio(Rational(binding.playerView.width, binding.playerView.height))
// enter the PiP mode
activity?.enterPictureInPictureMode(picInPicParamsBuilder.build())
}
// override to make the icon on top of PlayerView eiter visible or invisible
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode)
if(isInPictureInPictureMode){
binding.pipMode.visibility = View.GONE
}
else{
binding.pipMode.visibility = View.VISIBLE
}
}
VideoShowingFragment
当我想让用户在浏览 时以画中画模式观看所选视频时,我是否需要在第二个活动中主持VideoListFragment
?或者是否有另一种方法来实现我想要的?