|
|
@ -15,6 +15,7 @@ import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
|
|
import com.frank.ffmpeg.R; |
|
|
|
import com.frank.ffmpeg.R; |
|
|
|
import com.frank.ffmpeg.hardware.HardwareDecode; |
|
|
|
import com.frank.ffmpeg.hardware.HardwareDecode; |
|
|
|
|
|
|
|
import com.frank.ffmpeg.util.ScreenUtil; |
|
|
|
import com.frank.ffmpeg.util.TimeUtil; |
|
|
|
import com.frank.ffmpeg.util.TimeUtil; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -40,6 +41,14 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On |
|
|
|
|
|
|
|
|
|
|
|
private TextView txtVideoDuration; |
|
|
|
private TextView txtVideoDuration; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isShowing; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int screenWidth; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int moveEndPos = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int previewHalfWidth; |
|
|
|
|
|
|
|
|
|
|
|
public VideoPreviewBar(Context context) { |
|
|
|
public VideoPreviewBar(Context context) { |
|
|
|
super(context); |
|
|
|
super(context); |
|
|
|
initView(context); |
|
|
|
initView(context); |
|
|
@ -57,6 +66,23 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On |
|
|
|
txtVideoProgress = view.findViewById(R.id.txt_video_progress); |
|
|
|
txtVideoProgress = view.findViewById(R.id.txt_video_progress); |
|
|
|
txtVideoDuration = view.findViewById(R.id.txt_video_duration); |
|
|
|
txtVideoDuration = view.findViewById(R.id.txt_video_duration); |
|
|
|
setListener(); |
|
|
|
setListener(); |
|
|
|
|
|
|
|
screenWidth = ScreenUtil.getScreenWidth(context); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) { |
|
|
|
|
|
|
|
super.onLayout(changed, l, t, r, b); |
|
|
|
|
|
|
|
if (moveEndPos == 0) { |
|
|
|
|
|
|
|
int previewWidth = texturePreView.getWidth(); |
|
|
|
|
|
|
|
previewHalfWidth = previewWidth / 2; |
|
|
|
|
|
|
|
int marginEnd = 0; |
|
|
|
|
|
|
|
MarginLayoutParams layoutParams = (MarginLayoutParams) texturePreView.getLayoutParams(); |
|
|
|
|
|
|
|
if (layoutParams != null) { |
|
|
|
|
|
|
|
marginEnd = layoutParams.getMarginEnd(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
moveEndPos = screenWidth - previewWidth - marginEnd; |
|
|
|
|
|
|
|
Log.i(TAG, "previewWidth=" + previewWidth); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setPreviewCallback(final String filePath, TextureView texturePreView) { |
|
|
|
private void setPreviewCallback(final String filePath, TextureView texturePreView) { |
|
|
@ -104,15 +130,26 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On |
|
|
|
// us to ms
|
|
|
|
// us to ms
|
|
|
|
hardwareDecode.seekTo(progress * 1000); |
|
|
|
hardwareDecode.seekTo(progress * 1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int percent = progress * screenWidth / duration; |
|
|
|
|
|
|
|
if (percent > previewHalfWidth && percent < moveEndPos && texturePreView != null) { |
|
|
|
|
|
|
|
texturePreView.setTranslationX(percent - previewHalfWidth); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) { |
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) { |
|
|
|
|
|
|
|
if (!isShowing && texturePreView != null) { |
|
|
|
|
|
|
|
isShowing = true; |
|
|
|
|
|
|
|
texturePreView.setVisibility(VISIBLE); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) { |
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) { |
|
|
|
|
|
|
|
if (isShowing && texturePreView != null) { |
|
|
|
|
|
|
|
isShowing = false; |
|
|
|
|
|
|
|
texturePreView.setVisibility(GONE); |
|
|
|
|
|
|
|
} |
|
|
|
if (mPreviewBarCallback != null) { |
|
|
|
if (mPreviewBarCallback != null) { |
|
|
|
mPreviewBarCallback.onStopTracking(seekBar.getProgress()); |
|
|
|
mPreviewBarCallback.onStopTracking(seekBar.getProgress()); |
|
|
|
} |
|
|
|
} |
|
|
@ -131,6 +168,7 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
previewBar.setMax(durationMs); |
|
|
|
previewBar.setMax(durationMs); |
|
|
|
txtVideoDuration.setText(TimeUtil.getVideoTime(durationMs)); |
|
|
|
txtVideoDuration.setText(TimeUtil.getVideoTime(durationMs)); |
|
|
|
|
|
|
|
texturePreView.setVisibility(GONE); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|