add video player
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package com.mogo.tanlu.fragment;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -21,7 +19,6 @@ import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.model.MogoPoi;
|
||||
import com.mogo.map.search.geo.MogoPoiItem;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
|
||||
@@ -29,13 +26,12 @@ import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||
import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.tanlu.R;
|
||||
import com.mogo.tanlu.constant.TanluConstants;
|
||||
import com.mogo.tanlu.video.SimpleCoverVideoPlayer;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import static com.mogo.tanlu.video.VideoInitKt.initVideo;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
@@ -52,105 +48,51 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
|
||||
private static final String TAG = "TanluCardViewFragment";
|
||||
|
||||
private Button mAddMarker;
|
||||
private Button mAddMarkers;
|
||||
|
||||
private Bitmap mMarkerIcon;
|
||||
private Bitmap mClickedMarkerIcon;
|
||||
private TextView mLocInfo;
|
||||
private TextView mLoc;
|
||||
|
||||
private IMogoMarker mLastClickedMarker;
|
||||
private TanluInfoWindowAdapter mDemoInfoWindowAdapter;
|
||||
private MogoLocation mLocation;
|
||||
|
||||
private int position = -1;
|
||||
private GSYVideoOptionBuilder gsyVideoOptionBuilder = new GSYVideoOptionBuilder();
|
||||
private String videoUrl = "http://petchfile-1255510688.cos.ap-beijing.myqcloud.com/CarPad/com.zhidao.roadcondition/ZD801B1942L02537/ZD801B1942L02537_20200103161355/PhotoFront_20200103_161351.JPG?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDCWfcNwD5PXVWLxwejccR3Tiz5zhIkx0T%26q-sign-time%3D1578042652%3B1578049852%26q-key-time%3D1578042652%3B1578049852%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3Db9530357bc3d80fb13ec54dfaa9a7a1ee86180e2";
|
||||
// private String videoUrl = "http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8";
|
||||
SimpleCoverVideoPlayer simpleCoverVideoPlayer;
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.tanlu_card_view;
|
||||
return R.layout.tanlu_item_main_media_recycler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
initVideo();
|
||||
position = getArguments().getInt("position");
|
||||
simpleCoverVideoPlayer = findViewById(R.id.video_player_main);
|
||||
|
||||
//视频配置
|
||||
gsyVideoOptionBuilder.setUrl(videoUrl).setCacheWithPlay(false).setPlayTag(TAG)
|
||||
.build(simpleCoverVideoPlayer);
|
||||
// simpleCoverVideoPlayer.getStartButton().performClick();
|
||||
simpleCoverVideoPlayer.getStartButton().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.d("liyz", "onClick ---------> ");
|
||||
Intent intent = new Intent("fullscreen.video.play", Uri.parse("video://666"));
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
//图片显示
|
||||
|
||||
|
||||
|
||||
TanluServiceHandler.getPoiSearch().setPoiSearchListener(this);
|
||||
mLocation = TanluServiceHandler.getLocationClient().getLastKnowLocation();
|
||||
|
||||
mLocInfo = findViewById(R.id.demo_module_id_loc_info);
|
||||
mLoc = findViewById(R.id.demo_module_id_loc);
|
||||
mLoc.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TanluServiceHandler.getLocationClient().start(4_000L);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// mLocation = TanluServiceHandler.getLocationClient().getLastKnowLocation();
|
||||
mDemoInfoWindowAdapter = new TanluInfoWindowAdapter(getContext(), TanluServiceHandler.getNavi(), TanluServiceHandler.getImageloader());
|
||||
|
||||
mMarkerIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_search_poi_location);
|
||||
mClickedMarkerIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_search_choice_point);
|
||||
mAddMarker = findViewById(R.id.demo_module_id_add_marker);
|
||||
mAddMarker.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.icon(mMarkerIcon)
|
||||
.latitude(39.974525d)
|
||||
.owner(TanluConstants.TAG)
|
||||
.longitude(116.41733d);
|
||||
IMogoMarker marker = TanluServiceHandler.getMarkerManager().addMarker(TanluConstants.TAG, options);
|
||||
marker.setInfoWindowAdapter(mDemoInfoWindowAdapter);
|
||||
marker.setOnMarkerClickListener(TanluCardViewFragment.this);
|
||||
}
|
||||
});
|
||||
mAddMarkers = findViewById(R.id.demo_module_id_add_markers);
|
||||
mAddMarkers.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
ArrayList<MogoMarkerOptions> optionsList = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.owner(TanluConstants.TAG)
|
||||
.latitude(39.974525d + new Random().nextDouble())
|
||||
.longitude(116.41733d + new Random().nextDouble());
|
||||
if (i % 2 == 0) {
|
||||
options.icon(mMarkerIcon);
|
||||
} else {
|
||||
options.icon(mDemoInfoWindowAdapter.getMarkerView(options));
|
||||
}
|
||||
optionsList.add(options);
|
||||
}
|
||||
List<IMogoMarker> iMogoMarkers = TanluServiceHandler.getMarkerManager().addMarkers(TanluConstants.TAG, optionsList, true);
|
||||
for (IMogoMarker iMogoMarker : iMogoMarkers) {
|
||||
iMogoMarker.setInfoWindowAdapter(mDemoInfoWindowAdapter);
|
||||
iMogoMarker.setOnMarkerClickListener(TanluCardViewFragment.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.demo_module_id_clear).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TanluServiceHandler.getMarkerManager().removeMarkers(TanluConstants.TAG);
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.demo_module_id_current).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TanluServiceHandler.getMapUIController().moveToCenter(new MogoLatLng(mLocation.getLatitude(), mLocation.getLongitude()));
|
||||
}
|
||||
});
|
||||
|
||||
TanluServiceHandler.getLocationClient().addLocationListener(new IMogoLocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(MogoLocation location) {
|
||||
mLocation = location;
|
||||
// mLocation = location;
|
||||
Logger.d(TAG, "demo模块定位,定位间隔4s");
|
||||
}
|
||||
});
|
||||
@@ -162,15 +104,15 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
getViewLifecycleOwner().getLifecycle().addObserver(mPresenter);
|
||||
}
|
||||
|
||||
/**
|
||||
* marker点击事件 TODO
|
||||
* @param marker
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onMarkerClicked(IMogoMarker marker) {
|
||||
// if ( mLastClickedMarker != null ) {
|
||||
// mLastClickedMarker.setIcon( this.mMarkerIcon );
|
||||
// }
|
||||
// marker.setIcon( mClickedMarkerIcon );
|
||||
// mLastClickedMarker = marker;
|
||||
marker.getObject();
|
||||
|
||||
// marker.showInfoWindow();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -229,31 +171,31 @@ public class TanluCardViewFragment extends MvpFragment<IView, Presenter<IView>>
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
if (mPoiMarker != null) {
|
||||
mPoiMarker.destroy();
|
||||
}
|
||||
mPoiMarker = TanluServiceHandler.getMarkerManager().addMarker(TanluConstants.TAG, new MogoMarkerOptions()
|
||||
.longitude(item.getPoint().lng)
|
||||
.latitude(item.getPoint().lat)
|
||||
.icon(mMarkerIcon));
|
||||
if (mPoiMarker != null) {
|
||||
mPoiMarker.setInfoWindowAdapter(mDemoInfoWindowAdapter);
|
||||
mPoiMarker.setObject(item);
|
||||
mPoiMarker.showInfoWindow();
|
||||
}
|
||||
// if (mPoiMarker != null) {
|
||||
// mPoiMarker.destroy();
|
||||
// }
|
||||
// mPoiMarker = TanluServiceHandler.getMarkerManager().addMarker(TanluConstants.TAG, new MogoMarkerOptions()
|
||||
// .longitude(item.getPoint().lng)
|
||||
// .latitude(item.getPoint().lat)
|
||||
// .icon(mMarkerIcon));
|
||||
// if (mPoiMarker != null) {
|
||||
// mPoiMarker.setInfoWindowAdapter(mDemoInfoWindowAdapter);
|
||||
// mPoiMarker.setObject(item);
|
||||
// mPoiMarker.showInfoWindow();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(MogoLocation location) {
|
||||
mLocation = location;
|
||||
Logger.i(TAG, "接受到的地图模块定位信息");
|
||||
if (mLocInfo != null) {
|
||||
if (location.getErrCode() == 0) {
|
||||
mLocInfo.setText("当前位置:" + location.getAddress());
|
||||
} else {
|
||||
mLocInfo.setText(location.getErrInfo());
|
||||
}
|
||||
}
|
||||
// mLocation = location;
|
||||
// Logger.i(TAG, "接受到的地图模块定位信息");
|
||||
// if (mLocInfo != null) {
|
||||
// if (location.getErrCode() == 0) {
|
||||
// mLocInfo.setText("当前位置:" + location.getAddress());
|
||||
// } else {
|
||||
// mLocInfo.setText(location.getErrInfo());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.mogo.tanlu.video
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.Surface
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.mogo.tanlu.R
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.utils.GSYVideoType
|
||||
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge
|
||||
|
||||
|
||||
class SimpleCoverVideoPlayer : StandardGSYVideoPlayer {
|
||||
private lateinit var coverImage: ImageView
|
||||
private lateinit var start: ImageView
|
||||
private lateinit var fullscreen: ImageView
|
||||
|
||||
constructor(context: Context?) : super(context)
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context?, fullFlag: Boolean?) : super(context, fullFlag)
|
||||
|
||||
override fun init(context: Context) {
|
||||
super.init(context)
|
||||
coverImage = findViewById(R.id.thumbImage)
|
||||
start = findViewById(R.id.start)
|
||||
fullscreen = findViewById(R.id.fullscreen)
|
||||
if (mThumbImageViewLayout != null
|
||||
&& (mCurrentState == -1 || mCurrentState == GSYVideoView.CURRENT_STATE_NORMAL || mCurrentState == GSYVideoView.CURRENT_STATE_ERROR)
|
||||
) {
|
||||
mThumbImageViewLayout.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.tanlu_item_video_cover
|
||||
}
|
||||
|
||||
override fun getGSYVideoManager(): GSYVideoViewBridge {
|
||||
GSYVideoManager.instance().initContext(context.applicationContext)
|
||||
return GSYVideoManager.instance()
|
||||
}
|
||||
|
||||
override fun setProgressAndTime(
|
||||
progress: Int,
|
||||
secProgress: Int,
|
||||
currentTime: Int,
|
||||
totalTime: Int
|
||||
) {
|
||||
super.setProgressAndTime(progress, secProgress, currentTime, totalTime)
|
||||
if (progress != 0) {
|
||||
mProgressBar.progress = progress
|
||||
}
|
||||
}
|
||||
|
||||
// fun loadCoverImage(url: String, mContext: Context) {
|
||||
// Glide.with(mContext.applicationContext)
|
||||
// .load(url)
|
||||
// .error(R.color.color_303447)
|
||||
// .into(coverImage)
|
||||
// }
|
||||
|
||||
override fun updateStartImage() {
|
||||
when (mCurrentState) {
|
||||
GSYVideoView.CURRENT_STATE_PLAYING -> start.setImageResource(R.drawable.selector_bg_btn_pause)
|
||||
GSYVideoView.CURRENT_STATE_ERROR -> start.setImageResource(R.mipmap.main_video_refresh_btn)
|
||||
else -> start.setImageResource(R.drawable.selector_bg_btn_play)
|
||||
}
|
||||
}
|
||||
|
||||
fun setFullClickListener(listener: OnClickListener) {
|
||||
fullscreen.setOnClickListener(listener)
|
||||
}
|
||||
|
||||
override fun changeUiToCompleteShow() {
|
||||
super.changeUiToCompleteShow()
|
||||
setViewShowState(mBottomContainer, View.INVISIBLE)
|
||||
}
|
||||
|
||||
override fun onAutoCompletion() {
|
||||
super.onAutoCompletion()
|
||||
mProgressBar.progress = 0
|
||||
}
|
||||
|
||||
override fun showWifiDialog() {
|
||||
//直接播放,不显示WIFI对话框
|
||||
startPlayLogic()
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
mProgressBar.progress = 0
|
||||
mFullPauseBitmap = null
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
super.onClick(v)
|
||||
}
|
||||
|
||||
|
||||
override fun onPrepared() {
|
||||
super.onPrepared()
|
||||
}
|
||||
|
||||
override fun onCompletion() {
|
||||
|
||||
}
|
||||
|
||||
override fun onSurfaceUpdated(surface: Surface) {
|
||||
super.onSurfaceUpdated(surface)
|
||||
if (mThumbImageViewLayout != null && mThumbImageViewLayout.visibility == View.VISIBLE) {
|
||||
mThumbImageViewLayout.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun setViewShowState(view: View?, visibility: Int) {
|
||||
if (view === mThumbImageViewLayout && visibility != View.VISIBLE) {
|
||||
return
|
||||
}
|
||||
super.setViewShowState(view, visibility)
|
||||
}
|
||||
|
||||
override fun onSurfaceAvailable(surface: Surface) {
|
||||
super.onSurfaceAvailable(surface)
|
||||
if (GSYVideoType.getRenderType() != GSYVideoType.TEXTURE) {
|
||||
if (mThumbImageViewLayout != null && mThumbImageViewLayout.visibility == View.VISIBLE) {
|
||||
mThumbImageViewLayout.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mogo.tanlu.video
|
||||
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.cache.CacheFactory
|
||||
import com.shuyu.gsyvideoplayer.cache.ProxyCacheManager
|
||||
import com.shuyu.gsyvideoplayer.model.VideoOptionModel
|
||||
import com.shuyu.gsyvideoplayer.player.IjkPlayerManager
|
||||
import com.shuyu.gsyvideoplayer.player.PlayerFactory
|
||||
import com.shuyu.gsyvideoplayer.utils.GSYVideoType
|
||||
import tv.danmaku.ijk.media.player.IjkMediaPlayer
|
||||
|
||||
|
||||
fun initVideo() {
|
||||
PlayerFactory.setPlayManager(IjkPlayerManager::class.java)
|
||||
CacheFactory.setCacheManager(ProxyCacheManager::class.java)
|
||||
var list = mutableListOf<VideoOptionModel>()
|
||||
list.add(VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1))
|
||||
list.add(VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "videotoolbox", 0))
|
||||
GSYVideoManager.instance().optionModelList = list
|
||||
GSYVideoType.enableMediaCodec()
|
||||
GSYVideoType.enableMediaCodecTexture()
|
||||
}
|
||||
@@ -83,10 +83,6 @@ class AutoZoomInImageView : ImageView {
|
||||
private fun initInternalValues() {
|
||||
mDrawable = drawable
|
||||
|
||||
if (mDrawable == null) {
|
||||
throw IllegalArgumentException("please set the source of AutoZoomInImageView")
|
||||
}
|
||||
|
||||
mDrawableW = mDrawable.intrinsicWidth
|
||||
mDrawableH = mDrawable.intrinsicHeight
|
||||
|
||||
@@ -100,10 +96,6 @@ class AutoZoomInImageView : ImageView {
|
||||
private fun initInternalValues(drawable: Drawable) {
|
||||
mDrawable = drawable
|
||||
|
||||
if (mDrawable == null) {
|
||||
throw IllegalArgumentException("please set the source of AutoZoomInImageView")
|
||||
}
|
||||
|
||||
mDrawableW = mDrawable.intrinsicWidth
|
||||
mDrawableH = mDrawable.intrinsicHeight
|
||||
|
||||
|
||||
Reference in New Issue
Block a user