Skip to content

Commit

Permalink
Merge pull request #2 from Chayandev/master
Browse files Browse the repository at this point in the history
Fixed-unresponsive-ui
  • Loading branch information
redevrx authored May 9, 2024
2 parents 82448ec + 54ca3eb commit d5ca098
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 77 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions video-trimmer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,29 @@ dependencies {
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}


afterEvaluate {
publishing {
publications {

// Creates a Maven publication called "release".
create<MavenPublication>("release") {

// Applies the component for the release build variant.
// NOTE : Delete this line code if you publish Native Java / Kotlin Library
from(components["release"])

// NOTE : Different GroupId For Each Library / Module, So That Each Library Is Not Overwritten
groupId = "com.github.redevrx"

// NOTE : Different ArtifactId For Each Library / Module, So That Each Library Is Not Overwritten
artifactId = "android_video_trimmer"

// Version Library Name (Example : "1.0.0")
version = "1.0.0"

}

}
}
}
//
//afterEvaluate {
// publishing {
// publications {
//
// // Creates a Maven publication called "release".
// create<MavenPublication>("release") {
//
// // Applies the component for the release build variant.
// // NOTE : Delete this line code if you publish Native Java / Kotlin Library
// from(components["release"])
//
// // NOTE : Different GroupId For Each Library / Module, So That Each Library Is Not Overwritten
// groupId = "com.github.redevrx"
//
// // NOTE : Different ArtifactId For Each Library / Module, So That Each Library Is Not Overwritten
// artifactId = "android_video_trimmer"
//
// // Version Library Name (Example : "1.0.0")
// version = "1.0.0"
//
// }
//
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class RangeSeekBarView @JvmOverloads constructor(context: Context, attrs: Attrib
newX <= mPixelRangeMin -> mThumb.pos = mPixelRangeMin
else -> {
checkPositionThumb(mThumb, mThumb2, dx, true)
mThumb.pos = mThumb.pos + dx
mThumb.pos += dx
mThumb.lastTouchX = coordinate
}
}
Expand All @@ -140,7 +140,7 @@ class RangeSeekBarView @JvmOverloads constructor(context: Context, attrs: Attrib
newX >= mPixelRangeMax -> mThumb.pos = mPixelRangeMax
else -> {
checkPositionThumb(mThumb2, mThumb, dx, false)
mThumb.pos = mThumb.pos + dx
mThumb.pos += dx
mThumb.lastTouchX = coordinate
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TimeLineView @JvmOverloads constructor(context: Context, attrs: AttributeS
}

private fun init() {
mHeightView = context.resources.getDimensionPixelOffset(R.dimen.frames_video_height)
mHeightView = context.resources.getDimensionPixelOffset(R.dimen.frames_video_height)
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class VideoEditor @JvmOverloads constructor(

private lateinit var binding: TrimmerViewLayoutBinding

private var mDuration:Long = 0L
private var mDuration: Long = 0L
private var mTimeVideo = 0L
private var mStartPosition = 0L

Expand Down Expand Up @@ -117,7 +117,7 @@ class VideoEditor @JvmOverloads constructor(
GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
onClickVideoPlayPause()
Toast.makeText(context,"Click",Toast.LENGTH_LONG).show()
Toast.makeText(context, "Click", Toast.LENGTH_LONG).show()
return true
}
})
Expand All @@ -131,6 +131,8 @@ class VideoEditor @JvmOverloads constructor(
true
}



binding.handlerTop.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
onPlayerIndicatorSeekChanged(progress, fromUser)
Expand Down Expand Up @@ -161,6 +163,10 @@ class VideoEditor @JvmOverloads constructor(
onStopSeekThumbs()
}
})
//
// if (mPlayer != null && mPlayer.isPlaying) {
// binding.handlerTop.visibility = View.VISIBLE
// }
}

private fun onPlayerIndicatorSeekChanged(progress: Int, fromUser: Boolean) {
Expand Down Expand Up @@ -200,9 +206,8 @@ class VideoEditor @JvmOverloads constructor(
}



private fun onClickVideoPlayPause() {
if ( mPlayer.isPlaying) {
if (mPlayer.isPlaying) {
binding.iconVideoPlay.visibility = View.VISIBLE
mMessageHandler.removeMessages(SHOW_PROGRESS)
mPlayer.pause()
Expand All @@ -211,8 +216,11 @@ class VideoEditor @JvmOverloads constructor(
if (mResetSeekBar) {
mResetSeekBar = false
mPlayer.seekTo(mStartPosition)
binding.handlerTop.visibility=View.VISIBLE
setProgressBarPosition(0)
}
mResetSeekBar = false
binding.handlerTop.visibility = View.VISIBLE
mMessageHandler.sendEmptyMessage(SHOW_PROGRESS)
mPlayer.play()
}
Expand Down Expand Up @@ -247,7 +255,7 @@ class VideoEditor @JvmOverloads constructor(
binding.videoLoader.layoutParams = lp

binding.iconVideoPlay.visibility = View.VISIBLE
mDuration = mPlayer.duration
mDuration = mPlayer.duration
// mDuration = binding.videoLoader.duration.toFloat()
setSeekBarPosition()
setTimeFrames()
Expand Down Expand Up @@ -324,7 +332,7 @@ class VideoEditor @JvmOverloads constructor(

private fun notifyProgressUpdate(all: Boolean) {
if (mDuration == 0L) return
val position = mPlayer.currentPosition//binding.videoLoader.currentPosition
val position = mPlayer.currentPosition//binding.videoLoader.currentPosition
if (all) {
for (item in mListeners) {
item.updateProgress(position.toFloat(), mDuration, (position * 100 / mDuration))
Expand Down Expand Up @@ -354,12 +362,12 @@ class VideoEditor @JvmOverloads constructor(
setProgressBarPosition(time)
}

fun setVideoBackgroundColor(@ColorInt color:Int) = with(binding){
fun setVideoBackgroundColor(@ColorInt color: Int) = with(binding) {
container.setBackgroundColor(color)
layout.setBackgroundColor(color)
}

fun setFrameColor(@ColorInt color: Int) = with(binding){
fun setFrameColor(@ColorInt color: Int) = with(binding) {
frameColor.setBackgroundColor(color)
}

Expand All @@ -371,7 +379,7 @@ class VideoEditor @JvmOverloads constructor(
val matches = regex.findAll(txtTime)
val timeList = matches.map { it.value }.toList()

val filePath = "$destinationPath/${UUID.randomUUID()}.mp4"
val filePath = "$destinationPath/${UUID.randomUUID()}.mp4"

val transformation = TransformationRequest.Builder()
.setVideoMimeType(MimeTypes.VIDEO_H264)
Expand All @@ -382,7 +390,7 @@ class VideoEditor @JvmOverloads constructor(
.setTransformationRequest(transformation)
.addListener(object : androidx.media3.transformer.Transformer.Listener {
override fun onCompleted(composition: Composition, exportResult: ExportResult) {
mOnVideoEditedListener?.getResult(Uri.parse(filePath))
mOnVideoEditedListener?.getResult(Uri.parse(filePath))
}

override fun onError(
Expand Down Expand Up @@ -417,8 +425,9 @@ class VideoEditor @JvmOverloads constructor(
.setEffects(Effects.EMPTY)
.build()

val composition = Composition.Builder(listOf(EditedMediaItemSequence(listOf(editedMediaItem))))
.build()
val composition =
Composition.Builder(listOf(EditedMediaItemSequence(listOf(editedMediaItem))))
.build()

transformer.start(composition, filePath)
}
Expand Down Expand Up @@ -501,10 +510,11 @@ class VideoEditor @JvmOverloads constructor(
}


mPlayer.addListener(object :Player.Listener{
mPlayer.addListener(object : Player.Listener {
override fun onPlayerError(error: PlaybackException) {
mOnVideoEditedListener?.onError("Something went wrong reason : ${error.localizedMessage}")
}

@SuppressLint("UnsafeOptInUsageError")
override fun onVideoSizeChanged(videoSize: VideoSize) {
super.onVideoSizeChanged(videoSize)
Expand All @@ -516,6 +526,18 @@ class VideoEditor @JvmOverloads constructor(
}

onVideoPrepared(mPlayer)

}
override fun onPlaybackStateChanged(state: Int) {
if (state == Player.STATE_ENDED) {
// Video has ended, seek back to the start
mResetSeekBar=true
mPlayer.seekTo(mStartPosition)
binding.handlerTop.visibility=View.VISIBLE
setProgressBarPosition(0)
// You might want to start playing the video again here if needed
// mPlayer.play()
}
}
})

Expand Down Expand Up @@ -566,11 +588,14 @@ class VideoEditor @JvmOverloads constructor(

fun onResume() {
mPlayer.seekTo(videoPlayerCurrentPosition)
if(binding?.videoLoader?.player?.isPlaying==true){
binding.handlerTop.visibility= View.VISIBLE
}
// binding.videoLoader.seekTo(videoPlayerCurrentPosition)
}

fun onPause() {
videoPlayerCurrentPosition = mPlayer.currentPosition
videoPlayerCurrentPosition = mPlayer.currentPosition
// videoPlayerCurrentPosition = binding.videoLoader.currentPosition
}

Expand Down
8 changes: 8 additions & 0 deletions video-trimmer/src/main/res/drawable/seek_new_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<size
android:width="3dp"
android:height="@dimen/frames_video_height" />
</shape>
Loading

0 comments on commit d5ca098

Please sign in to comment.