Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Subtitle Support for Native Player in Fullscreen Mode #64

Merged
merged 11 commits into from
Nov 19, 2024
Merged
10 changes: 9 additions & 1 deletion app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,18 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
blockId: String,
courseId: String,
isPlaying: Boolean,
transcripts: Map<String, String>,
) {
replaceFragmentWithBackStack(
fm,
VideoFullScreenFragment.newInstance(videoUrl, videoTime, blockId, courseId, isPlaying)
VideoFullScreenFragment.newInstance(
videoUrl = videoUrl,
videoTime = videoTime,
blockId = blockId,
courseId = courseId,
isPlaying = isPlaying,
transcripts = transcripts,
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ interface CourseRouter {
videoTime: Long,
blockId: String,
courseId: String,
isPlaying: Boolean
isPlaying: Boolean,
transcripts: Map<String, String>
)

fun navigateToFullScreenYoutubeVideo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import org.openedx.core.domain.model.VideoQuality
import org.openedx.core.extension.objectToString
import org.openedx.core.extension.requestApplyInsetsWhenAttached
import org.openedx.core.extension.stringToObject
import org.openedx.core.presentation.dialog.appreview.AppReviewManager
import org.openedx.core.presentation.global.viewBinding
import org.openedx.course.R
Expand Down Expand Up @@ -69,6 +71,9 @@ class VideoFullScreenFragment : Fragment(R.layout.fragment_video_full_screen) {
if (viewModel.isPlaying == null) {
viewModel.isPlaying = requireArguments().getBoolean(ARG_IS_PLAYING)
}
viewModel.transcripts = stringToObject<Map<String, String>>(
requireArguments().getString(ARG_TRANSCRIPTS, "")
) ?: emptyMap()
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -199,21 +204,24 @@ class VideoFullScreenFragment : Fragment(R.layout.fragment_video_full_screen) {
private const val ARG_BLOCK_ID = "blockId"
private const val ARG_COURSE_ID = "courseId"
private const val ARG_IS_PLAYING = "isPlaying"
private const val ARG_TRANSCRIPTS = "transcripts"

fun newInstance(
videoUrl: String,
videoTime: Long,
blockId: String,
courseId: String,
isPlaying: Boolean,
transcripts: Map<String, String>,
): VideoFullScreenFragment {
val fragment = VideoFullScreenFragment()
fragment.arguments = bundleOf(
ARG_BLOCK_VIDEO_URL to videoUrl,
ARG_VIDEO_TIME to videoTime,
ARG_BLOCK_ID to blockId,
ARG_COURSE_ID to courseId,
ARG_IS_PLAYING to isPlaying
ARG_IS_PLAYING to isPlaying,
ARG_TRANSCRIPTS to objectToString(transcripts),
)
return fragment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ class VideoUnitFragment : Fragment(R.layout.fragment_video_unit) {
viewModel.exoPlayer?.currentPosition ?: 0L,
viewModel.blockId,
viewModel.courseId,
viewModel.isPlaying
viewModel.isPlaying,
viewModel.transcripts,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class VideoViewModel(
var videoUrl = ""
var currentVideoTime = 0L
var isPlaying: Boolean? = null
var transcripts = emptyMap<String, String>()

private var isBlockAlreadyCompleted = false

Expand Down