Parcourir la source

Merge branch 'export-video'

Wayne il y a 6 ans
Parent
commit
e8eb266cf8

Fichier diff supprimé car celui-ci est trop grand
+ 17 - 11
src/main/java/com/bomostory/sceneeditmodule/MovieEditActivity.kt


+ 31 - 23
src/main/java/com/bomostory/sceneeditmodule/SuperMovieMaker.kt

@@ -7,6 +7,7 @@ import android.graphics.Paint
 import android.util.Log
 import com.bomostory.sceneeditmodule.MovieEditActivity.Companion.FPS
 import com.bomostory.sceneeditmodule.basicdata.Music
+import com.bomostory.sceneeditmodule.basicdata.Project
 import com.bomostory.sceneeditmodule.basicdata.Scene
 import com.example.exportmedia.MediaHelper
 import com.example.exportmedia.data.AudioSource
@@ -26,7 +27,7 @@ class SuperMovieMaker {
 
     fun make(
             outputFile: File,
-            scene: Scene,
+            project: Project,
             musics: List<Music>,
             scaleWidth: Int,
             scaleHeight: Int,
@@ -37,7 +38,7 @@ class SuperMovieMaker {
             movieBuilder.audioSources = generateAudioSource(musics)
 
             val inputSceneStatus = LinkedHashMap<Int, Int>()
-            val frameDataList = generateFrameDataList(scene)
+            val frameDataList = generateFrameDataList(project)
             var bitmapIndex = 0
             val permitCount = frameDataList.size
             val semaphore = Semaphore(permitCount)
@@ -50,8 +51,11 @@ class SuperMovieMaker {
                 inputSceneStatus[i] = frameData.repeat
                 semaphore.acquire()
                 Completable.create {
-                    val bitmap = drawScene(scene, frameData.x, scaleWidth, scaleHeight)
-                    movieBuilder.addImage(i, bitmap!!).blockingSubscribe()
+                    project?.story?.apply {
+                        val scene = scenes[frameData.sceneIndex]
+                        val bitmap = drawScene(scene, frameData.x, scaleWidth, scaleHeight)
+                        movieBuilder.addImage(i, bitmap!!).blockingSubscribe()
+                    }
                     it.onComplete()
                 }
                         .subscribeOn(Schedulers.computation())
@@ -83,28 +87,32 @@ class SuperMovieMaker {
         return audioSources
     }
 
-    fun generateFrameDataList(scene: Scene): List<FrameData> {
+    fun generateFrameDataList(project: Project): List<FrameData> {
         val frameDataList = ArrayList<FrameData>()
-        scene.record?.apply {
-            var x = 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) {
-                        x = track.positionX
-                        trackPosition = tracks.indexOf(track)
+        var index = 0
+        project.story?.scenes?.forEach { scene ->
+            val sceneIndex = index++
+            scene.record?.apply {
+                var x = 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) {
+                            x = track.positionX
+                            trackPosition = tracks.indexOf(track)
+                        }
                     }
-                }
 
-                if (frameDataList.isEmpty()) {
-                    frameDataList.add(FrameData(x, 1))
-                } else {
-                    val frameData = frameDataList.last()
-                    if (frameData.x == x) {
-                        frameData.repeat++
+                    if (frameDataList.isEmpty()) {
+                        frameDataList.add(FrameData(sceneIndex, x, 1))
                     } else {
-                        frameDataList.add(FrameData(x, 1))
+                        val frameData = frameDataList.last()
+                        if (frameData.x == x) {
+                            frameData.repeat++
+                        } else {
+                            frameDataList.add(FrameData(sceneIndex, x, 1))
+                        }
                     }
                 }
             }
@@ -170,5 +178,5 @@ class SuperMovieMaker {
         return sceneBitmap
     }
 
-    data class FrameData(var x: Int, var repeat: Int)
+    data class FrameData(val sceneIndex: Int, val x: Int, var repeat: Int)
 }