Created
June 26, 2020 15:42
-
-
Save ktvipin27/7c6922cf948e36ea8116ee461ce54c1f to your computer and use it in GitHub Desktop.
Fragment for displaying media preview in cameraX sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MediaViewerFragment : Fragment(R.layout.fragment_media_viewer) { | |
private val args: MediaViewerFragmentArgs by navArgs() | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
btnBack.setOnClickListener { findNavController().popBackStack() } | |
val mediaUri = args.mediaUri | |
if (mediaUri.path?.endsWith(VIDEO_FILE_EXTENSION, true) == true) { | |
val mediaController = MediaController(requireContext()) | |
videoView.setMediaController(mediaController) | |
videoView.setVideoURI(mediaUri) | |
videoView.seekTo(1) | |
videoView.visibility = VISIBLE | |
photoView.visibility = GONE | |
} else { | |
photoView.setImageURI(mediaUri) | |
photoView.visibility = VISIBLE | |
videoView.visibility = GONE | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment