@@ -4,6 +4,7 @@ import android.content.Context
4
4
import android.content.Intent
5
5
import android.databinding.DataBindingUtil
6
6
import android.os.Bundle
7
+ import android.text.format.DateFormat
7
8
import android.view.View
8
9
import android.view.WindowManager
9
10
import com.shuyu.gsyvideoplayer.GSYPreViewManager
@@ -19,11 +20,14 @@ import me.sweetll.tucao.base.BaseActivity
19
20
import me.sweetll.tucao.model.json.Part
20
21
import me.sweetll.tucao.business.video.adapter.StandardVideoAllCallBackAdapter
21
22
import me.sweetll.tucao.databinding.ActivityCachedVideoBinding
23
+ import me.sweetll.tucao.extension.HistoryHelpers
22
24
import me.sweetll.tucao.extension.setUp
23
25
import me.sweetll.tucao.extension.toast
26
+ import me.sweetll.tucao.model.json.Video
24
27
import me.sweetll.tucao.widget.DanmuVideoPlayer
25
28
import tv.danmaku.ijk.media.player.IjkMediaPlayer
26
29
import java.io.File
30
+ import java.util.*
27
31
28
32
class CachedVideoActivity : BaseActivity (), DanmuVideoPlayer.DanmuPlayerHolder {
29
33
lateinit var binding: ActivityCachedVideoBinding
@@ -33,12 +37,17 @@ class CachedVideoActivity : BaseActivity(), DanmuVideoPlayer.DanmuPlayerHolder {
33
37
var isPlay = false
34
38
var isPause = false
35
39
40
+ var firstPlay = true
41
+
42
+ lateinit var video: Video
43
+ lateinit var selectedPart: Part
44
+
36
45
companion object {
37
- private val ARG_PART = " part "
46
+ private val ARG_VIDEO = " video "
38
47
39
- fun intentTo (context : Context , part : Part ) {
48
+ fun intentTo (context : Context , video : Video ) {
40
49
val intent = Intent (context, CachedVideoActivity ::class .java)
41
- intent.putExtra(ARG_PART , part )
50
+ intent.putExtra(ARG_VIDEO , video )
42
51
context.startActivity(intent)
43
52
}
44
53
}
@@ -47,11 +56,22 @@ class CachedVideoActivity : BaseActivity(), DanmuVideoPlayer.DanmuPlayerHolder {
47
56
window.setFlags(WindowManager .LayoutParams .FLAG_FULLSCREEN , WindowManager .LayoutParams .FLAG_FULLSCREEN )
48
57
49
58
binding = DataBindingUtil .setContentView(this , R .layout.activity_cached_video)
50
- val part: Part = intent.getParcelableExtra(ARG_PART )
59
+ video = intent.getParcelableExtra(ARG_VIDEO )
60
+ selectedPart = video.parts[0 ]
61
+
62
+ HistoryHelpers .loadPlayHistory()
63
+ .flatMap { it.parts }
64
+ .find { it.vid == selectedPart.vid }
65
+ ?.let {
66
+ selectedPart.hadPlay = true
67
+ selectedPart.lastPlayPosition = it.lastPlayPosition
68
+ }
69
+
70
+
51
71
setupPlayer()
52
- loadPart(part )
72
+ loadPart(selectedPart )
53
73
54
- val danmuFile = File (part .durls[0 ].cacheFolderPath, " danmu.xml" )
74
+ val danmuFile = File (selectedPart .durls[0 ].cacheFolderPath, " danmu.xml" )
55
75
if (danmuFile.exists()) {
56
76
loadDanmuUri(danmuFile.absolutePath)
57
77
} else {
@@ -88,7 +108,14 @@ class CachedVideoActivity : BaseActivity(), DanmuVideoPlayer.DanmuPlayerHolder {
88
108
override fun onPrepared (url : String? ) {
89
109
super .onPrepared(url)
90
110
isPlay = true
111
+ if (firstPlay) {
112
+ firstPlay = false
113
+ if (selectedPart.lastPlayPosition != 0 ) {
114
+ binding.player.showJump(selectedPart.lastPlayPosition)
115
+ }
116
+ }
91
117
}
118
+
92
119
})
93
120
94
121
binding.player.fullscreenButton.visibility = View .GONE
@@ -119,7 +146,7 @@ class CachedVideoActivity : BaseActivity(), DanmuVideoPlayer.DanmuPlayerHolder {
119
146
120
147
override fun onPause () {
121
148
super .onPause()
122
- binding.player.onVideoPause()
149
+ binding.player.onVideoPause(isPlay )
123
150
isPause = true
124
151
}
125
152
@@ -141,6 +168,16 @@ class CachedVideoActivity : BaseActivity(), DanmuVideoPlayer.DanmuPlayerHolder {
141
168
}
142
169
143
170
override fun onSavePlayHistory (position : Int ) {
144
- // DO nothing
171
+ HistoryHelpers .savePlayHistory(
172
+ video.copy(create = DateFormat .format(" yyyy-MM-dd hh:mm:ss" , Date ()).toString())
173
+ .also {
174
+ it.parts = video.parts.filter {
175
+ it.vid == selectedPart.vid
176
+ }.map {
177
+ it.lastPlayPosition = position
178
+ it
179
+ }.toMutableList()
180
+ }
181
+ )
145
182
}
146
183
}
0 commit comments