mirror of
https://github.com/tuskyapp/Tusky
synced 2025-01-30 15:35:27 +01:00
fix videos not always keeping aspect ratio (#1508)
This commit is contained in:
parent
b61bbc3fb5
commit
fe304b4e83
@ -103,7 +103,6 @@
|
|||||||
<activity android:name=".ViewTagActivity" />
|
<activity android:name=".ViewTagActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ViewMediaActivity"
|
android:name=".ViewMediaActivity"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
|
||||||
android:theme="@style/TuskyBaseTheme" />
|
android:theme="@style/TuskyBaseTheme" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".AccountActivity"
|
android:name=".AccountActivity"
|
||||||
|
@ -50,7 +50,7 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||||||
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
||||||
// Start/pause/resume video playback as fragment is shown/hidden
|
// Start/pause/resume video playback as fragment is shown/hidden
|
||||||
super.setUserVisibleHint(isVisibleToUser)
|
super.setUserVisibleHint(isVisibleToUser)
|
||||||
if (videoPlayer == null) {
|
if (videoView == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,10 +58,10 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||||||
if (mediaActivity.isToolbarVisible) {
|
if (mediaActivity.isToolbarVisible) {
|
||||||
handler.postDelayed(hideToolbar, TOOLBAR_HIDE_DELAY_MS)
|
handler.postDelayed(hideToolbar, TOOLBAR_HIDE_DELAY_MS)
|
||||||
}
|
}
|
||||||
videoPlayer.start()
|
videoView.start()
|
||||||
} else {
|
} else {
|
||||||
handler.removeCallbacks(hideToolbar)
|
handler.removeCallbacks(hideToolbar)
|
||||||
videoPlayer.pause()
|
videoView.pause()
|
||||||
mediaController.hide()
|
mediaController.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,18 +69,31 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun setupMediaView(url: String, previewUrl: String?) {
|
override fun setupMediaView(url: String, previewUrl: String?) {
|
||||||
descriptionView = mediaDescription
|
descriptionView = mediaDescription
|
||||||
val videoView = videoPlayer
|
|
||||||
videoView.transitionName = url
|
videoView.transitionName = url
|
||||||
videoView.setVideoPath(url)
|
videoView.setVideoPath(url)
|
||||||
mediaController = MediaController(mediaActivity)
|
mediaController = MediaController(mediaActivity)
|
||||||
mediaController.setMediaPlayer(videoPlayer)
|
mediaController.setMediaPlayer(videoView)
|
||||||
videoPlayer.setMediaController(mediaController)
|
videoView.setMediaController(mediaController)
|
||||||
videoView.requestFocus()
|
videoView.requestFocus()
|
||||||
videoView.setOnTouchListener { _, _ ->
|
videoView.setOnTouchListener { _, _ ->
|
||||||
mediaActivity.onPhotoTap()
|
mediaActivity.onPhotoTap()
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
videoView.setOnPreparedListener { mp ->
|
videoView.setOnPreparedListener { mp ->
|
||||||
|
val containerWidth = videoContainer.measuredWidth.toFloat()
|
||||||
|
val containerHeight = videoContainer.measuredHeight.toFloat()
|
||||||
|
val videoWidth = mp.videoWidth.toFloat()
|
||||||
|
val videoHeight = mp.videoHeight.toFloat()
|
||||||
|
|
||||||
|
if(containerWidth/containerHeight > videoWidth/videoHeight) {
|
||||||
|
videoView.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
videoView.layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
} else {
|
||||||
|
videoView.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
videoView.layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
}
|
||||||
|
|
||||||
progressBar.hide()
|
progressBar.hide()
|
||||||
mp.isLooping = true
|
mp.isLooping = true
|
||||||
if (arguments!!.getBoolean(ARG_START_POSTPONED_TRANSITION)) {
|
if (arguments!!.getBoolean(ARG_START_POSTPONED_TRANSITION)) {
|
||||||
@ -117,7 +130,7 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onToolbarVisibilityChange(visible: Boolean) {
|
override fun onToolbarVisibilityChange(visible: Boolean) {
|
||||||
if (videoPlayer == null || !userVisibleHint) {
|
if (videoView == null || !userVisibleHint) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,46 +1,43 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
android:id="@+id/videoContainer"
|
||||||
android:layout_gravity="center"
|
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
|
|
||||||
<VideoView
|
|
||||||
android:id="@+id/videoPlayer"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/mediaDescription"
|
android:id="@+id/mediaDescription"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="?attr/actionBarSize"
|
android:layout_marginTop="?attr/actionBarSize"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
android:background="#60000000"
|
android:background="#60000000"
|
||||||
android:lineSpacingMultiplier="1.1"
|
android:lineSpacingMultiplier="1.1"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textColor="#eee"
|
android:textColor="#eee"
|
||||||
android:textSize="?attr/status_text_medium"
|
android:textSize="?attr/status_text_medium"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:text="Some media description" />
|
tools:text="Some media description" />
|
||||||
|
|
||||||
|
<VideoView
|
||||||
|
android:id="@+id/videoView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
android:layout_gravity="center" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user