-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2747 from dimagi/add-fullscreen-option-to-inline-…
…videos Add fullscreen option to in-line videos
- Loading branch information
Showing
19 changed files
with
290 additions
and
47 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:gravity="center"> | ||
|
||
<org.commcare.views.media.CommCareVideoView | ||
android:id="@+id/fullscreen_video_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="center" /> | ||
</LinearLayout> |
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
Large diffs are not rendered by default.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
app/src/org/commcare/activities/FullscreenVideoViewActivity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.commcare.activities | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import org.commcare.dalvik.databinding.ActivityFullscreenVideoViewBinding | ||
import org.commcare.views.media.CommCareMediaController | ||
|
||
/** | ||
* Activity to view inline videos in fullscreen mode, it returns the last time position to the | ||
* calling activity | ||
* | ||
* @author avazirna | ||
*/ | ||
class FullscreenVideoViewActivity : AppCompatActivity() { | ||
|
||
private lateinit var viewBinding: ActivityFullscreenVideoViewBinding | ||
private var lastPosition = -1 | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
viewBinding = ActivityFullscreenVideoViewBinding.inflate(layoutInflater) | ||
setContentView(viewBinding.root) | ||
|
||
// Get video URI from intent, crash if no URI is available | ||
intent.data?.let { viewBinding.fullscreenVideoView.setVideoURI(intent.data) } | ||
?: throw RuntimeException("Video file not found!"); | ||
lastPosition = restoreLastPosition(savedInstanceState) | ||
|
||
viewBinding.fullscreenVideoView.setMediaController(CommCareMediaController(this, true)) | ||
viewBinding.fullscreenVideoView.setOnPreparedListener { | ||
if (lastPosition != -1) { | ||
viewBinding.fullscreenVideoView.seekTo(lastPosition) | ||
} | ||
viewBinding.fullscreenVideoView.start() | ||
} | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
super.onSaveInstanceState(outState) | ||
if (lastPosition != -1) { | ||
outState.putInt(CommCareMediaController.INLINE_VIDEO_TIME_POSITION, lastPosition) | ||
} | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
if (viewBinding.fullscreenVideoView != null) { | ||
viewBinding.fullscreenVideoView.pause() | ||
lastPosition = viewBinding.fullscreenVideoView.currentPosition | ||
} | ||
} | ||
|
||
override fun onBackPressed() { | ||
setResultIntent() | ||
super.onBackPressed() | ||
} | ||
|
||
private fun setResultIntent() { | ||
val i = Intent() | ||
i.putExtra( | ||
CommCareMediaController.INLINE_VIDEO_TIME_POSITION, | ||
viewBinding.fullscreenVideoView.currentPosition | ||
) | ||
this.setResult(RESULT_OK, i) | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
viewBinding.fullscreenVideoView.stopPlayback() | ||
} | ||
|
||
// priority is given to lastPosition saved state | ||
private fun restoreLastPosition(savedInstanceState: Bundle?): Int { | ||
val intentExtras = intent.extras | ||
if (savedInstanceState != null && | ||
savedInstanceState.containsKey(CommCareMediaController.INLINE_VIDEO_TIME_POSITION)) { | ||
return savedInstanceState.getInt(CommCareMediaController.INLINE_VIDEO_TIME_POSITION) | ||
} else if (intentExtras != null && | ||
intentExtras.containsKey(CommCareMediaController.INLINE_VIDEO_TIME_POSITION)) { | ||
return intentExtras.getInt(CommCareMediaController.INLINE_VIDEO_TIME_POSITION) | ||
} | ||
return -1 | ||
} | ||
} |
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
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
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
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