Skip to content
This repository was archived by the owner on Sep 24, 2023. It is now read-only.

Commit 9c0858d

Browse files
committed
add videotrimmer source library to project
1 parent d0b75f2 commit 9c0858d

26 files changed

+1334
-10
lines changed

.idea/gradle.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ dependencies {
4848
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4949
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
5050

51-
implementation 'com.github.freddyfang:android-video-trimmer:v1.0.0'
52-
53-
51+
implementation project(':videotrimmer')
5452
implementation 'com.github.MasayukiSuda:Mp4Composer-android:v0.4.0'
5553
implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:1.8.4'
5654
implementation 'com.android.volley:volley:1.1.1'
55+
5756
}

app/src/main/java/net/zentring/live/LiveActivity.kt

+26-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import android.app.Activity
44
import android.content.Intent
55
import android.content.res.Resources
66
import android.graphics.*
7+
import android.media.MediaCodec
8+
import android.media.MediaMetadataRetriever
79
import android.media.MediaPlayer
810
import android.os.Bundle
911
import android.util.Log
@@ -33,6 +35,7 @@ import kotlinx.android.synthetic.main.activity_live.*
3335
import net.ossrs.rtmp.ConnectCheckerRtmp
3436
import java.io.File
3537
import java.io.InputStream
38+
import java.nio.ByteBuffer
3639
import java.text.SimpleDateFormat
3740
import java.util.*
3841
import kotlin.math.round
@@ -135,13 +138,10 @@ class LiveActivity : AppCompatActivity(), ConnectCheckerRtmp, SurfaceHolder.Call
135138
.show()
136139
sdVideoPreview.visibility = View.VISIBLE
137140

138-
// if (rtmpFile!!.prepareAudio(tmpFile.absolutePath) && rtmpFile!!.prepareVideo(tmpFile.absolutePath)) {
139-
//
140-
// }
141141
}
142142
} else {
143143
runOnUiThread {
144-
Toast.makeText(this, "剪輯完成檔案", Toast.LENGTH_SHORT).show()
144+
Toast.makeText(this, "剪輯完成", Toast.LENGTH_SHORT).show()
145145
}
146146
}
147147
}
@@ -719,7 +719,9 @@ class LiveActivity : AppCompatActivity(), ConnectCheckerRtmp, SurfaceHolder.Call
719719
private fun openSideVideos() {
720720
goHome()
721721
videoList.visibility = View.VISIBLE
722+
videoList.bringToFront()
722723
main_control.visibility = View.INVISIBLE
724+
main_control.bringToFront()
723725

724726
data.isSelectEnabled = false
725727
data.selectedVideoList = MutableList(0) { "" }
@@ -732,16 +734,25 @@ class LiveActivity : AppCompatActivity(), ConnectCheckerRtmp, SurfaceHolder.Call
732734
try {
733735
val mp = MediaPlayer()
734736
mp.setDataSource(it.absolutePath)
735-
i++
736737
mp.prepare()
737738
mp.setOnPreparedListener { mediaPlayer ->
739+
i++
738740
val time: Int = mediaPlayer.duration
739741
runOnUiThread {
740742
addVideoToList(it.nameWithoutExtension, (time / 1000), i)
741743
}
742744
mediaPlayer.release()
743745

744746
}
747+
mp.setOnErrorListener { mediaPlayer, what, extra ->
748+
i++
749+
runOnUiThread {
750+
addVideoToList(it.nameWithoutExtension, -1, i)
751+
}
752+
mediaPlayer.release()
753+
754+
false
755+
}
745756
} catch (e: Exception) {
746757

747758
}
@@ -774,11 +785,15 @@ class LiveActivity : AppCompatActivity(), ConnectCheckerRtmp, SurfaceHolder.Call
774785
rtmpCamera1 = RtmpCamera1(rtmpCameraPreview, this)
775786
rtmpCamera1!!.setReTries(100)
776787

777-
778788
rtmpFile = RtmpFromFile(rtmpFilePreview, this, this, this)
779789

780790
rtmpCameraPreview.holder.addCallback(this)
781791

792+
793+
// var info = MediaCodec.BufferInfo()
794+
// var buffer = ByteBuffer.allocate(100)
795+
// rtmpCamera1!!.getVideoData(buffer, info)
796+
782797
}
783798

784799
override fun onCreate(savedInstanceState: Bundle?) {
@@ -876,7 +891,11 @@ class LiveActivity : AppCompatActivity(), ConnectCheckerRtmp, SurfaceHolder.Call
876891

877892
var timeText = TextView(this)
878893
timeText.setTextColor(Color.GRAY)
879-
timeText.text = time.toString() + "s"
894+
if (time < 0) {
895+
timeText.text = "NaN"
896+
} else {
897+
timeText.text = time.toString() + "s"
898+
}
880899
timeText.layoutParams = Constraints.LayoutParams(
881900
ConstraintLayout.LayoutParams.WRAP_CONTENT,
882901
ConstraintLayout.LayoutParams.WRAP_CONTENT

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
include ':videotrimmer'
12
include ':app'
23
rootProject.name = "Live"

videotrimmer/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

videotrimmer/build.gradle

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
5+
android {
6+
compileSdkVersion 28
7+
8+
defaultConfig {
9+
minSdkVersion 19
10+
targetSdkVersion 28
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
kotlinOptions {
26+
freeCompilerArgs = ['-Xjvm-default=compatibility']
27+
jvmTarget = '1.8'
28+
}
29+
30+
androidExtensions {
31+
experimental = true
32+
}
33+
}
34+
35+
dependencies {
36+
implementation fileTree(dir: 'libs', include: ['*.jar'])
37+
38+
testImplementation 'junit:junit:4.12'
39+
androidTestImplementation 'androidx.test:runner:1.2.0'
40+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
41+
42+
implementation 'androidx.appcompat:appcompat:1.0.2'
43+
implementation 'androidx.core:core-ktx:1.0.2'
44+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
45+
implementation "androidx.recyclerview:recyclerview:1.1.0-beta01"
46+
47+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
48+
}

videotrimmer/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package idv.luchafang.videotrimmer;
2+
3+
import android.content.Context;
4+
import androidx.test.InstrumentationRegistry;
5+
import androidx.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("idv.luchafang.videotrimmer.test", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="idv.luchafang.videotrimmer"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package idv.luchafang.videotrimmer
2+
3+
internal fun obtainVideoTrimmerPresenter() = VideoTrimmerPresenter()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package idv.luchafang.videotrimmer
2+
3+
import idv.luchafang.videotrimmer.data.TrimmerDraft
4+
import java.io.File
5+
6+
internal interface VideoTrimmerContract {
7+
interface View {
8+
fun getSlidingWindowWidth(): Int
9+
fun setupAdaptor(video: File, frames: List<Long>, frameWidth: Int)
10+
fun setupSlidingWindow()
11+
12+
fun restoreSlidingWindow(left: Float, right: Float)
13+
fun restoreVideoFrameList(framePosition: Int, frameOffset: Int)
14+
}
15+
16+
interface Presenter {
17+
fun onViewAttached(view: View)
18+
fun onViewDetached()
19+
20+
fun setVideo(video: File)
21+
fun setMaxDuration(millis: Long)
22+
fun setMinDuration(millis: Long)
23+
fun setFrameCountInWindow(count: Int)
24+
fun setOnSelectedRangeChangedListener(listener: VideoTrimmerView.OnSelectedRangeChangedListener)
25+
26+
fun isValidState(): Boolean
27+
fun show()
28+
29+
fun getTrimmerDraft(): TrimmerDraft
30+
fun restoreTrimmer(draft: TrimmerDraft)
31+
}
32+
}

0 commit comments

Comments
 (0)