Quellcode durchsuchen

New: make movie play related fuction compatible muti scene

Shan-PC\Shan vor 6 Jahren
Ursprung
Commit
4c1c46a112

+ 21 - 11
src/main/java/com/bomostory/sceneeditmodule/MovieEditActivity.kt

@@ -10,15 +10,11 @@ import android.os.Bundle
 import android.os.Environment
 import android.os.Handler
 import android.support.v4.app.DialogFragment
-import android.util.Log
 import android.view.View
 import android.widget.CompoundButton
 import android.widget.SeekBar
 import android.widget.Toast
-import com.bomostory.sceneeditmodule.basicdata.DataParser
-import com.bomostory.sceneeditmodule.basicdata.Music
-import com.bomostory.sceneeditmodule.basicdata.Project
-import com.bomostory.sceneeditmodule.basicdata.Scene
+import com.bomostory.sceneeditmodule.basicdata.*
 import com.bomostory.sceneeditmodule.utils.MoviePlayer
 import com.bomostory.sceneeditmodule.utils.MusicPlayer
 import com.bomostory.sceneeditmodule.view.AudioTrackGroupView
@@ -92,10 +88,17 @@ class MovieEditActivity : AppCompatActivity(),
         set(value) {
             field = value
             value?.let {
-                it.story?.let {
-                    movieEditView.story = it
-                    scene = it.scenes[0]
-                }
+                story = it.story
+            }
+        }
+
+    private var story: Story? = null
+        set(value) {
+            field = value
+            moviePlayer.story = value
+            movieEditView.story = value
+            value?.let {
+                scene = it.scenes[0]
             }
         }
 
@@ -104,8 +107,6 @@ class MovieEditActivity : AppCompatActivity(),
             field = value
             value?.let {
                 movieView.scene = value
-                movieEditView.scene = value
-                moviePlayer.scene = value
             }
         }
 
@@ -187,7 +188,16 @@ class MovieEditActivity : AppCompatActivity(),
         }
 
         moviePlayer.moviePlayListener = object : MoviePlayer.OnMoviePlayListener {
+            override fun onMovieSceneUpdate(scene: Scene) {
+                if (scene != this@MovieEditActivity.scene) {
+                    this@MovieEditActivity.scene = scene
+                }
+            }
+
             override fun onMoviePlayComplete() {
+                story?.scenes?.let {
+                    this@MovieEditActivity.scene = it[0]
+                }
                 movieEditView.isBtnPanelEnable = true
             }
 

+ 60 - 16
src/main/java/com/bomostory/sceneeditmodule/utils/MoviePlayer.kt

@@ -1,6 +1,7 @@
 package com.bomostory.sceneeditmodule.utils
 
 import com.bomostory.sceneeditmodule.basicdata.Scene
+import com.bomostory.sceneeditmodule.basicdata.Story
 import io.reactivex.Observable
 import io.reactivex.Observer
 import io.reactivex.android.schedulers.AndroidSchedulers
@@ -11,6 +12,7 @@ import java.util.concurrent.atomic.AtomicLong
 
 class MoviePlayer {
     interface OnMoviePlayListener {
+        fun onMovieSceneUpdate(scene: Scene)
         fun onMoviePlayViewUpdate(x: Int)
         fun onMoviePlayTimeUpdate(time: Long)
         fun onMoviePlayComplete()
@@ -20,7 +22,20 @@ class MoviePlayer {
         const val INTERVAL_PERIOD: Long = 1
     }
 
-    var scene: Scene? = null
+    var story: Story? = null
+        set(value) {
+            field = value
+            value?.apply {
+                for (scene in scenes) {
+                    scene.record?.period?.let {
+                        totalPeriod += it
+                    }
+                }
+            }
+        }
+
+    var totalPeriod = 0L
+
     var musicPlayer = MusicPlayer()
 
     var moviePlayListener: OnMoviePlayListener? = null
@@ -31,7 +46,7 @@ class MoviePlayer {
         musicPlayer.add(path)
     }
 
-    fun removeMusic(path: String){
+    fun removeMusic(path: String) {
         musicPlayer.remove(path)
     }
 
@@ -74,20 +89,13 @@ class MoviePlayer {
                     }
 
                     override fun onNext(t: Long) {
-                        scene?.let {
-                            it.record?.let {
-                                for (track in it.tracks) {
-                                    if (track.time == t) {
-                                        moviePlayListener?.onMoviePlayViewUpdate(track.positionX)
-                                    }
-                                }
-
-                                moviePlayListener?.onMoviePlayTimeUpdate(t)
-
-                                if (t > (it.period / INTERVAL_PERIOD)) {
-                                    disposable?.dispose()
-                                    onComplete()
-                                }
+                        story?.apply {
+
+                            updateMovie(t)
+
+                            if (t > (totalPeriod / INTERVAL_PERIOD)) {
+                                disposable?.dispose()
+                                onComplete()
                             }
                         }
                     }
@@ -102,7 +110,43 @@ class MoviePlayer {
     fun seekTo(mSec: Int?) {
         mSec?.let {
             lastTick.set(it.toLong())
+            updateMovie(mSec.toLong())
             musicPlayer.seekTo(it)
         }
     }
+
+    private fun updateMovie(t: Long) {
+        val scene = getScene(t)
+        scene?.apply {
+            moviePlayListener?.onMovieSceneUpdate(this)
+            record?.let {
+                for (track in it.tracks) {
+                    if (track.time == t) {
+                        moviePlayListener?.onMoviePlayViewUpdate(track.positionX)
+                    }
+                }
+            }
+        }
+        moviePlayListener?.onMoviePlayTimeUpdate(t)
+    }
+
+    private fun getScene(t: Long): Scene? {
+        var currentScene: Scene? = null
+        var startPeriod = 0L
+        var endPeriod = 0L
+
+        story?.apply {
+            for (scene in scenes) {
+                scene.record?.apply {
+                    endPeriod += period
+                    if (t in startPeriod..endPeriod) {
+                        currentScene = scene
+                        startPeriod = endPeriod
+                    }
+                }
+            }
+        }
+
+        return currentScene
+    }
 }

+ 12 - 5
src/main/java/com/bomostory/sceneeditmodule/view/MovieEditView.kt

@@ -18,14 +18,21 @@ class MovieEditView : ConstraintLayout {
     var story: Story? = null
         set(value) {
             movieSelectView.story = value
+
+            value?.apply {
+                for (scene in scenes) {
+                    scene.record?.let {
+                        period += it.period
+                    }
+                }
+            }
         }
 
-    var scene: Scene? = null
+    var period: Long = 0
         set(value) {
-            movieSeekView.scene = value
-            value?.record?.period?.let {
-                audioTrackGroupView.scenePeriod = it
-            }
+            field = value
+            audioTrackGroupView.scenePeriod = value
+            movieSeekView.period = value
         }
 
     var playTime: Long = 0

+ 5 - 11
src/main/java/com/bomostory/sceneeditmodule/view/MovieSeekView.kt

@@ -6,24 +6,18 @@ import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.view.View
 import android.widget.SeekBar
-import com.bomostory.sceneeditmodule.basicdata.Scene
 import com.bomostory.sceneeditmodule.utils.TimeUtils
 import com.example.tfat.myapplication.R
 import kotlinx.android.synthetic.main.movie_seek_view.view.*
 
 class MovieSeekView : ConstraintLayout {
 
-    var scene: Scene? = null
+    var period: Long = 0
         set(value) {
-            field = value
-            value?.let {
-                it.record?.let {
-                    progressTime.text = TimeUtils.getPlayMovieTimeFormat(playTime)
-                    totalTime.text = TimeUtils.getPlayMovieTimeFormat(it.period)
-                    seekBar.progress = playTime.toInt()
-                    seekBar.max = it.period.toInt()
-                }
-            }
+            progressTime.text = TimeUtils.getPlayMovieTimeFormat(playTime)
+            totalTime.text = TimeUtils.getPlayMovieTimeFormat(value)
+            seekBar.progress = playTime.toInt()
+            seekBar.max = value.toInt()
         }
 
     var playTime: Long = 0