use the extension function for formatting video time
This commit is contained in:
parent
37c40b8de7
commit
57a076d65c
1 changed files with 6 additions and 22 deletions
|
@ -13,6 +13,7 @@ import android.view.*
|
||||||
import android.view.animation.AnimationUtils
|
import android.view.animation.AnimationUtils
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import com.simplemobiletools.commons.extensions.getFormattedDuration
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.getNavBarHeight
|
import com.simplemobiletools.gallery.extensions.getNavBarHeight
|
||||||
|
@ -21,7 +22,6 @@ import com.simplemobiletools.gallery.helpers.MEDIUM
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.pager_video_item.view.*
|
import kotlinx.android.synthetic.main.pager_video_item.view.*
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSeekBarChangeListener {
|
class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSeekBarChangeListener {
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
|
|
||||||
private fun setupTimeHolder() {
|
private fun setupTimeHolder() {
|
||||||
mSeekBar!!.max = mDuration
|
mSeekBar!!.max = mDuration
|
||||||
mView.video_duration.text = getTimeString(mDuration)
|
mView.video_duration.text = mDuration.getFormattedDuration()
|
||||||
mTimerHandler = Handler()
|
mTimerHandler = Handler()
|
||||||
setupTimer()
|
setupTimer()
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
if (mMediaPlayer != null && !mIsDragged && mIsPlaying) {
|
if (mMediaPlayer != null && !mIsDragged && mIsPlaying) {
|
||||||
mCurrTime = mMediaPlayer!!.currentPosition / 1000
|
mCurrTime = mMediaPlayer!!.currentPosition / 1000
|
||||||
mSeekBar!!.progress = mCurrTime
|
mSeekBar!!.progress = mCurrTime
|
||||||
mCurrTimeView!!.text = getTimeString(mCurrTime)
|
mCurrTimeView!!.text = mCurrTime.getFormattedDuration()
|
||||||
}
|
}
|
||||||
|
|
||||||
mTimerHandler!!.postDelayed(this, 1000)
|
mTimerHandler!!.postDelayed(this, 1000)
|
||||||
|
@ -224,7 +224,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
private fun setProgress(seconds: Int) {
|
private fun setProgress(seconds: Int) {
|
||||||
mMediaPlayer!!.seekTo(seconds * 1000)
|
mMediaPlayer!!.seekTo(seconds * 1000)
|
||||||
mSeekBar!!.progress = seconds
|
mSeekBar!!.progress = seconds
|
||||||
mCurrTimeView!!.text = getTimeString(seconds)
|
mCurrTimeView!!.text = seconds.getFormattedDuration()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addPreviewImage() {
|
private fun addPreviewImage() {
|
||||||
|
@ -247,7 +247,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
|
|
||||||
private fun cleanup() {
|
private fun cleanup() {
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
mCurrTimeView?.text = getTimeString(0)
|
mCurrTimeView?.text = 0.getFormattedDuration()
|
||||||
mMediaPlayer?.release()
|
mMediaPlayer?.release()
|
||||||
mMediaPlayer = null
|
mMediaPlayer = null
|
||||||
mSeekBar?.progress = 0
|
mSeekBar?.progress = 0
|
||||||
|
@ -269,7 +269,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
playVideo()
|
playVideo()
|
||||||
} else {
|
} else {
|
||||||
mSeekBar!!.progress = mSeekBar!!.max
|
mSeekBar!!.progress = mSeekBar!!.max
|
||||||
mCurrTimeView!!.text = getTimeString(mDuration)
|
mCurrTimeView!!.text = mDuration.getFormattedDuration()
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,22 +321,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTimeString(duration: Int): String {
|
|
||||||
val sb = StringBuilder(8)
|
|
||||||
val hours = duration / (60 * 60)
|
|
||||||
val minutes = duration % (60 * 60) / 60
|
|
||||||
val seconds = duration % (60 * 60) % 60
|
|
||||||
|
|
||||||
if (duration > 3600) {
|
|
||||||
sb.append(String.format(Locale.getDefault(), "%02d", hours)).append(":")
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(String.format(Locale.getDefault(), "%02d", minutes))
|
|
||||||
sb.append(":").append(String.format(Locale.getDefault(), "%02d", seconds))
|
|
||||||
|
|
||||||
return sb.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
if (mMediaPlayer != null && fromUser) {
|
if (mMediaPlayer != null && fromUser) {
|
||||||
setProgress(progress)
|
setProgress(progress)
|
||||||
|
|
Loading…
Reference in a new issue