|
@@ -1,13 +1,13 @@
|
|
package com.bomostory.sceneeditmodule
|
|
package com.bomostory.sceneeditmodule
|
|
|
|
|
|
|
|
+import android.app.AlertDialog
|
|
|
|
+import android.app.ProgressDialog
|
|
import android.content.DialogInterface
|
|
import android.content.DialogInterface
|
|
-import android.graphics.*
|
|
|
|
-import android.support.v7.app.AppCompatActivity
|
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
import android.os.Environment
|
|
import android.os.Environment
|
|
import android.os.Handler
|
|
import android.os.Handler
|
|
import android.support.v4.app.DialogFragment
|
|
import android.support.v4.app.DialogFragment
|
|
-import android.util.Log
|
|
|
|
|
|
+import android.support.v7.app.AppCompatActivity
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.widget.CompoundButton
|
|
import android.widget.CompoundButton
|
|
import android.widget.SeekBar
|
|
import android.widget.SeekBar
|
|
@@ -16,17 +16,13 @@ import com.bomostory.sceneeditmodule.utils.MoviePlayer
|
|
import com.bomostory.sceneeditmodule.utils.MusicPlayer
|
|
import com.bomostory.sceneeditmodule.utils.MusicPlayer
|
|
import com.bomostory.sceneeditmodule.view.AudioTrackGroupView
|
|
import com.bomostory.sceneeditmodule.view.AudioTrackGroupView
|
|
import com.bomostory.sceneeditmodule.view.MovieSelectView
|
|
import com.bomostory.sceneeditmodule.view.MovieSelectView
|
|
|
|
+import com.example.exportmedia.MediaHelper
|
|
import com.example.tfat.myapplication.R
|
|
import com.example.tfat.myapplication.R
|
|
import com.google.gson.Gson
|
|
import com.google.gson.Gson
|
|
-import io.reactivex.Observable
|
|
|
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers
|
|
import io.reactivex.schedulers.Schedulers
|
|
import io.reactivex.schedulers.Schedulers
|
|
import kotlinx.android.synthetic.main.activity_movie_edit.*
|
|
import kotlinx.android.synthetic.main.activity_movie_edit.*
|
|
-import com.example.exportmedia.MediaHelper
|
|
|
|
-import com.example.exportmedia.data.AudioSource
|
|
|
|
-import com.example.exportmedia.vedio.MovieMaker
|
|
|
|
import java.io.File
|
|
import java.io.File
|
|
-import java.util.AbstractMap
|
|
|
|
-import kotlin.math.pow
|
|
|
|
|
|
|
|
|
|
|
|
class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener, MusicSelectFragment.OnFragmentInteractionListener {
|
|
class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener, MusicSelectFragment.OnFragmentInteractionListener {
|
|
@@ -248,113 +244,41 @@ class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener
|
|
}
|
|
}
|
|
|
|
|
|
private fun saveMovie(view: View) {
|
|
private fun saveMovie(view: View) {
|
|
- val inputSceneStatus = LinkedHashMap<Int, Int>()
|
|
|
|
- var sceneIndex = -1
|
|
|
|
- var sceneRepeatCount = 0
|
|
|
|
- var sceneCount = 0
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- val movieBuilder = MovieMaker.Builder(mediaHelper)
|
|
|
|
- movieBuilder.fps = FPS
|
|
|
|
- movieBuilder.audioSources = generateAudioSource()
|
|
|
|
|
|
+ val scaledWidth = resources.getDimensionPixelSize(R.dimen.movie_width)
|
|
|
|
+ val scaleHeight = resources.getDimensionPixelSize(R.dimen.movie_height)
|
|
|
|
|
|
- var totalFrame = 0
|
|
|
|
- scene?.record?.period?.let {
|
|
|
|
- totalFrame = (it/((1f / FPS) * 1000).toLong()).toInt()
|
|
|
|
|
|
+ val pd = ProgressDialog(this).apply {
|
|
|
|
+ val t = scene?.record?.period ?: 0
|
|
|
|
+ max = (t / 33).toInt()
|
|
|
|
+ setMessage("progressing")
|
|
}
|
|
}
|
|
|
|
|
|
- generateMovieFilms()
|
|
|
|
|
|
+ val fileName = "test${System.currentTimeMillis()}.mp4"
|
|
|
|
+ val outputFile = File(Environment.getExternalStorageDirectory(), fileName)
|
|
|
|
+ val s = scene ?: return
|
|
|
|
+
|
|
|
|
+ SuperMovieMaker().make(
|
|
|
|
+ outputFile,
|
|
|
|
+ s,
|
|
|
|
+ musics,
|
|
|
|
+ scaledWidth,
|
|
|
|
+ scaleHeight,
|
|
|
|
+ mediaHelper)
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
+ .doOnSubscribe { pd.show() }
|
|
|
|
+ .doFinally { pd.dismiss() }
|
|
.subscribe({
|
|
.subscribe({
|
|
- Log.d("Debug","progress ${sceneCount++}/$totalFrame")
|
|
|
|
- if (it.key == sceneIndex) {
|
|
|
|
- sceneRepeatCount++
|
|
|
|
- } else {
|
|
|
|
- sceneIndex = it.key
|
|
|
|
- sceneRepeatCount = 1
|
|
|
|
- movieBuilder.addImage(it.key, it.value).subscribe()
|
|
|
|
- }
|
|
|
|
- inputSceneStatus[sceneIndex] = sceneRepeatCount
|
|
|
|
|
|
+ pd.setMessage(it)
|
|
}, {
|
|
}, {
|
|
-
|
|
|
|
|
|
+ val msg = """
|
|
|
|
+ Error:
|
|
|
|
+ ${it.message}
|
|
|
|
+ """.trimIndent()
|
|
|
|
+ AlertDialog.Builder(this).setMessage(msg).show()
|
|
}, {
|
|
}, {
|
|
- movieBuilder.addInputFile(inputSceneStatus).subscribe({
|
|
|
|
- movieBuilder.inputFilePath = it
|
|
|
|
- }, {
|
|
|
|
-
|
|
|
|
- }, {
|
|
|
|
- val movieMaker = movieBuilder.build()
|
|
|
|
- movieMaker.output(File(Environment.getExternalStorageDirectory(), "test.mp4")).subscribe()
|
|
|
|
- })
|
|
|
|
|
|
+ AlertDialog.Builder(this).setMessage("complete").show()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- private fun generateAudioSource(): ArrayList<AudioSource> {
|
|
|
|
- val audioSources = ArrayList<AudioSource>()
|
|
|
|
- for (music in musics) {
|
|
|
|
- val audioSource = AudioSource()
|
|
|
|
- audioSource.duration = music.duration
|
|
|
|
- audioSource.offsetSec = music.offsetTime.toFloat() / 1000
|
|
|
|
- audioSource.path = music.path
|
|
|
|
- audioSources.add(audioSource)
|
|
|
|
- }
|
|
|
|
- return audioSources
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private fun generateMovieFilms(): Observable<AbstractMap.SimpleEntry<Int, Bitmap>> {
|
|
|
|
- var preBitmap: Bitmap?
|
|
|
|
- return Observable.create<AbstractMap.SimpleEntry<Int, Bitmap>> {
|
|
|
|
- scene?.apply {
|
|
|
|
- record?.apply {
|
|
|
|
- var bitmap = drawScene(0)
|
|
|
|
- var bitmapIndex = 0
|
|
|
|
- var trackPosition = -1
|
|
|
|
-
|
|
|
|
- for (t in 0 .. period step ((1f / FPS) * 1000).toLong()) {
|
|
|
|
- for (track in tracks) {
|
|
|
|
- if (t >= track.time && tracks.indexOf(track) > trackPosition) {
|
|
|
|
- preBitmap = bitmap
|
|
|
|
- preBitmap?.recycle()
|
|
|
|
-
|
|
|
|
- bitmap = drawScene(track.positionX)
|
|
|
|
- trackPosition = tracks.indexOf(track)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- bitmap?.apply {
|
|
|
|
- it.onNext(AbstractMap.SimpleEntry(bitmapIndex++, this))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- it.onComplete()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private fun drawScene(trackX: Int): Bitmap? {
|
|
|
|
- var sceneBitmap: Bitmap? = null
|
|
|
|
- val scaledWidth = resources.getDimensionPixelSize(R.dimen.movie_width)
|
|
|
|
- val scaleHeight = resources.getDimensionPixelSize(R.dimen.movie_height)
|
|
|
|
-
|
|
|
|
- scene?.apply {
|
|
|
|
- sceneBitmap = BitmapFactory.decodeFile(backgroundPath)
|
|
|
|
- sceneBitmap = Bitmap.createScaledBitmap(sceneBitmap, scaledWidth, scaleHeight, true)
|
|
|
|
-
|
|
|
|
- val canvas = Canvas(sceneBitmap)
|
|
|
|
- for (layer in layers) {
|
|
|
|
- for (actor in layer.actors) {
|
|
|
|
- var actorBitmap = BitmapFactory.decodeFile(actor.resourcePath)
|
|
|
|
- actorBitmap = Bitmap.createScaledBitmap(actorBitmap, actor.sideLength, actor.sideLength, true)
|
|
|
|
-
|
|
|
|
- canvas.save()
|
|
|
|
- canvas.translate(trackX / 2f.pow(layers.indexOf(layer)), 0f)
|
|
|
|
- canvas.drawBitmap(actorBitmap, actor.positionX.toFloat(), actor.positionY.toFloat(), Paint())
|
|
|
|
- canvas.restore()
|
|
|
|
-
|
|
|
|
- actorBitmap.recycle()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return sceneBitmap
|
|
|
|
- }
|
|
|
|
}
|
|
}
|