Commit 31597ce1 by 万齐军

feature: 倾诉2.0视频播放网络检查

parent 080ea869
......@@ -12,6 +12,8 @@ import com.alibaba.android.arouter.facade.annotation.Route
import com.ydl.confide.R
import com.ydl.confide.api.ConfideRoute
import com.ydl.confide.databinding.ActivityExpertIntroBinding
import com.ydl.confide.home.util.ConfideNetworkUtil
import com.ydl.ydlcommon.view.dialog.CommonDialog
@Route(path = ConfideRoute.R_VIDEO_SHOW)
......@@ -54,7 +56,7 @@ class ExpertIntroActivity : AppCompatActivity() {
}
}
})
adapter.checkNetwork()
}
private fun loadMore() {
......
package com.ydl.confide.intro
import android.app.Activity
import android.content.Context
import android.net.Uri
import android.util.Log
......@@ -14,6 +15,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.dou361.ijkplayer.widget.IjkVideoView
import com.ydl.confide.R
import com.ydl.confide.databinding.ItemExpertIntroBinding
import com.ydl.confide.home.util.ConfideNetworkUtil
import com.ydl.ydlcommon.view.dialog.CommonDialog
internal class IntroAdapter(
private val context: Context,
......@@ -23,6 +26,10 @@ internal class IntroAdapter(
private val videoViews = hashMapOf<Int, IjkVideoView>()
private var hasAgreePlayWithoutWiFi = false
private var curPos = 0
init {
lifecycleOwner.lifecycle.addObserver(this)
}
......@@ -49,11 +56,49 @@ internal class IntroAdapter(
override fun onViewAttachedToWindow(holder: ItemIntroHolder) {
val adapterPosition = holder.adapterPosition
val videoView = IjkVideoView(context)
videoView.setVideoURI(Uri.parse("https://video.ydlcdn.com/2020/04/01/ac2e4bb4e3ac8e2f0eca41e2d49c8484.mp4"))
if (hasAgreePlayWithoutWiFi || ConfideNetworkUtil.isWifi(context)) {
videoView.setVideoURI(Uri.parse("https://video.ydlcdn.com/2020/04/01/ac2e4bb4e3ac8e2f0eca41e2d49c8484.mp4"))
} else {
data[adapterPosition].playUrl?.let { videoView.tag = it }
}
videoViews.put(adapterPosition, videoView)
holder.onAttach(videoView)
}
internal fun checkNetwork() {
if (!ConfideNetworkUtil.isWifi(context)) {
val dialog = CommonDialog.create(context)
.setTitle(context.getString(R.string.confide_tip))
.setMessage(context.getString(R.string.confide_video_wifi_tip))
.setLeftOnclick("继续播放") {
hasAgreePlayWithoutWiFi = true
for (entry in videoViews.entries) {
val value = entry.value
(value.tag as? String)?.let {
value.setVideoURI(Uri.parse(it))
if (curPos == entry.key) {
value.start()
}
}
}
}
.setLeftButton_color(R.color.platform_but_text_color_selected)
.setRightButton_color(R.color.platform_text_bright_color)
.setRightClick("取消") {
if (context is Activity) {
context.onBackPressed()
}
}
.setCancelAble(true)
dialog.setOnCancelListener {
if (context is Activity) {
context.onBackPressed()
}
}
dialog.show()
}
}
override fun onViewDetachedFromWindow(holder: ItemIntroHolder) {
super.onViewDetachedFromWindow(holder)
val adapterPosition = holder.adapterPosition
......@@ -76,7 +121,10 @@ internal class IntroAdapter(
}
fun onSelect(position: Int) {
Log.i("qwe", "" + videoViews.size)
curPos = position
if (!ConfideNetworkUtil.isWifi(context) && !hasAgreePlayWithoutWiFi) {
return
}
for (entry in videoViews.entries) {
if (entry.key == position) {
entry.value.seekTo(0)
......
......@@ -3,7 +3,6 @@ package com.ydl.confide.intro
import android.util.Log
import android.view.View
import android.widget.SeekBar
import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import androidx.databinding.ObservableInt
import androidx.databinding.ViewDataBinding
......@@ -22,6 +21,10 @@ import java.util.concurrent.TimeUnit
internal class ItemIntroHolder(binding: ItemExpertIntroBinding) :
BindingViewHolder<ItemExpertIntroBinding>(binding), LifecycleObserver {
companion object {
private const val TAG = "ItemIntroHolder"
}
private var disposable: Disposable? = null
private var video: IjkVideoView? = null
......@@ -65,7 +68,7 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) :
this.video = videoView
binding.videoView.addView(videoView)
video?.setOnPreparedListener { player ->
Log.d("qweqwe", "${player.videoHeight},${player.videoWidth},${player.duration}")
Log.d(TAG, "${player.videoHeight},${player.videoWidth},${player.duration}")
val duration = player.duration.toInt()
if (duration > 0) {
binding.seekbar.max = duration
......@@ -74,7 +77,7 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) :
}
}
video?.setOnInfoListener { mp, what, extra ->
Log.d("qweqwe", "${what},${extra}")
Log.d(TAG, "${what},${extra}")
return@setOnInfoListener false
}
video?.setOnCompletionListener { stopTiming() }
......@@ -115,6 +118,9 @@ class VideoViewModel {
val count = ObservableInt()
val intro = ObservableField<String>("")
val tag = ObservableField<String>("")
var playUrl: String? = "https://video.ydlcdn.com/2020/04/01/ac2e4bb4e3ac8e2f0eca41e2d49c8484.mp4"
var coverUrl: String? = null
var isVideo = true
}
......
<resources>
<string name="confide_title">即时倾诉</string>
<string name="confide_video_wifi_tip">当前处于非wifi环境下,播放会消耗流量,确定继续播放?</string>
<string name="confide_tip">提示</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment