|
@@ -1,6 +1,7 @@
|
|
package com.bomostory.sceneeditmodule.utils
|
|
package com.bomostory.sceneeditmodule.utils
|
|
|
|
|
|
import com.bomostory.sceneeditmodule.basicdata.Scene
|
|
import com.bomostory.sceneeditmodule.basicdata.Scene
|
|
|
|
+import com.bomostory.sceneeditmodule.basicdata.Story
|
|
import io.reactivex.Observable
|
|
import io.reactivex.Observable
|
|
import io.reactivex.Observer
|
|
import io.reactivex.Observer
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
@@ -11,6 +12,7 @@ import java.util.concurrent.atomic.AtomicLong
|
|
|
|
|
|
class MoviePlayer {
|
|
class MoviePlayer {
|
|
interface OnMoviePlayListener {
|
|
interface OnMoviePlayListener {
|
|
|
|
+ fun onMovieSceneUpdate(scene: Scene)
|
|
fun onMoviePlayViewUpdate(x: Int)
|
|
fun onMoviePlayViewUpdate(x: Int)
|
|
fun onMoviePlayTimeUpdate(time: Long)
|
|
fun onMoviePlayTimeUpdate(time: Long)
|
|
fun onMoviePlayComplete()
|
|
fun onMoviePlayComplete()
|
|
@@ -20,7 +22,20 @@ class MoviePlayer {
|
|
const val INTERVAL_PERIOD: Long = 1
|
|
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 musicPlayer = MusicPlayer()
|
|
|
|
|
|
var moviePlayListener: OnMoviePlayListener? = null
|
|
var moviePlayListener: OnMoviePlayListener? = null
|
|
@@ -31,7 +46,7 @@ class MoviePlayer {
|
|
musicPlayer.add(path)
|
|
musicPlayer.add(path)
|
|
}
|
|
}
|
|
|
|
|
|
- fun removeMusic(path: String){
|
|
|
|
|
|
+ fun removeMusic(path: String) {
|
|
musicPlayer.remove(path)
|
|
musicPlayer.remove(path)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,20 +89,13 @@ class MoviePlayer {
|
|
}
|
|
}
|
|
|
|
|
|
override fun onNext(t: Long) {
|
|
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?) {
|
|
fun seekTo(mSec: Int?) {
|
|
mSec?.let {
|
|
mSec?.let {
|
|
lastTick.set(it.toLong())
|
|
lastTick.set(it.toLong())
|
|
|
|
+ updateMovie(mSec.toLong())
|
|
musicPlayer.seekTo(it)
|
|
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
|
|
|
|
+ }
|
|
}
|
|
}
|