|
@@ -6,6 +6,7 @@ import com.bomostory.sceneeditmodule.basicdata.Scene
|
|
import com.bomostory.sceneeditmodule.basicdata.Story
|
|
import com.bomostory.sceneeditmodule.basicdata.Story
|
|
import java.util.*
|
|
import java.util.*
|
|
import kotlin.collections.ArrayList
|
|
import kotlin.collections.ArrayList
|
|
|
|
+import kotlin.collections.HashMap
|
|
|
|
|
|
class MoviePlayerV2 {
|
|
class MoviePlayerV2 {
|
|
interface OnMoviePlayListener {
|
|
interface OnMoviePlayListener {
|
|
@@ -29,7 +30,10 @@ class MoviePlayerV2 {
|
|
|
|
|
|
var musicList: List<Music> = ArrayList()
|
|
var musicList: List<Music> = ArrayList()
|
|
|
|
|
|
- var mediaPlayers = ArrayList<MediaPlayer>()
|
|
|
|
|
|
+ private var mediaPlayers = ArrayList<MediaPlayer>()
|
|
|
|
+
|
|
|
|
+ private val recordPlayers = HashMap<Int, MediaPlayer>()
|
|
|
|
+
|
|
|
|
|
|
fun init() {
|
|
fun init() {
|
|
isPause = false
|
|
isPause = false
|
|
@@ -42,8 +46,12 @@ class MoviePlayerV2 {
|
|
|
|
|
|
updateMovie()
|
|
updateMovie()
|
|
|
|
|
|
|
|
+ tryStopRecord()
|
|
|
|
+
|
|
tryStopMusic()
|
|
tryStopMusic()
|
|
|
|
|
|
|
|
+ initRecord()
|
|
|
|
+
|
|
initMediaPlayer()
|
|
initMediaPlayer()
|
|
|
|
|
|
}
|
|
}
|
|
@@ -59,6 +67,8 @@ class MoviePlayerV2 {
|
|
|
|
|
|
updateMovie()
|
|
updateMovie()
|
|
|
|
|
|
|
|
+ tryPlayRecord()
|
|
|
|
+
|
|
tryPlayMusic()
|
|
tryPlayMusic()
|
|
|
|
|
|
if (currentTime >= period) {
|
|
if (currentTime >= period) {
|
|
@@ -76,6 +86,8 @@ class MoviePlayerV2 {
|
|
fun pause() {
|
|
fun pause() {
|
|
isPause = true
|
|
isPause = true
|
|
|
|
|
|
|
|
+ tryPauseRecord()
|
|
|
|
+
|
|
tryPauseMusic()
|
|
tryPauseMusic()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -84,6 +96,8 @@ class MoviePlayerV2 {
|
|
|
|
|
|
updateMovie()
|
|
updateMovie()
|
|
|
|
|
|
|
|
+ trySeekRecord()
|
|
|
|
+
|
|
trySeekMusic()
|
|
trySeekMusic()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -121,8 +135,26 @@ class MoviePlayerV2 {
|
|
return currentScene
|
|
return currentScene
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun initRecord() {
|
|
|
|
+ recordPlayers.clear()
|
|
|
|
+ story?.let { story ->
|
|
|
|
+ for (scene in story.scenes) {
|
|
|
|
+ scene.recordPath?.let {
|
|
|
|
+ val mediaPlayer = MediaPlayer()
|
|
|
|
+ mediaPlayer.apply {
|
|
|
|
+ reset()
|
|
|
|
+ setDataSource(scene.recordPath)
|
|
|
|
+ prepare()
|
|
|
|
+ }
|
|
|
|
+ recordPlayers.put(story.scenes.indexOf(scene), mediaPlayer)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private fun initMediaPlayer() {
|
|
private fun initMediaPlayer() {
|
|
mediaPlayers.clear()
|
|
mediaPlayers.clear()
|
|
|
|
+
|
|
for (music in musicList) {
|
|
for (music in musicList) {
|
|
val mediaPlayer = MediaPlayer()
|
|
val mediaPlayer = MediaPlayer()
|
|
mediaPlayer.apply {
|
|
mediaPlayer.apply {
|
|
@@ -135,9 +167,19 @@ class MoviePlayerV2 {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun tryPlayRecord() {
|
|
|
|
+ story?.let {
|
|
|
|
+ recordPlayers[it.scenes.indexOf(getScene(currentTime))]?.apply {
|
|
|
|
+ if (!isPlaying) {
|
|
|
|
+ start()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private fun tryPlayMusic() {
|
|
private fun tryPlayMusic() {
|
|
for (music in musicList) {
|
|
for (music in musicList) {
|
|
- val musicEndTime = if(music.isLoop) (music.offsetTime + music.endTime - music.startTime) + music.loopDuration else (music.offsetTime + music.endTime - music.startTime)
|
|
|
|
|
|
+ val musicEndTime = if (music.isLoop) (music.offsetTime + music.endTime - music.startTime) + music.loopDuration else (music.offsetTime + music.endTime - music.startTime)
|
|
|
|
|
|
if (currentTime in music.offsetTime..musicEndTime) {
|
|
if (currentTime in music.offsetTime..musicEndTime) {
|
|
if (!mediaPlayers[musicList.indexOf(music)].isPlaying) {
|
|
if (!mediaPlayers[musicList.indexOf(music)].isPlaying) {
|
|
@@ -150,18 +192,42 @@ class MoviePlayerV2 {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun tryPauseRecord() {
|
|
|
|
+ recordPlayers.forEach {
|
|
|
|
+ it.value.pause()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private fun tryPauseMusic() {
|
|
private fun tryPauseMusic() {
|
|
for (mediaPlayer in mediaPlayers) {
|
|
for (mediaPlayer in mediaPlayers) {
|
|
mediaPlayer.pause()
|
|
mediaPlayer.pause()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun trySeekRecord() {
|
|
|
|
+ story?.let {
|
|
|
|
+ var period: Long = 0
|
|
|
|
+ for (i in 0 until it.scenes.indexOf(getScene(currentTime))) {
|
|
|
|
+ period += (it.scenes[i].record?.period ?: 0)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ recordPlayers[it.scenes.indexOf(getScene(currentTime))]?.apply {
|
|
|
|
+ if (period == 0L) {
|
|
|
|
+ this.seekTo(currentTime.toInt())
|
|
|
|
+ } else {
|
|
|
|
+ this.seekTo((currentTime % period).toInt())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private fun trySeekMusic() {
|
|
private fun trySeekMusic() {
|
|
for (music in musicList) {
|
|
for (music in musicList) {
|
|
- val musicEndTime = if(music.isLoop) (music.offsetTime + music.endTime - music.startTime) + music.loopDuration else (music.offsetTime + music.endTime - music.startTime)
|
|
|
|
|
|
+ val musicEndTime = if (music.isLoop) (music.offsetTime + music.endTime - music.startTime) + music.loopDuration else (music.offsetTime + music.endTime - music.startTime)
|
|
|
|
|
|
if (currentTime in music.offsetTime..musicEndTime) {
|
|
if (currentTime in music.offsetTime..musicEndTime) {
|
|
- val actualTime = if (currentTime - music.offsetTime >= music.endTime - music.startTime)((currentTime - music.offsetTime).toDouble() / (music.endTime - music.startTime)).toInt()
|
|
|
|
|
|
+ val actualTime = if (currentTime - music.offsetTime >= music.endTime - music.startTime) ((currentTime - music.offsetTime).toDouble() / (music.endTime - music.startTime)).toInt()
|
|
else (currentTime - music.offsetTime).toInt()
|
|
else (currentTime - music.offsetTime).toInt()
|
|
mediaPlayers[musicList.indexOf(music)].seekTo(actualTime)
|
|
mediaPlayers[musicList.indexOf(music)].seekTo(actualTime)
|
|
} else {
|
|
} else {
|
|
@@ -171,10 +237,15 @@ class MoviePlayerV2 {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private fun tryStopMusic(){
|
|
|
|
|
|
+ private fun tryStopRecord() {
|
|
|
|
+ recordPlayers.forEach {
|
|
|
|
+ it.value.stop()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun tryStopMusic() {
|
|
for (mediaPlayer in mediaPlayers) {
|
|
for (mediaPlayer in mediaPlayers) {
|
|
mediaPlayer.stop()
|
|
mediaPlayer.stop()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|