Procházet zdrojové kódy

Merge remote-tracking branch 'origin/master'

cooperku_kdanmobile před 6 roky
rodič
revize
006e3dc03d

+ 35 - 4
src/main/java/com/bomostory/sceneeditmodule/SuperMovieMaker.kt

@@ -1,14 +1,13 @@
 package com.bomostory.sceneeditmodule
 
 import android.content.Context
-import android.graphics.Bitmap
 import android.media.MediaMetadataRetriever
 import android.os.Environment
 import android.util.Log
 import com.bomostory.sceneeditmodule.screen.movie.MovieEditActivity.Companion.FPS
 import com.bomostory.sceneeditmodule.basicdata.Music
 import com.bomostory.sceneeditmodule.basicdata.Project
-import com.bomostory.sceneeditmodule.basicdata.Scene
+import com.bomostory.sceneeditmodule.basicdata.Story
 import com.example.exportmedia.MediaHelper
 import com.example.exportmedia.audio.AudioLooper
 import com.example.exportmedia.data.AudioSource
@@ -17,7 +16,6 @@ import io.reactivex.Completable
 import io.reactivex.Observable
 import io.reactivex.schedulers.Schedulers
 import java.io.File
-import java.util.AbstractMap
 import java.util.concurrent.Semaphore
 import kotlin.collections.ArrayList
 import kotlin.collections.LinkedHashMap
@@ -35,9 +33,15 @@ class SuperMovieMaker {
             mediaHelper: MediaHelper): Observable<String> {
         return Observable.create<String> { emitter ->
             try {
+                val audioSources = ArrayList<AudioSource>()
+                project.story?.let {
+                    audioSources.addAll(generateRecordSource(it))
+                }
+                audioSources.addAll(generateAudioSource(musics, mediaHelper))
+
                 val movieBuilder = MovieMaker.Builder(mediaHelper)
                 movieBuilder.fps = FPS
-                movieBuilder.audioSources = generateAudioSource(musics, mediaHelper)
+                movieBuilder.audioSources = audioSources
 
                 val inputSceneStatus = LinkedHashMap<Int, Int>()
                 val frameDataList = generateFrameDataList(project)
@@ -80,6 +84,33 @@ class SuperMovieMaker {
         }
     }
 
+    private fun generateRecordSource(story: Story): ArrayList<AudioSource> {
+        val audioSources = ArrayList<AudioSource>()
+
+        var period: Long = 0
+        for (scene in story.scenes) {
+            val mediaMetadataRetriever = MediaMetadataRetriever()
+            val audioSource = AudioSource()
+
+            scene.recordPath?.let {
+                try {
+                    mediaMetadataRetriever.setDataSource(it)
+
+                    audioSource.path = scene.recordPath
+                    audioSource.duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toLong()
+                    audioSource.offsetSec = period.toFloat() / 1000
+
+                    audioSources.add(audioSource)
+                } catch (e: Exception) {
+
+                }
+            }
+
+            period += scene.record?.period ?: 0
+        }
+        return audioSources
+    }
+
     private fun generateAudioSource(musics: List<Music>, mediaHelper: MediaHelper): ArrayList<AudioSource> {
         val audioSources = ArrayList<AudioSource>()
         for (music in musics) {