提交 97034f9e 编写于 作者: S shuyu

1.4.6 修正了预览

上级 72f9aeb7
......@@ -68,6 +68,11 @@ dependencies {
## 下方个版本说明,可以当做简单的wiki使用~,效果可参考DEMO。
### 1.4.6
* 修改了某些虚拟按键手机下,全屏后返回导致界面显示不正的问题。
### 1.4.5
* 支持切换IJKPlayer和EXOPlayer,不过EXOPlayer后台播放回到前台黑的问题除了seekto无解啊。
......
......@@ -2,39 +2,34 @@ package com.example.gsyvideoplayer;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.example.gsyvideoplayer.listener.SampleListener;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.CustomGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.transitionseverywhere.TransitionManager;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.example.gsyvideoplayer.utils.CommonUtil.setViewHeight;
public class DetailPlayer extends AppCompatActivity {
@BindView(R.id.post_detail_nested_scroll)
NestedScrollView postDetailNestedScroll;
@BindView(R.id.detail_player)
StandardGSYVideoPlayer detailPlayer;
CustomGSYVideoPlayer detailPlayer;
@BindView(R.id.activity_detail_player)
RelativeLayout activityDetailPlayer;
private boolean isFull;
private boolean isPlay;
private boolean isPause;
......@@ -163,38 +158,6 @@ public class DetailPlayer extends AppCompatActivity {
}
}
private void toFull() {
isFull = true;
TransitionManager.beginDelayedTransition(activityDetailPlayer);
setViewHeight(detailPlayer, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
resolveFullVideoUI();
orientationUtils.setEnable(true);
}
private void toNormal() {
isFull = false;
orientationUtils.setEnable(false);
int delay = orientationUtils.backToProtVideo();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
TransitionManager.beginDelayedTransition(activityDetailPlayer);
setViewHeight(detailPlayer, ViewGroup.LayoutParams.MATCH_PARENT,
(int) getResources().getDimension(R.dimen.post_media_height));
}
}, delay);
}
private void toDo() {
if (isFull) {
toNormal();
} else {
toFull();
}
}
private void resolveNormalVideoUI() {
//增加title
......@@ -203,10 +166,4 @@ public class DetailPlayer extends AppCompatActivity {
detailPlayer.getBackButton().setVisibility(View.GONE);
}
private void resolveFullVideoUI() {
detailPlayer.getTitleTextView().setVisibility(View.VISIBLE);
detailPlayer.getTitleTextView().setText("测试视频");
detailPlayer.getBackButton().setVisibility(View.VISIBLE);
}
}
......@@ -38,27 +38,14 @@ public class SampleVideo extends StandardGSYVideoPlayer {
private TextView mSwitchSize;
private ImageView mSeekBarImage;
private Timer mSeekBarImageTimer;
private List<SwitchVideoModel> mUrlList = new ArrayList<>();
private ShowSeekBarImageTimerTask mShowSeekBarImageTimerTask;
//记住切换数据源类型
private int mType = 0;
//数据源
private int mSourcePosition = 0;
//记录上一个进度图的位置,用于判断是否取数据
private int mPreSeekPosition = -1;
//记录进度图变化的帧图片图的偏移时间,避免太频繁进入
private long mOffsetTime;
public SampleVideo(Context context) {
super(context);
initView();
......@@ -72,7 +59,6 @@ public class SampleVideo extends StandardGSYVideoPlayer {
private void initView() {
mMoreScale = (TextView) findViewById(R.id.moreScale);
mSwitchSize = (TextView) findViewById(R.id.switchSize);
mSeekBarImage = (ImageView) findViewById(R.id.seek_bar_image);
//切换清晰度
mMoreScale.setOnClickListener(new OnClickListener() {
......@@ -183,106 +169,4 @@ public class SampleVideo extends StandardGSYVideoPlayer {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
super.onProgressChanged(seekBar, progress, fromUser);
if ((mCurrentState == GSYVideoPlayer.CURRENT_STATE_PLAYING
|| mCurrentState == GSYVideoPlayer.CURRENT_STATE_PAUSE)
&& GSYVideoManager.instance().getMediaPlayer() != null) {
int width = seekBar.getWidth();
int offset = (int) (width - (getResources().getDimension(R.dimen.seek_bar_image) / 2)) / 100 * progress;
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mSeekBarImage.getLayoutParams();
layoutParams.leftMargin = offset;
//设置帧预览图的显示位置
mSeekBarImage.setLayoutParams(layoutParams);
long currentTime = System.currentTimeMillis();
if (fromUser && (mPreSeekPosition == -1 || Math.abs(progress - mPreSeekPosition) > 2)
&& (currentTime - mOffsetTime) > 400) {
//开始预览帧小图
startSeekBarImageTimer(seekBar.getProgress());
mPreSeekPosition = progress;
mOffsetTime = currentTime;
}
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
super.onStartTrackingTouch(seekBar);
mSeekBarImage.setVisibility(VISIBLE);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
super.onStopTrackingTouch(seekBar);
cancelSeekBarImageTimer();
mSeekBarImage.setVisibility(GONE);
mPreSeekPosition = -1;
}
@Override
public void onPrepared() {
super.onPrepared();
}
private void startSeekBarImageTimer(int progress) {
cancelSeekBarImageTimer();
mSeekBarImageTimer = new Timer();
mShowSeekBarImageTimerTask = new ShowSeekBarImageTimerTask(progress);
mSeekBarImageTimer.schedule(mShowSeekBarImageTimerTask, 10);
}
private void cancelSeekBarImageTimer() {
if (mShowSeekBarImageTimerTask != null) {
mShowSeekBarImageTimerTask.cancel();
}
if (mSeekBarImageTimer != null) {
mSeekBarImageTimer.cancel();
}
}
/**
* 获取帧预览图任务
**/
protected class ShowSeekBarImageTimerTask extends TimerTask {
int progress;
ShowSeekBarImageTimerTask(int progress) {
this.progress = progress;
}
@Override
public void run() {
if (!TextUtils.isEmpty(mUrl)) {
try {
int time = progress * getDuration() / 100 * 1000;
//获取帧图片
if (GSYVideoManager.instance().getMediaMetadataRetriever() != null) {
final Bitmap bitmap = GSYVideoManager.instance().getMediaMetadataRetriever()
.getFrameAtTime(time, MediaMetadataRetriever.OPTION_CLOSEST);
((Activity) getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
if (bitmap != null) {
//显示
mSeekBarImage.setImageBitmap(bitmap);
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
......@@ -29,7 +29,7 @@
</android.support.v4.widget.NestedScrollView>
<com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
<com.shuyu.gsyvideoplayer.video.CustomGSYVideoPlayer
android:id="@+id/detail_player"
android:layout_width="match_parent"
android:layout_height="@dimen/post_media_height" />
......
......@@ -186,14 +186,4 @@
android:textSize="13sp" />
</LinearLayout>
<ImageView
android:id="@+id/seek_bar_image"
android:layout_width="@dimen/seek_bar_image"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:layout_above="@+id/layout_bottom"
android:layout_marginBottom="30dp"/>
</RelativeLayout>
package com.shuyu.gsyvideoplayer.video;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.R;
import java.util.Timer;
import java.util.TimerTask;
/**
* Created by shuyu on 2016/12/10.
*/
public class CustomGSYVideoPlayer extends StandardGSYVideoPlayer {
private ImageView mSeekBarImage;
private ShowSeekBarImageTimerTask mShowSeekBarImageTimerTask;
private Timer mSeekBarImageTimer;
//记录上一个进度图的位置,用于判断是否取数据
private int mPreSeekPosition = -1;
//记录进度图变化的帧图片图的偏移时间,避免太频繁进入
private long mOffsetTime;
public CustomGSYVideoPlayer(Context context) {
super(context);
initView();
}
public CustomGSYVideoPlayer(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
}
private void initView() {
mSeekBarImage = (ImageView) findViewById(R.id.seek_bar_image);
}
@Override
public int getLayoutId() {
return R.layout.video_layout_custom;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
super.onProgressChanged(seekBar, progress, fromUser);
if ((mCurrentState == GSYVideoPlayer.CURRENT_STATE_PLAYING
|| mCurrentState == GSYVideoPlayer.CURRENT_STATE_PAUSE)
&& GSYVideoManager.instance().getMediaPlayer() != null) {
int width = seekBar.getWidth();
int offset = (int) (width - (getResources().getDimension(R.dimen.seek_bar_image) / 2)) / 100 * progress;
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mSeekBarImage.getLayoutParams();
layoutParams.leftMargin = offset;
//设置帧预览图的显示位置
mSeekBarImage.setLayoutParams(layoutParams);
long currentTime = System.currentTimeMillis();
if (fromUser && (mPreSeekPosition == -1 || Math.abs(progress - mPreSeekPosition) > 2)
&& (currentTime - mOffsetTime) > 400) {
//开始预览帧小图
startSeekBarImageTimer(seekBar.getProgress());
mPreSeekPosition = progress;
mOffsetTime = currentTime;
}
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
super.onStartTrackingTouch(seekBar);
mSeekBarImage.setVisibility(VISIBLE);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
super.onStopTrackingTouch(seekBar);
cancelSeekBarImageTimer();
mSeekBarImage.setVisibility(GONE);
mPreSeekPosition = -1;
}
private void startSeekBarImageTimer(int progress) {
cancelSeekBarImageTimer();
mSeekBarImageTimer = new Timer();
mShowSeekBarImageTimerTask = new ShowSeekBarImageTimerTask(progress);
mSeekBarImageTimer.schedule(mShowSeekBarImageTimerTask, 10);
}
private void cancelSeekBarImageTimer() {
if (mShowSeekBarImageTimerTask != null) {
mShowSeekBarImageTimerTask.cancel();
}
if (mSeekBarImageTimer != null) {
mSeekBarImageTimer.cancel();
}
}
/**
* 获取帧预览图任务
**/
protected class ShowSeekBarImageTimerTask extends TimerTask {
int progress;
ShowSeekBarImageTimerTask(int progress) {
this.progress = progress;
}
@Override
public void run() {
if (!TextUtils.isEmpty(mUrl)) {
try {
int time = progress * getDuration() / 100 * 1000;
//获取帧图片
if (GSYVideoManager.instance().getMediaMetadataRetriever() != null) {
final Bitmap bitmap = GSYVideoManager.instance().getMediaMetadataRetriever()
.getFrameAtTime(time, MediaMetadataRetriever.OPTION_CLOSEST);
((Activity) getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
if (bitmap != null) {
//显示
mSeekBarImage.setImageBitmap(bitmap);
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<RelativeLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
</RelativeLayout>
<com.shuyu.gsyvideoplayer.GSYImageCover
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="fitXY" />
<RelativeLayout
android:id="@+id/thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#000000"
android:scaleType="fitCenter" />
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#99000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="invisible">
<TextView
android:id="@+id/current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="00:00"
android:textColor="#ffffff" />
<SeekBar
android:id="@+id/progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0"
android:background="@null"
android:max="100"
android:maxHeight="4dp"
android:minHeight="4dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:progressDrawable="@drawable/video_seek_progress"
android:thumb="@drawable/video_seek_thumb" />
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:text="00:00"
android:textColor="#ffffff" />
<TextView
android:id="@+id/switchSize"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="16dp"
android:gravity="center"
android:minEms="2"
android:text="标准"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/fullscreen"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/video_enlarge" />
</LinearLayout>
<ProgressBar
android:id="@+id/bottom_progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_alignParentBottom="true"
android:max="100"
android:progressDrawable="@drawable/video_progress" />
<ImageView
android:id="@+id/back_tiny"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:visibility="gone" />
<moe.codeest.enviews.ENDownloadView
android:id="@+id/loading"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="invisible" />
<moe.codeest.enviews.ENPlayView
android:id="@+id/start"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical" />
<ImageView
android:id="@+id/small_close"
android:layout_width="30dp"
android:layout_height="30dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:scaleType="centerInside"
android:src="@drawable/video_small_close"
android:visibility="gone" />
<ImageView
android:id="@+id/lock_screen"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="50dp"
android:scaleType="centerInside"
android:src="@drawable/unlock"
android:visibility="gone" />
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/back_tiny"
android:layout_toRightOf="@+id/back_tiny"
android:background="@drawable/video_title_bg"
android:gravity="center_vertical">
<ImageView
android:id="@+id/back"
android:layout_width="48dp"
android:layout_height="48dp"
android:paddingLeft="10dp"
android:scaleType="centerInside"
android:src="@drawable/video_back" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:textColor="@android:color/white"
android:textSize="18sp" />
</LinearLayout>
<ImageView
android:id="@+id/seek_bar_image"
android:layout_width="@dimen/seek_bar_image"
android:layout_height="100dp"
android:layout_above="@+id/layout_bottom"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:visibility="gone" />
</RelativeLayout>
......@@ -4,4 +4,6 @@
<dimen name="video_progress_dialog_margin_top">80dp</dimen>
<dimen name="video_volume_dialog_margin_left">24dp</dimen>
<dimen name="seek_bar_image">150dp</dimen>
</resources>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册