From bc0f8e8ec428c7bea887db5f8315f99d43d70de1 Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Thu, 9 Feb 2023 20:59:18 +0800 Subject: [PATCH] =?UTF-8?q?[M2]=201=E3=80=81=E5=9B=BE/=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E8=BD=AE=E6=92=ADopt=202=E3=80=81m2=E7=AB=96=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mogo/och/bus/passenger/BusPassengerM2.kt | 15 +-- .../passenger/ui/video/PM2VideoFragment.kt | 7 +- .../ui/widget/video/AdvanceImageView.kt | 5 +- .../ui/widget/video/AdvancePagerAdapter.kt | 97 +++++++++++++------ .../ui/widget/video/AdvanceVideoView.kt | 97 +++++++++++++------ .../ui/widget/video/ImageAndVideoRotation.kt | 5 +- .../passenger/ui/widget/video/RotationItem.kt | 5 +- .../src/m2/res/layout/p_m2_fragment.xml | 6 +- .../src/m2/res/layout/p_m2_hpmap_fragment.xml | 26 ++--- app/productFlavors/fOchBusPassengerM2.gradle | 7 +- 10 files changed, 174 insertions(+), 96 deletions(-) diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/BusPassengerM2.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/BusPassengerM2.kt index a2c8aae031..2fdb5c96b0 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/BusPassengerM2.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/BusPassengerM2.kt @@ -20,7 +20,7 @@ import com.mogo.och.bus.passenger.ui.PM2BaseFragment * Created on 2022/3/29 */ @Route(path = BusPassengerConst.PATH) -class MogoOCHBusPassenger : IMogoOCH, IMogoStatusChangedListener { +class MogoOCHBusPassenger : IMogoOCH { private var mActivity: FragmentActivity? = null private var mContainerId = 0 private var mPM2Fragment: PM2BaseFragment? = null @@ -28,6 +28,7 @@ class MogoOCHBusPassenger : IMogoOCH, IMogoStatusChangedListener { override fun createCoverage(activity: FragmentActivity?, containerId: Int?): Fragment? { mActivity = activity mContainerId = containerId!! + showFragment() return null } @@ -40,18 +41,6 @@ class MogoOCHBusPassenger : IMogoOCH, IMogoStatusChangedListener { } override fun init(context: Context) { - MogoStatusManager.getInstance() - .registerStatusChangedListener("OchBus", StatusDescriptor.VR_MODE, this) - } - - override fun onStatusChanged(descriptor: StatusDescriptor, isTrue: Boolean) { - if (descriptor == StatusDescriptor.VR_MODE) { - if (isTrue) { - showFragment() - } else { - hideFragment() - } - } } /** diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt index 587e839869..6d5f814176 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/video/PM2VideoFragment.kt @@ -48,12 +48,12 @@ class PM2VideoFragment : } private fun initResourceData() { - TODO("要替换成接驳私有化的链接") arrayListOf.clear() arrayListOf.add( RotationItem( "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656558672856/小宝宝.mp4", 0, + "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559345882/1.png", "小宝宝" ) ) @@ -61,6 +61,7 @@ class PM2VideoFragment : RotationItem( "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559367261/2.png", 0, + "", "小猫" ) ) @@ -68,6 +69,7 @@ class PM2VideoFragment : RotationItem( "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656558730074/星空.mp4", 1, + "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559406169/4.png", "星空" ) ) @@ -75,7 +77,8 @@ class PM2VideoFragment : RotationItem( "https://img.zhidaohulian.com/fileServer/online_car_hailing/1656559384635/3.png", 0, - "星空" + "", + "大海" ) ) } diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceImageView.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceImageView.kt index 481fc4b080..8e56661e7c 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceImageView.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceImageView.kt @@ -13,6 +13,7 @@ import com.bumptech.glide.Glide class AdvanceImageView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : RelativeLayout(context, attrs) { + private var imageView: ImageView? = null init { @@ -22,10 +23,10 @@ class AdvanceImageView @JvmOverloads constructor( private fun initView() { imageView = ImageView(context) imageView?.scaleType = ImageView.ScaleType.FIT_XY - addView(imageView, LayoutParams(-1,-1)) + addView(imageView, LayoutParams(-1, -1)) } - public fun setImagePath(path: String){ + fun setImagePath(path: String){ imageView?.let { Glide.with(context).load(path).into(it) } } } \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt index 8e36998e78..0a2c745238 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvancePagerAdapter.kt @@ -19,13 +19,12 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter( private var dataList = mutableListOf() private var viewList = mutableListOf() - private var thread: Thread? = null - private var lastPosition = -1 private var current = 0 private val time = 5000 private val pause = false + private var thread: Thread? = null fun setData(list: MutableList){ if (list.isEmpty()) return @@ -41,6 +40,16 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter( notifyDataSetChanged() + mViewPager.currentItem = 0 + + if (list.size > 0) { + if (list[0].type == 1) {//有人反应第一个是视频不播放这边优化了一下 + var video = list[mViewPager.currentItem] as AdvanceVideoView + video.setVideo { + mViewPager.setCurrentItem(mViewPager.currentItem + 1, true) + } + } + } } override fun getCount(): Int { @@ -67,9 +76,10 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter( } private fun addView(item: RotationItem) { - if (item.type.equals("1")) { // 表示视频 + if (item.type === 1) { // 表示视频 var videoView = AdvanceVideoView(mContext) - videoView.setVideoImagePath(item.path) + videoView.setCacheImageView(item.cacheImgPath) + videoView.setVideoPath(item.path) viewList.add(videoView) } else { // 表示图片 var imageView = AdvanceImageView(mContext) @@ -78,45 +88,72 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager): PagerAdapter( } } - public fun setPause(){ + fun setPause(){ } - public fun setResume(){ + fun setResume(){ } override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { - TODO("Not yet implemented") } override fun onPageSelected(position: Int) { - TODO("Not yet implemented") } override fun onPageScrollStateChanged(state: Int) { // 由于viewpager的预加载机制onPageSelected这里面加载videoview 放的跟玩一样 等操作完成后再播放videoview就香了 很丝滑 -// if (state == 0) { -// if (viewList.size > 1) { //多于1,才会循环跳转 -// if (lastPosition != -1 && lastPosition != mViewPager.currentItem -// && viewList[lastPosition] is AdvanceVideoView) { -// var videoView: AdvanceVideoView = (AdvanceVideoView)viewList[lastPosition] -// videoView.setPause() -// } -// if (mViewPager.getCurrentItem() < 1) { //首位之前,跳转到末尾(N) -// var position = dataList.size //注意这里是mList,而不是mViews -// mViewPager.setCurrentItem(position, false) -// } else if (mViewPager.currentItem > dataList.size) { //末位之后,跳转到首位(1) -// mViewPager.setCurrentItem(1, false) //false:不显示跳转过程的动画 -// } -// current = 0;//换页重新计算时间 -// if (viewList.get(mViewPager.currentItem) instanceof AdvanceVideoView) { -// ((AdvanceVideoView) list.get(mViewPager.getCurrentItem())).setVideo(mediaPlayer -> { -// mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true); -// }) -// } -// lastPosition = mViewPager.currentItem -// } -// } + if (state == 0) { //静止,什么都没做 + if (viewList.size > 1) { //多于1,才会循环跳转 + if (lastPosition != -1 && lastPosition != mViewPager.currentItem + && viewList[lastPosition] is AdvanceVideoView) { + var videoView: AdvanceVideoView = viewList[lastPosition] as AdvanceVideoView + videoView.setPause() + } + if (mViewPager.currentItem < 1) { //首位之前,跳转到末尾(N) + var position = dataList.size //注意这里是mList,而不是mViews + mViewPager.setCurrentItem(position, false) + } else if (mViewPager.currentItem > dataList.size) { //末位之后,跳转到首位(1) + mViewPager.setCurrentItem(1, false) //false:不显示跳转过程的动画 + } + current = 0//换页重新计算时间 + if (viewList[mViewPager.currentItem] is AdvanceVideoView) { + + (viewList[mViewPager.currentItem] as AdvanceVideoView).setVideo { + mViewPager.setCurrentItem(mViewPager.currentItem + 1, true) + } + + }else if (viewList[mViewPager.currentItem] is AdvanceImageView){ + startTimer() + } + lastPosition = mViewPager.currentItem + } + } + } + + private fun startTimer() { + if (null != thread && !thread?.isInterrupted!!) { + thread?.interrupt() + thread = null + } + thread = Thread{ + while (null != thread && !thread?.isInterrupted!!) { + try { + Thread.sleep(1000) + if (!pause && viewList[mViewPager.currentItem] !is AdvanceVideoView) + current += 1000 + if (current >= time) { + mViewPager.post { + mViewPager.setCurrentItem(mViewPager.currentItem + 1, true) + } + current = 0 + } + } catch (e: InterruptedException) { + e.printStackTrace(); + } + } + } + thread?.start() } } \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt index cd5f2d86cc..4872341d53 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/AdvanceVideoView.kt @@ -1,7 +1,9 @@ package com.mogo.och.bus.passenger.ui.widget.video import android.content.Context +import android.graphics.Bitmap import android.graphics.Color +import android.media.MediaMetadataRetriever import android.media.MediaPlayer import android.util.AttributeSet import android.widget.ImageView @@ -9,6 +11,7 @@ import android.widget.RelativeLayout import android.widget.VideoView import com.bumptech.glide.Glide import com.mogo.eagle.core.utilcode.util.UiThreadHandler +import java.lang.RuntimeException /** * @author: wangmingjun @@ -19,9 +22,8 @@ class AdvanceVideoView @JvmOverloads constructor( ) : RelativeLayout(context, attrs) { private var videoRelativeLayout: RelativeLayout? = null - private var videoPlayer: VideoView? = null - - private var startImage: ImageView? = null + private var cacheImage: ImageView? = null + private var videoView: VideoView? = null private var path: String? = null init { @@ -30,54 +32,93 @@ class AdvanceVideoView @JvmOverloads constructor( private fun initView() { videoRelativeLayout = RelativeLayout(context) - addView(videoRelativeLayout, LayoutParams(-1,-1)) - startImage = ImageView(context) - startImage?.scaleType = ImageView.ScaleType.FIT_XY - addView(startImage, LayoutParams(-1,-1)) + addView(videoRelativeLayout, LayoutParams(-1, -1)) + cacheImage = ImageView(context) + cacheImage?.scaleType = ImageView.ScaleType.FIT_XY + addView(cacheImage, LayoutParams(-1, -1)) } - fun setVideoImagePath(path: String){ + fun setVideoPath(path: String){ this.path = path - startImage?.let { Glide.with(context).load(path).into(it) } + } + + + fun setCacheImageView(imgPath: String){ + cacheImage?.visibility = VISIBLE + cacheImage?.let { Glide.with(context).load(imgPath).into(it) } } fun setVideo(onCompletionListener : MediaPlayer.OnCompletionListener) { - if (videoPlayer != null) { - videoRelativeLayout?.removeView(videoPlayer) - videoPlayer = null + if (videoView != null){ + videoRelativeLayout?.removeView(videoView) + videoView = null } - videoPlayer = VideoView(context) - videoPlayer?.setVideoPath(path) - videoPlayer?.setBackgroundColor(Color.TRANSPARENT) - var layoutParams= LayoutParams(-1,-1) + //视频播放控件 + videoView = VideoView(context) + videoView?.setVideoPath(path) + videoView?.setBackgroundColor(Color.TRANSPARENT) + + var layoutParams = LayoutParams(-1, -1) //设置videoview占满父view播放 layoutParams.addRule(ALIGN_PARENT_LEFT) layoutParams.addRule(ALIGN_PARENT_RIGHT) layoutParams.addRule(ALIGN_PARENT_TOP) layoutParams.addRule(ALIGN_PARENT_BOTTOM) - videoRelativeLayout?.addView(videoPlayer, layoutParams); - videoPlayer?.setOnCompletionListener(onCompletionListener); - videoPlayer?.start() + videoRelativeLayout?.addView(videoView, layoutParams) + videoView?.setOnCompletionListener(onCompletionListener) + videoView?.start() - videoPlayer?.setOnPreparedListener { + videoView?.setOnPreparedListener { UiThreadHandler.postDelayed({ - startImage?.visibility = GONE - }, 400) //防止黑屏闪烁 + cacheImage?.visibility = GONE + },500) } + + videoView?.setOnCompletionListener(onCompletionListener) } fun setPause() { - if (videoPlayer != null) { - videoPlayer?.pause() - startImage?.visibility = VISIBLE + if (videoView != null) { + videoView?.pause() } } fun setRestart() { - if (videoPlayer != null) { - videoPlayer?.start() - startImage?.visibility = GONE + if (videoView != null) { + videoView?.start() + } + } + + /** + * 加载首帧,作为视频缓存显示的图片 + */ + private fun loadCacheImage(){ + Thread { + var retriever = MediaMetadataRetriever() + var bitmap: Bitmap? = null + try { + if (path?.contains("http") == true){ + retriever.setDataSource(path, HashMap()) + }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) + } + } } } } \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt index 31c2e308a1..0afd21993d 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/ImageAndVideoRotation.kt @@ -3,9 +3,7 @@ package com.mogo.och.bus.passenger.ui.widget.video import android.content.Context import android.util.AttributeSet import android.widget.RelativeLayout -import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.ViewPager - /** * @author: wangmingjun * @date: 2023/2/6 @@ -25,7 +23,8 @@ class ImageAndVideoRotation @JvmOverloads constructor( viewPager = ViewPager(context) pagerAdapter = AdvancePagerAdapter(context, viewPager!!) viewPager?.adapter = pagerAdapter - addView(viewPager, LayoutParams(-1,-1)) + + addView(viewPager, LayoutParams(-1, -1)) } fun setData(list: MutableList){ diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt index 80b733636f..ed788c6179 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/widget/video/RotationItem.kt @@ -6,4 +6,7 @@ package com.mogo.och.bus.passenger.ui.widget.video * type:0 图片 * type:1 视频 */ -data class RotationItem(var path: String, var type: Int, var title: String) \ No newline at end of file +data class RotationItem(var path: String, + var type: Int, + var cacheImgPath: String, + var title: String) \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_fragment.xml b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_fragment.xml index a1869bd98d..db67764a84 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_fragment.xml +++ b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_fragment.xml @@ -8,7 +8,7 @@ @@ -16,7 +16,7 @@ @@ -26,7 +26,7 @@ diff --git a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_hpmap_fragment.xml b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_hpmap_fragment.xml index fec8fd6cd4..5070519a7a 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_hpmap_fragment.xml +++ b/OCH/mogo-och-bus-passenger/src/m2/res/layout/p_m2_hpmap_fragment.xml @@ -13,19 +13,19 @@ - + + + + + + - + + + + + + + \ No newline at end of file diff --git a/app/productFlavors/fOchBusPassengerM2.gradle b/app/productFlavors/fOchBusPassengerM2.gradle index c65c95c257..1633111a77 100644 --- a/app/productFlavors/fOchBusPassengerM2.gradle +++ b/app/productFlavors/fOchBusPassengerM2.gradle @@ -18,7 +18,12 @@ project.android.productFlavors { // 车机类型,主要用于区分自研车机还是别人家的车机,自研车机类型为0 buildConfigField 'int', 'CAR_MACHINE_TYPE', '2' //高德地图鉴权信息 - manifestPlaceholders = [AMAP_API_VALUE: rootProject.ext.android.fLauncherAmapApiValue, CHANNEL_VALUE: "fOchBusPassenger",ACTIVITY_ROOT:true] + manifestPlaceholders = [ + AMAP_API_VALUE: rootProject.ext.android.fLauncherAmapApiValue, + CHANNEL_VALUE: "fOchBusPassenger", + ACTIVITY_ROOT:true, + SCREEN_ORIENTATION: "portrait" + ] // 是否需要实时上报坐标 buildConfigField 'boolean', 'IS_NEED_UPLOAD_COORDINATES_IN_TIME', 'true'