Переглянути джерело

Merge branch 'master' of git.kdan.cc:Bomo/Bomo_for_Android_editorModule

faterhenry 6 роки тому
батько
коміт
96478d3337

+ 15 - 13
src/main/java/com/bomostory/sceneeditmodule/MovieEditActivity.kt

@@ -19,13 +19,11 @@ import com.bomostory.sceneeditmodule.view.MovieSelectView
 import com.example.tfat.myapplication.R
 import com.google.gson.Gson
 import io.reactivex.Observable
-import io.reactivex.android.schedulers.AndroidSchedulers
 import io.reactivex.schedulers.Schedulers
 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 io.reactivex.Completable
 import java.io.File
 import java.util.AbstractMap
 import kotlin.math.pow
@@ -250,16 +248,20 @@ class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener
     }
 
     private fun saveMovie(view: View) {
-        Completable.create {
-            val movieBuilder = MovieMaker.Builder(mediaHelper)
-            movieBuilder.fps = FPS
-            movieBuilder.audioSources = generateAudioSource()
-            generateMovieFilms(movieBuilder).subscribe()
-            movieBuilder.build().output(File(Environment.getExternalStorageDirectory(), "test.mp4")).subscribe()
-        }
+        val movieBuilder = MovieMaker.Builder(mediaHelper)
+        movieBuilder.fps = FPS
+        movieBuilder.audioSources = generateAudioSource()
+        generateMovieFilms()
                 .subscribeOn(Schedulers.io())
-                .observeOn(AndroidSchedulers.mainThread())
-                .subscribe({}, {})
+                .subscribe({
+                    movieBuilder.addImage(it.key, it.value).subscribe()
+                }, {
+
+                }, {
+                    val movieMaker = movieBuilder.build()
+                    movieMaker.output(File(Environment.getExternalStorageDirectory(), "test.mp4")).subscribe()
+                })
+
     }
 
     private fun generateAudioSource(): ArrayList<AudioSource> {
@@ -274,7 +276,7 @@ class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener
         return audioSources
     }
 
-    private fun generateMovieFilms(movieBuilder: MovieMaker.Builder): Observable<AbstractMap.SimpleEntry<Int, Bitmap>> {
+    private fun generateMovieFilms(): Observable<AbstractMap.SimpleEntry<Int, Bitmap>> {
         var preBitmap: Bitmap?
         return Observable.create<AbstractMap.SimpleEntry<Int, Bitmap>> {
             scene?.apply {
@@ -294,7 +296,7 @@ class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener
                             }
                         }
                         bitmap?.apply {
-                            movieBuilder.addImage(bitmapIndex++, this).subscribe()
+                            it.onNext(AbstractMap.SimpleEntry(bitmapIndex++, this))
                             Log.d("Debug", "Index: $bitmapIndex  Time: $t")
                         }
                     }