[M2]视频优化
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.mogo.och.bus.passenger.ui
|
||||
|
||||
import android.provider.Settings
|
||||
import android.view.Surface
|
||||
import com.mogo.commons.mvp.MvpFragment
|
||||
import com.mogo.och.bus.passenger.R
|
||||
import com.mogo.och.bus.passenger.presenter.PM2Presenter
|
||||
@@ -25,8 +27,21 @@ class PM2BaseFragment :
|
||||
}
|
||||
|
||||
override fun initViews() {
|
||||
//横竖屏
|
||||
setScreenDirection()
|
||||
|
||||
//隐藏小地图
|
||||
initFragment();
|
||||
initFragment()
|
||||
}
|
||||
|
||||
private fun setScreenDirection() {
|
||||
var ro = Settings.System.getInt(context?.contentResolver,
|
||||
Settings.System.USER_ROTATION,Surface.ROTATION_270)
|
||||
if (ro != Surface.ROTATION_270){
|
||||
ro = Surface.ROTATION_270
|
||||
}
|
||||
Settings.System.putInt(context?.contentResolver,
|
||||
Settings.System.USER_ROTATION,ro)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,5 +64,7 @@ class AdvanceGSYVideoPlayer: StandardGSYVideoPlayer {
|
||||
setViewShowState(
|
||||
mLockScreen, GONE
|
||||
)
|
||||
|
||||
setIsTouchWiget(false)
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,6 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
private fun addView(item: RotationItem) {
|
||||
if (item.type == 1) { // 表示视频
|
||||
val videoView = AdvanceVideoView(mContext)
|
||||
videoView.setCacheImageView(item.cacheImgPath)
|
||||
videoView.setVideoPath(item.path)
|
||||
viewList.add(videoView)
|
||||
} else { // 表示图片
|
||||
@@ -129,7 +128,7 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
if (viewList[mViewPager.currentItem] is AdvanceVideoView) {
|
||||
|
||||
val videoView = (viewList[mViewPager.currentItem] as AdvanceVideoView)
|
||||
videoView.setCacheImageView(dataList[mViewPager.currentItem].cacheImgPath)
|
||||
videoView.setCacheImageView()
|
||||
videoView.setVideo(gsySampleCallBack,mViewPager.currentItem)
|
||||
|
||||
} else if (viewList[mViewPager.currentItem] is AdvanceImageView) {
|
||||
@@ -148,15 +147,16 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
Logger.d("onPageScrollStateChanged", "onPrepared")
|
||||
val videoView = (viewList[mViewPager.currentItem] as AdvanceVideoView)
|
||||
UiThreadHandler.postDelayed({
|
||||
Logger.d("onPageScrollStateChanged", "cacheImg gone")
|
||||
videoView.setCacheImageViewGone()
|
||||
},2000)
|
||||
},1000)
|
||||
}
|
||||
|
||||
override fun onAutoComplete(url: String?, vararg objects: Any?) {
|
||||
Logger.d("onPageScrollStateChanged", "onAutoComplete()")
|
||||
val videoView = (viewList[mViewPager.currentItem] as AdvanceVideoView)
|
||||
videoView.onVideoReset()
|
||||
videoView.setCacheImageView(dataList[mViewPager.currentItem].cacheImgPath)
|
||||
videoView.setCacheImageView()
|
||||
goNextItemView()
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
Logger.d("onPageScrollStateChanged", "onPlayError()")
|
||||
val videoView = (viewList[mViewPager.currentItem] as AdvanceVideoView)
|
||||
videoView.onVideoReset()
|
||||
videoView.setCacheImageView(dataList[mViewPager.currentItem].cacheImgPath)
|
||||
videoView.setCacheImageView()
|
||||
goNextItemView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import android.widget.ImageView
|
||||
import android.widget.RelativeLayout
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.util.BitmapHelper
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.bus.passenger.R
|
||||
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder
|
||||
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack
|
||||
@@ -63,28 +65,30 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
fun setVideoPath(path: String) {
|
||||
this.path = path
|
||||
// BitmapHelper.getVideoThumbnail(path) /*获取第一帧图*/
|
||||
cacheImage?.let {
|
||||
Glide.with(context).load(BitmapHelper.getVideoThumbnail(path))
|
||||
.apply(RequestOptions().placeholder(R.drawable.m2_p_video_holder).centerCrop())
|
||||
.into(it)
|
||||
// it.setImageBitmap(BitmapHelper.getVideoThumbnail(path))
|
||||
}
|
||||
cacheImage?.visibility = VISIBLE
|
||||
Thread{
|
||||
var bitmap = BitmapHelper.getVideoThumbnail(path)
|
||||
Logger.d("onPageScrollStateChanged", "setVideoPath")
|
||||
ThreadUtils.runOnUiThread {
|
||||
Logger.d("onPageScrollStateChanged", "bitmap加载")
|
||||
cacheImage?.let {
|
||||
Glide.with(context).load(bitmap)
|
||||
.apply(
|
||||
RequestOptions().placeholder(R.drawable.m2_p_video_holder).centerCrop()
|
||||
)
|
||||
.into(it)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
fun setCacheImageView(imgPath: String) {
|
||||
|
||||
// cacheImage?.let {
|
||||
// Glide.with(context)
|
||||
// .load(imgPath)
|
||||
// .apply(RequestOptions().placeholder(R.drawable.m2_p_video_holder).centerCrop())
|
||||
// .into(it)
|
||||
// }
|
||||
|
||||
fun setCacheImageView() {
|
||||
cacheImage?.visibility = VISIBLE
|
||||
}
|
||||
|
||||
fun setVideo(onCompletionListener: GSYSampleCallBack,position: Int) {
|
||||
Logger.d("onPageScrollStateChanged", "setVideoPlay")
|
||||
gsyVideoOptionBuilder = GSYVideoOptionBuilder()
|
||||
gsyVideoOptionBuilder?.setUrl(path)
|
||||
?.setPlayTag(path + position)
|
||||
@@ -116,36 +120,4 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
videoViewPlayer?.startPlayLogic()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载首帧,作为视频缓存显示的图片
|
||||
*/
|
||||
// private fun loadCacheImage(){
|
||||
// Thread {
|
||||
// var retriever = MediaMetadataRetriever()
|
||||
// var bitmap: Bitmap? = null
|
||||
// try {
|
||||
// if (path?.contains("http") == true){
|
||||
// retriever.setDataSource(path, HashMap<String,String>())
|
||||
// }else{
|
||||
// retriever.setDataSource(path)
|
||||
// }
|
||||
// bitmap = retriever.frameAtTime
|
||||
// }catch (ex: Exception){
|
||||
// ex.printStackTrace()
|
||||
// }finally {
|
||||
// try {
|
||||
// retriever.release()
|
||||
// }catch (e: RuntimeException){
|
||||
// e.printStackTrace()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (bitmap != null) {
|
||||
// UiThreadHandler.post {
|
||||
// setCacheImageView(bitmap)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user