將VideoView的retryCount封裝
This commit is contained in:
parent
90344d14b0
commit
792ebc70c2
@ -132,7 +132,7 @@ class SplitViewFragment : Fragment() {
|
|||||||
if (position >= data.size) return@setOnClickListener
|
if (position >= data.size) return@setOnClickListener
|
||||||
if (!videoViews[position].isPlaying) {
|
if (!videoViews[position].isPlaying) {
|
||||||
if (!videoViews[position].isLoading) {
|
if (!videoViews[position].isLoading) {
|
||||||
videoViews[position].retryCount = 0
|
videoViews[position].resetRetryCount()
|
||||||
videoViews[position].play()
|
videoViews[position].play()
|
||||||
}
|
}
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
@ -166,7 +166,7 @@ class SplitViewFragment : Fragment() {
|
|||||||
fun playAll() = MainScope().launch(Dispatchers.Main) {
|
fun playAll() = MainScope().launch(Dispatchers.Main) {
|
||||||
if (videoViews.isEmpty()) return@launch
|
if (videoViews.isEmpty()) return@launch
|
||||||
for (index in data.indices) {
|
for (index in data.indices) {
|
||||||
videoViews[index].retryCount = 0
|
videoViews[index].resetRetryCount()
|
||||||
videoViews[index].play()
|
videoViews[index].play()
|
||||||
delay(300)
|
delay(300)
|
||||||
}
|
}
|
||||||
@ -174,6 +174,7 @@ class SplitViewFragment : Fragment() {
|
|||||||
|
|
||||||
fun stopAll() = MainScope().launch(Dispatchers.Main) {
|
fun stopAll() = MainScope().launch(Dispatchers.Main) {
|
||||||
for (index in data.indices) {
|
for (index in data.indices) {
|
||||||
|
videoViews[index].stopRetryCount()
|
||||||
videoViews[index].stop()
|
videoViews[index].stop()
|
||||||
delay(300)
|
delay(300)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
var retryCount = 0
|
private var retryCount = 0
|
||||||
private var retryRunnable = object : Runnable {
|
private var retryRunnable = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
play()
|
play()
|
||||||
@ -99,26 +99,27 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun play() {
|
fun play() {
|
||||||
/*if (retryCount == RETRY_OFF) {
|
|
||||||
return
|
|
||||||
}*/
|
|
||||||
videoView.postInvalidate()
|
videoView.postInvalidate()
|
||||||
gstLibrary.play()
|
gstLibrary.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
isPlaying = false
|
isPlaying = false
|
||||||
retryCount = RETRY_OFF
|
|
||||||
if (this::gstLibrary.isInitialized) {
|
if (this::gstLibrary.isInitialized) {
|
||||||
gstLibrary.stop()
|
gstLibrary.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetRetryCount() {
|
||||||
|
retryCount = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopRetryCount() {
|
||||||
|
retryCount = RETRY_OFF
|
||||||
|
}
|
||||||
|
|
||||||
override fun surfaceCreated(holder: SurfaceHolder) {
|
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||||
Log.d("${TAG}_$tag", "Surface created: " + holder.surface)
|
Log.d("${TAG}_$tag", "Surface created: " + holder.surface)
|
||||||
if (this::gstLibrary.isInitialized) {
|
|
||||||
gstLibrary.setSurfaceHolder(holder)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
||||||
@ -130,7 +131,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
|
|
||||||
override fun surfaceDestroyed(p0: SurfaceHolder) {
|
override fun surfaceDestroyed(p0: SurfaceHolder) {
|
||||||
Log.d("${TAG}_$tag", "Surface destroyed")
|
Log.d("${TAG}_$tag", "Surface destroyed")
|
||||||
// TODO: 如果呼叫 releaseSurface(),會閃退
|
// TODO: 呼叫 releaseSurface() 會閃退,目前仍在釐清時機點
|
||||||
if (this::gstLibrary.isInitialized) {
|
if (this::gstLibrary.isInitialized) {
|
||||||
gstLibrary.releaseSurface()
|
gstLibrary.releaseSurface()
|
||||||
}
|
}
|
||||||
@ -162,7 +163,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
MSG_PLAY -> {
|
MSG_PLAY -> {
|
||||||
isLoading = false
|
isLoading = false
|
||||||
isPlaying = true
|
isPlaying = true
|
||||||
retryCount = 0
|
resetRetryCount()
|
||||||
}
|
}
|
||||||
MSG_BUFFERING -> {
|
MSG_BUFFERING -> {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
@ -173,7 +174,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
mHandler.post(retryRunnable)
|
mHandler.post(retryRunnable)
|
||||||
retryCount++
|
retryCount++
|
||||||
} else {
|
} else {
|
||||||
retryCount = RETRY_OFF
|
stopRetryCount()
|
||||||
//Log.e("${TAG}_$tag", "Retry count = 5, stopped retry...")
|
//Log.e("${TAG}_$tag", "Retry count = 5, stopped retry...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user