Android音视频剪辑器自定义View实战!

Android音视频剪辑器自定义View实战! - 掘金

/*** Created by zhouxuming on 2023/3/30** @descr 音视频剪辑器*/
public class AudioViewEditor extends View {//进度文本显示格式-数字格式public static final int HINT_FORMAT_NUMBER = 0;//进度文本显示格式-时间格式public static final int HINT_FORMAT_TIME = 1;private final Paint mPaint = new Paint();//空间最小宽度private final int MIN_WIDTH = 200;private final float playControlLeft = 10; //播控实际左边界private final float playControlRight = 80; //播控实际右边界//滑块bitmapprivate Bitmap mThumbImage;//progress bar 选中背景
//    private Bitmap mProgressBarSelBg;private Bitmap mMaxThumbImage;private Bitmap mMinThumbImage;//progress bar 背景private Bitmap mProgressBarBg;private float mThumbWidth;private float mThumbHalfWidth; //触摸响应宽度的一半private float mThumbHalfHeight;//seekbar 进度条高度private float mProgressBarHeight;//宽度左右paddingprivate float mWidthPadding;//最小值(绝对)private float mAbsoluteMinValue;//最大值(绝对)private float mAbsoluteMaxValue;//已选标准(占滑动条百分比)最小值private double mPercentSelectedMinValue = 0d;//已选标准(占滑动条百分比)最大值private double mPercentSelectedMaxValue = 1d;//当前事件处理的thumb滑块private Thumb mPressedThumb = null;//滑块事件private ThumbListener mThumbListener;private RectF mProgressBarRect;private RectF mProgressBarSelRect;//是否可以滑动private boolean mIsEnable = true;//最大值和最小值之间要求的最小范围绝对值private float mBetweenAbsoluteValue;//文字格式private int mProgressTextFormat;//文本高度private int mWordHeight;//文本字体大小private float mWordSize;private float mStartMinPercent;private float mStartMaxPercent;private boolean fixedMode; //固定模式private Paint cursorPaint;private Paint borderPaint;//播控按钮部分逻辑private Paint playControlPaint;private boolean isPlay = true; //播控状态private Bitmap playResumeBitmap;private Bitmap playPauseBitmap;private PlayerControlListener playerControlListener;private float cur;// 光标坐标private float pre;// 100 份每一份的偏移量private float min;//起始坐标private float max;//最大坐标private boolean isFirst = true;public AudioViewEditor(Context context) {super(context);}public AudioViewEditor(Context context, AttributeSet attrs) {super(context, attrs);TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.AudioViewEditor, 0, 0);mAbsoluteMinValue = a.getFloat(R.styleable.AudioViewEditor_absoluteMin, (float) 0.0);mAbsoluteMaxValue = a.getFloat(R.styleable.AudioViewEditor_absolutemMax, (float) 100.0);mStartMinPercent = a.getFloat(R.styleable.AudioViewEditor_startMinPercent, 0);mStartMaxPercent = a.getFloat(R.styleable.AudioViewEditor_startMaxPercent, 1);mThumbImage = BitmapFactory.decodeResource(getResources(), a.getResourceId(R.styleable.AudioViewEditor_thumbImage, R.drawable.drag_left_bar));mMaxThumbImage = BitmapFactory.decodeResource(getResources(), R.drawable.drag_right_bar);mProgressBarBg = BitmapFactory.decodeResource(getResources(), a.getResourceId(R.styleable.AudioViewEditor_progressBarBg, R.drawable.seekbar_bg));playPauseBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.play_control_pause);playResumeBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.play_control_resume);//        mProgressBarSelBg = BitmapFactory.decodeResource(getResources(), a.getResourceId(R.styleable.CustomRangeSeekBar_progressBarSelBg, R.mipmap.seekbar_sel_bg));mBetweenAbsoluteValue = a.getFloat(R.styleable.AudioViewEditor_betweenAbsoluteValue, 0);mProgressTextFormat = a.getInt(R.styleable.AudioViewEditor_progressTextFormat, HINT_FORMAT_NUMBER);mWordSize = a.getDimension(R.styleable.AudioViewEditor_progressTextSize, dp2px(context, 16));mPaint.setTextSize(mWordSize);mThumbWidth = mThumbImage.getWidth();mThumbHalfWidth = 0.5f * mThumbWidth;mThumbHalfHeight = 0.5f * mThumbImage.getHeight();
//        mProgressBarHeight = 0.3f * mThumbHalfHeight;mProgressBarHeight = mThumbImage.getHeight();//TOOD 提供定义attrmWidthPadding = mThumbHalfHeight;mWidthPadding += playControlRight;//为了加左右侧播控按钮, 特地添加出来的空间Paint.FontMetrics metrics = mPaint.getFontMetrics();mWordHeight = (int) (metrics.descent - metrics.ascent);/*光标*/cursorPaint = new Paint();cursorPaint.setAntiAlias(true);cursorPaint.setColor(Color.WHITE);borderPaint = new Paint();borderPaint.setAntiAlias(true);borderPaint.setColor(Color.parseColor("#DBAE6A"));playControlPaint = new Paint();playControlPaint.setAntiAlias(true);playControlPaint.setColor(Color.parseColor("#1E1F21"));restorePercentSelectedMinValue();restorePercentSelectedMaxValue();a.recycle();}/*** 格式化毫秒->00:00*/private static String formatSecondTime(int millisecond) {if (millisecond == 0) {return "00:00";}int second = millisecond / 1000;int m = second / 60;int s = second % 60;if (m >= 60) {int hour = m / 60;int minute = m % 60;return hour + ":" + (minute > 9 ? minute : "0" + minute) + ":" + (s > 9 ? s : "0" + s);} else {return (m > 9 ? m : "0" + m) + ":" + (s > 9 ? s : "0" + s);}}/*** 将dip或dp值转换为px值,保证尺寸大小不变** @param dipValue (DisplayMetrics类中属性density)* @return*/public static int dp2px(Context context, float dipValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (dipValue * scale + 0.5f);}/*** 还原min滑块到初始值*/public void restorePercentSelectedMinValue() {setPercentSelectedMinValue(mStartMinPercent);}/*** 还原max滑块到初始值*/public void restorePercentSelectedMaxValue() {setPercentSelectedMaxValue(mStartMaxPercent);}@Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);mProgressBarRect = new RectF(mWidthPadding, mWordHeight + 0.5f * (h - mWordHeight - mProgressBarHeight),w - mWidthPadding, mWordHeight + 0.5f * (h - mWordHeight + mProgressBarHeight));mProgressBarSelRect = new RectF(mProgressBarRect);}/*** 设置seekbar 是否接收事件** @param enabled*/@Overridepublic void setEnabled(boolean enabled) {super.setEnabled(enabled);this.mIsEnable = enabled;}/*** 返回被选择的最小值(绝对值)** @return The currently selected min value.*/public float getSelectedAbsoluteMinValue() {return percentToAbsoluteValue(mPercentSelectedMinValue);}/*** 设置被选择的最小值(绝对值)** @param value 最小值的绝对值*              return 如果最小值与最大值的最小间距达到阈值返回false,正常返回true*/public boolean setSelectedAbsoluteMinValue(float value) {boolean status = true;if (0 == (mAbsoluteMaxValue - mAbsoluteMinValue)) {setPercentSelectedMinValue(0d);} else {float maxValue = percentToAbsoluteValue(mPercentSelectedMaxValue);if (mBetweenAbsoluteValue > 0 && maxValue - value <= mBetweenAbsoluteValue) {value = new Float(maxValue - mBetweenAbsoluteValue);status = false;}if (maxValue - value <= 0) {status = false;value = maxValue;}setPercentSelectedMinValue(absoluteValueToPercent(value));}return status;}public float getAbsoluteMaxValue() {return mAbsoluteMaxValue;}public void setAbsoluteMaxValue(double maxvalue) {this.mAbsoluteMaxValue = new Float(maxvalue);}/*** 返回被选择的最大值(绝对值).*/public float getSelectedAbsoluteMaxValue() {return percentToAbsoluteValue(mPercentSelectedMaxValue);}/*** 设置被选择的最大值(绝对值)** @param value*/public boolean setSelectedAbsoluteMaxValue(float value) {boolean status = true;if (0 == (mAbsoluteMaxValue - mAbsoluteMinValue)) {setPercentSelectedMaxValue(1d);} else {float minValue = percentToAbsoluteValue(mPercentSelectedMinValue);if (mBetweenAbsoluteValue > 0 && value - minValue <= mBetweenAbsoluteValue) {value = new Float(minValue + mBetweenAbsoluteValue);status = false;}if (value - minValue <= 0) {status = false;value = minValue;}setPercentSelectedMaxValue(absoluteValueToPercent(value));}return status;}@Overridepublic boolean onTouchEvent(MotionEvent event) {if (!mIsEnable)return true;switch (event.getAction()) {case MotionEvent.ACTION_DOWN:if (isTouchPlayControl(event.getX())) {isPlay = !isPlay;playerControlListener.onPlayerControl(isPlay);invalidate();return true;}if (mPressedThumb == null && isInCursorRange(event.getX(), cur)) {
//                    if (mThumbListener != null){
//                        mThumbListener.onCursor(cur);
//                    }} else {mPressedThumb = evalPressedThumb(event.getX());if (Thumb.MIN.equals(mPressedThumb)) {if (mThumbListener != null)mThumbListener.onClickMinThumb(getSelectedAbsoluteMaxValue(), getSelectedAbsoluteMinValue());}if (Thumb.MAX.equals(mPressedThumb)) {if (mThumbListener != null)mThumbListener.onClickMaxThumb();}}invalidate();//Intercept parent TouchEventif (getParent() != null) {getParent().requestDisallowInterceptTouchEvent(true);}break;case MotionEvent.ACTION_MOVE:if (mPressedThumb == null && isInCursorRange(event.getX(), cur)) {isMoving = true;float eventX = event.getX();if (eventX >= percentToScreen(mPercentSelectedMaxValue)) {eventX = percentToScreen(mPercentSelectedMaxValue);} else if (eventX <= percentToScreen(mPercentSelectedMinValue)) {eventX = percentToScreen(mPercentSelectedMinValue);}cur = eventX;if (mThumbListener != null) {mThumbListener.onCursorMove(percentToAbsoluteValue(screenToPercent(cur)));}invalidate();} else if (mPressedThumb != null) {float eventX = event.getX();float maxValue = percentToAbsoluteValue(mPercentSelectedMaxValue);float minValue = percentToAbsoluteValue(mPercentSelectedMinValue);float eventValue = percentToAbsoluteValue(screenToPercent(eventX));if (Thumb.MIN.equals(mPressedThumb)) {minValue = eventValue;if (mBetweenAbsoluteValue > 0 && maxValue - minValue <= mBetweenAbsoluteValue) {minValue = new Float((maxValue - mBetweenAbsoluteValue));}
//                        setPercentSelectedMinValue(screenToPercent(event.getX()));if (isFixedMode()) {mPercentSelectedMaxValue = Math.max(0d, Math.min(1d, Math.max(absoluteValueToPercent(eventValue + (maxValue - minValue)), mPercentSelectedMinValue)));}if (cur <= percentToScreen(mPercentSelectedMinValue)) {//防止光标静态越界cur = percentToScreen(mPercentSelectedMinValue);}setPercentSelectedMinValue(absoluteValueToPercent(minValue));if (mThumbListener != null)mThumbListener.onMinMove(getSelectedAbsoluteMaxValue(), getSelectedAbsoluteMinValue());} else if (Thumb.MAX.equals(mPressedThumb)) {maxValue = eventValue;if (mBetweenAbsoluteValue > 0 && maxValue - minValue <= mBetweenAbsoluteValue) {maxValue = new Float(minValue + mBetweenAbsoluteValue);}
//                        setPercentSelectedMaxValue(screenToPercent(event.getX()));if (isFixedMode()) {mPercentSelectedMinValue = Math.max(0d, Math.min(1d, Math.min(absoluteValueToPercent(eventValue - (maxValue - minValue)), mPercentSelectedMaxValue)));}if (cur >= percentToScreen(mPercentSelectedMaxValue)) {//防止光标静态越界cur = percentToScreen(mPercentSelectedMaxValue);}setPercentSelectedMaxValue(absoluteValueToPercent(maxValue));if (mThumbListener != null)mThumbListener.onMaxMove(getSelectedAbsoluteMaxValue(), getSelectedAbsoluteMinValue());}}//Intercept parent TouchEventif (getParent() != null) {getParent().requestDisallowInterceptTouchEvent(true);}break;case MotionEvent.ACTION_UP:if (isMoving) {if (mThumbListener != null) {mThumbListener.onCursorUp(percentToAbsoluteValue(screenToPercent(cur)));}isMoving = false;}if (Thumb.MIN.equals(mPressedThumb)) {if (mThumbListener != null)mThumbListener.onUpMinThumb(getSelectedAbsoluteMaxValue(), getSelectedAbsoluteMinValue());}if (Thumb.MAX.equals(mPressedThumb)) {if (mThumbListener != null)mThumbListener.onUpMaxThumb(getSelectedAbsoluteMaxValue(), getSelectedAbsoluteMinValue());}//Intercept parent TouchEventif (getParent() != null) {getParent().requestDisallowInterceptTouchEvent(true);}break;case MotionEvent.ACTION_CANCEL:if (Thumb.MIN.equals(mPressedThumb)) {if (mThumbListener != null)mThumbListener.onUpMinThumb(getSelectedAbsoluteMaxValue(), getSelectedAbsoluteMinValue());}if (Thumb.MAX.equals(mPressedThumb)) {if (mThumbListener != null)mThumbListener.onUpMaxThumb(getSelectedAbsoluteMaxValue(), getSelectedAbsoluteMinValue());}mPressedThumb = null;//Intercept parent TouchEventif (getParent() != null) {getParent().requestDisallowInterceptTouchEvent(true);}break;}return true;}private boolean isTouchPlayControl(float eventX) {if (eventX > playControlLeft && eventX < playControlRight) {return true;}return false;}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int width = MIN_WIDTH;if (MeasureSpec.UNSPECIFIED != MeasureSpec.getMode(widthMeasureSpec)) {width = MeasureSpec.getSize(widthMeasureSpec);}int height = mThumbImage.getHeight() + mWordHeight * 2;if (MeasureSpec.UNSPECIFIED != MeasureSpec.getMode(heightMeasureSpec)) {height = Math.min(height, MeasureSpec.getSize(heightMeasureSpec));}setMeasuredDimension(width, height);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);// draw seek bar background linemPaint.setStyle(Paint.Style.FILL);drawPlayControl(canvas);canvas.drawBitmap(mProgressBarBg, null, mProgressBarRect, mPaint);// draw seek bar active range linemProgressBarSelRect.left = percentToScreen(mPercentSelectedMinValue);mProgressBarSelRect.right = percentToScreen(mPercentSelectedMaxValue);//canvas.drawBitmap(mProgressBarSelBg, mWidthPadding, 0.5f * (getHeight() - mProgressBarHeight), mPaint);//        canvas.drawBitmap(mProgressBarSelBg, null, mProgressBarSelRect, mPaint); //原中部选中进度// draw minimum thumbdrawThumb(percentToScreen(mPercentSelectedMinValue), Thumb.MIN.equals(mPressedThumb), canvas, false);// draw maximum thumbdrawThumb(percentToScreen(mPercentSelectedMaxValue), Thumb.MAX.equals(mPressedThumb), canvas, true);mPaint.setColor(Color.rgb(255, 165, 0));mPaint.setAntiAlias(true);
//        mPaint.setTextSize(DensityUtils.dp2px(getContext(), 16));drawThumbMinText(percentToScreen(mPercentSelectedMinValue), getSelectedAbsoluteMinValue(), canvas);drawThumbMaxText(percentToScreen(mPercentSelectedMaxValue), getSelectedAbsoluteMaxValue(), canvas);drawBorder(canvas);drawCursor(canvas);}private void drawPlayControl(Canvas canvas) {canvas.drawRoundRect(playControlLeft, mProgressBarRect.top, playControlRight + mThumbWidth + mThumbHalfWidth, mProgressBarRect.bottom, 5, 5, playControlPaint);Bitmap targetBitmap = isPlay ? playPauseBitmap : playResumeBitmap;//x轴距离未计算准确 y轴正确canvas.drawBitmap(targetBitmap, (playControlLeft + (playControlRight - playControlLeft) / 2) - mThumbHalfWidth + (targetBitmap.getWidth() >> 1), mProgressBarRect.top + (mProgressBarRect.bottom - mProgressBarRect.top) / 2 - (targetBitmap.getHeight() >> 1), playControlPaint);}private void drawBorder(Canvas canvas) {//topfloat borderLeft = mProgressBarSelRect.left;float borderRight = mProgressBarSelRect.right;canvas.drawRect(borderLeft - 1, mProgressBarRect.top, borderRight + 1, mProgressBarRect.top + 10, borderPaint);//bottomcanvas.drawRect(borderLeft - 1, mProgressBarRect.bottom, borderRight + 1, mProgressBarRect.bottom - 10, borderPaint);}private void drawCursor(Canvas canvas) {min = percentToScreen(mPercentSelectedMinValue);//开始坐标max = percentToScreen(mPercentSelectedMaxValue);//终点坐标pre = (getWidth() - 2 * mWidthPadding) / 1000; //每一份的坐标if (isFirst) {cur = min;isFirst = false;}canvas.drawRect(cur - 2, mProgressBarRect.top + 5, cur + 2, mProgressBarRect.bottom - 5, cursorPaint);}//启动播放线程检查 ptspublic void startMove() {new Thread(new Runnable() {@Overridepublic void run() {while (true) {if (isPlay) {long pts = playerCallback != null ? playerCallback.getCurrentPosition() : 0;updatePTS(pts);}try {Thread.sleep(30);} catch (InterruptedException e) {e.printStackTrace();}}}}).start();}/*** 根据播放器 pts 控制游标进度** @param pts*/public void updatePTS(float pts) {if (isMoving) {return;}if (pts > 0) {double v = absoluteValueToPercent(pts);cur = percentToScreen(v);if (cur >= max || cur < min) {cur = min;}invalidate();}}public boolean isPlay() {return isPlay;}public void setPlay(boolean play) {isPlay = play;}private boolean isMoving = false;@Overrideprotected Parcelable onSaveInstanceState() {Bundle bundle = new Bundle();bundle.putParcelable("SUPER", super.onSaveInstanceState());bundle.putDouble("MIN", mPercentSelectedMinValue);bundle.putDouble("MAX", mPercentSelectedMaxValue);return bundle;}@Overrideprotected void onRestoreInstanceState(Parcelable parcel) {Bundle bundle = (Bundle) parcel;super.onRestoreInstanceState(bundle.getParcelable("SUPER"));mPercentSelectedMinValue = bundle.getDouble("MIN");mPercentSelectedMaxValue = bundle.getDouble("MAX");}/*** Draws the "normal" resp. "pressed" thumb image on specified x-coordinate.** @param screenCoord The x-coordinate in screen space where to draw the image.* @param pressed     Is the thumb currently in "pressed" state?* @param canvas      The canvas to draw upon.*/private void drawThumb(float screenCoord, boolean pressed, Canvas canvas, boolean isMax) {//基准点 bar 居中位置
//        canvas.drawBitmap(isMax ? mMaxThumbImage : mThumbImage, screenCoord - mThumbHalfWidth, (mWordHeight + 0.5f * (getHeight() - mWordHeight) - mThumbHalfHeight), mPaint);//基准点顶两边位置canvas.drawBitmap(isMax ? mMaxThumbImage : mThumbImage, isMax ? screenCoord : screenCoord - mThumbHalfWidth * 2, (mWordHeight + 0.5f * (getHeight() - mWordHeight) - mThumbHalfHeight), mPaint);}/*** 画min滑块值text** @param screenCoord* @param value* @param canvas*/private void drawThumbMinText(float screenCoord, Number value, Canvas canvas) {String progress = getProgressStr(value.intValue());float progressWidth = mPaint.measureText(progress);canvas.drawText(progress, (screenCoord - progressWidth / 2) - mThumbHalfWidth, mWordSize, mPaint);}/*** 画max滑块值text** @param screenCoord* @param value* @param canvas*/private void drawThumbMaxText(float screenCoord, Number value, Canvas canvas) {String progress = getProgressStr(value.intValue());float progressWidth = mPaint.measureText(progress);canvas.drawText(progress, (screenCoord - progressWidth / 2) + mThumbHalfWidth, mWordSize, mPaint);}/*** 根据touchX, 判断是哪一个thumb(Min or Max)** @param touchX 触摸的x在屏幕中坐标(相对于容器)*/private Thumb evalPressedThumb(float touchX) {Thumb result = null;boolean minThumbPressed = isInThumbRange(touchX, mPercentSelectedMinValue, false);boolean maxThumbPressed = isInThumbRange(touchX, mPercentSelectedMaxValue, true);if (minThumbPressed && maxThumbPressed) {// if both thumbs are pressed (they lie on top of each other), choose the one with more room to drag. this avoids "stalling" the thumbs in a corner, not being able to drag them apart anymore.result = (touchX / getWidth() > 0.5f) ? Thumb.MIN : Thumb.MAX;} else if (minThumbPressed) {result = Thumb.MIN;} else if (maxThumbPressed) {result = Thumb.MAX;}return result;}/*** 判断touchX是否在滑块点击范围内** @param touchX            需要被检测的 屏幕中的x坐标(相对于容器)* @param percentThumbValue 需要检测的滑块x坐标百分比值(滑块x坐标)*/private boolean isInThumbRange(float touchX, double percentThumbValue, boolean isMax) {if (isMax) {return Math.abs(touchX - mThumbHalfWidth - percentToScreen(percentThumbValue)) <= mThumbHalfWidth;} else {return Math.abs(touchX + mThumbHalfWidth - percentToScreen(percentThumbValue)) <= mThumbHalfWidth;}
//        return Math.abs(touchX - percentToScreen(percentThumbValue)) <= mThumbHalfWidth; //居中基准时}/*** 判断用户是否触碰光标** @param touchX  需要被检测的 屏幕中的x坐标(相对于容器)* @param cursorX 光标x坐标(滑块x坐标)* @return*/private boolean isInCursorRange(float touchX, float cursorX) {return Math.abs(touchX - cursorX) <= mThumbHalfWidth;}/*** 设置已选择最小值的百分比值*/public void setPercentSelectedMinValue(double value) {mPercentSelectedMinValue = Math.max(0d, Math.min(1d, Math.min(value, mPercentSelectedMaxValue)));invalidate();}/*** 设置已选择最大值的百分比值*/public void setPercentSelectedMaxValue(double value) {mPercentSelectedMaxValue = Math.max(0d, Math.min(1d, Math.max(value, mPercentSelectedMinValue)));invalidate();}/*** 进度值,从百分比到绝对值** @return*/@SuppressWarnings("unchecked")private float percentToAbsoluteValue(double normalized) {return (float) (mAbsoluteMinValue + normalized * (mAbsoluteMaxValue - mAbsoluteMinValue));}/*** 进度值,从绝对值到百分比*/private double absoluteValueToPercent(float value) {if (0 == mAbsoluteMaxValue - mAbsoluteMinValue) {// prevent division by zero, simply return 0.return 0d;}return (value - mAbsoluteMinValue) / (mAbsoluteMaxValue - mAbsoluteMinValue);}/*** 进度值,从百分比值转换到屏幕中坐标值*/private float percentToScreen(double percentValue) {return (float) (mWidthPadding + percentValue * (getWidth() - 2 * mWidthPadding));}/*** 进度值,转换屏幕像素值到百分比值*/private double screenToPercent(float screenCoord) {int width = getWidth();if (width <= 2 * mWidthPadding) {// prevent division by zero, simply return 0.return 0d;} else {double result = (screenCoord - mWidthPadding) / (width - 2 * mWidthPadding);return Math.min(1d, Math.max(0d, result));}}public void setThumbListener(ThumbListener mThumbListener) {this.mThumbListener = mThumbListener;}private String getProgressStr(int progress) {String progressStr;if (mProgressTextFormat == HINT_FORMAT_TIME) {progressStr = formatSecondTime(progress);} else {progressStr = String.valueOf(progress);}return progressStr;}public boolean isFixedMode() {return fixedMode;}public void setFixedMode(boolean fixedMode) {this.fixedMode = fixedMode;}/*** 重置总时长-单位秒** @param totalSecond*/public void resetTotalSecond(int totalSecond) {if (totalSecond > 0 && totalSecond < 12000) {mAbsoluteMaxValue = totalSecond * 1000;mAbsoluteMinValue = 0.0f;mProgressTextFormat = HINT_FORMAT_TIME;invalidate();}}/*** 重置总时长-单位毫秒** @param totalMillisecond*/public void resetTotalMillisecond(float totalMillisecond) {if (totalMillisecond > 0 && totalMillisecond < 1200000) {mAbsoluteMaxValue = totalMillisecond;mAbsoluteMinValue = 0.0f;mProgressTextFormat = HINT_FORMAT_TIME;invalidate();}}public void setPlayerControlListener(PlayerControlListener playerControlListener) {this.playerControlListener = playerControlListener;}/*** Thumb枚举, 最大或最小*/private enum Thumb {MIN, MAX}public interface PlayerControlListener {void onPlayerControl(boolean isPlay);}/*** 游标以及滑块事件*/public interface ThumbListener {void onClickMinThumb(Number max, Number min);void onClickMaxThumb();void onUpMinThumb(Number max, Number min);void onUpMaxThumb(Number max, Number min);void onMinMove(Number max, Number min);void onMaxMove(Number max, Number min);void onCursorMove(Number cur);void onCursorUp(Number cur);}public interface IPlayerCallback {long getCurrentPosition();}private IPlayerCallback playerCallback = null;public void setPlayerCallback(IPlayerCallback playerCallback) {this.playerCallback = playerCallback;}public void release() {isPlay = false;}
}

image.png

 Android音视频剪辑器自定义View实战! - 掘金话不多说,先上一个代码完成效果。 动图好像录成横屏的了,也没找到调整反转 GIF 的位置,下面再补一张设计稿静态图吧 最近这几年音视频应用越来越广泛,随之而来的音视频相关的需求也越来越多,音视频的剪辑https://juejin.cn/post/7236635197071802424?utm_source=gold_browser_extension#heading-10

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/97433.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ElasticSearch DSL语句(bool查询、算分控制、地理查询、排序、分页、高亮等)

文章目录 DSL 查询种类DSL query 基本语法1、全文检索2、精确查询3、地理查询4、function score &#xff08;算分控制&#xff09;5、bool 查询 搜索结果处理1、排序2、分页3、高亮 RestClient操作 DSL 查询种类 查询所有&#xff1a;查询所有数据&#xff0c;一般在测试时使…

PySpark-核心编程

2. PySpark——RDD编程入门 文章目录 2. PySpark——RDD编程入门2.1 程序执行入口SparkContext对象2.2 RDD的创建2.2.1 并行化创建2.2.2 获取RDD分区数2.2.3 读取文件创建 2.3 RDD算子2.4 常用Transformation算子2.4.1 map算子2.4.2 flatMap算子2.4.3 reduceByKey算子2.4.4 Wor…

ajax-axios-url-form-serialize 插件

AJAX AJAX 概念 1.什么是 AJAX ? mdn 使用浏览器的 XMLHttpRequest 对象 与服务器通信 浏览器网页中&#xff0c;使用 AJAX技术&#xff08;XHR对象&#xff09;发起获取省份列表数据的请求&#xff0c;服务器代码响应准备好的省份列表数据给前端&#xff0c;前端拿到数据数…

SAP动态安全库存简介

动态安全库存:跑需求计划时,ERP系统按设置的库存方式自动计算出满足一定时间内可保障生产的库存数量 SAP动态安全库存的计算公式:动态安全库存=平均日需求*覆盖范围。 平均日需求=特定时期内的总需求/特定时期内的工作天数 覆盖范围指在没又货物供应的情况下,库存可以维…

实现两个栈模拟队列

实现两个栈模拟队列 思路&#xff1a;可以想象一下左手和右手&#xff0c;两个栈&#xff1a;stack1&#xff08;数据所在的栈&#xff09; &#xff0c;stack2&#xff08;临时存放&#xff09;。 入队&#xff1a;需要将入队 num 加在 stack1 的栈顶即可&#xff1b; 出队&am…

测试工具coverage的高阶使用

在文章Python之单元测试使用的一点心得中&#xff0c;笔者介绍了自己在使用Python测试工具coverge的一点心得&#xff0c;包括&#xff1a; 使用coverage模块计算代码测试覆盖率使用coverage api计算代码测试覆盖率coverage配置文件的使用coverage badge的生成 本文在此基础上…

【Leetcode】103.二叉树的锯齿形层序遍历

一、题目 1、题目描述 给你二叉树的根节点 root ,返回其节点值的 锯齿形层序遍历 。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。 示例1: 输入:root = [3,9,20,null,null,15,7] 输出:[[3],[20,9],[15,7]]示例2: 输入:root = [1] 输…

hive-无法启动hiveserver2

启动hiveserver2没有反应&#xff0c;客户端也无法连接( beeline -u jdbc:hive2://node01:10000 -n root) 报错如下 查看hive的Log日志&#xff0c;发现如下报错 如何解决 在hive的hive_site.xml中添加如下代码 <property><name>hive.server2.active.passive…

论文笔记:Continuous Trajectory Generation Based on Two-Stage GAN

2023 AAAI 1 intro 1.1 背景 建模人类个体移动模式并生成接近真实的轨迹在许多应用中至关重要 1&#xff09;生成轨迹方法能够为城市规划、流行病传播分析和交通管控等城市假设分析场景提供仿仿真数据支撑2&#xff09;生成轨迹方法也是目前促进轨迹数据开源共享与解决轨迹数…

fiddler抓包问题记录,支持https、解决 tunnel to 443

fiddler下载安装步骤及基本配置 fiddler抓包教程&#xff0c;如何抓取HTTPS请求&#xff0c;详细教程 可能遇到的问题及解决方案 1. 不能正常访问页面&#xff08;所有https都无法访问&#xff09; 解决方案&#xff1a;查看下面配置是否正确 Rules-customization 找到 OnB…

不是说嵌入式是风口吗,那为什么工作还那么难找?

最近确实有很多媒体、机构渲染嵌入式可以拿高薪&#xff0c;这在行业内也是事实&#xff0c;但前提是你有足够的竞争力&#xff0c;真的懂嵌入式。 时至今日&#xff0c;能做嵌入式程序开发的人其实相当常见&#xff0c;尤其是随着树莓派、Arduino等开发板的普及&#xff0c;甚…

el-table实现懒加载(el-table-infinite-scroll)

2023.8.15今天我学习了用el-table对大量的数据进行懒加载。 效果如下&#xff1a; 1.首先安装&#xff1a; npm install --save el-table-infinite-scroll2 2.全局引入&#xff1a; import ElTableInfiniteScroll from "el-table-infinite-scroll";// 懒加载 V…

ansible(1)-- 部署ansible连接被控端

目录 一、部署ansible 1.1 安装 1.2 测试连接 192.168.136.55 ansible 192.168.136.56被控端 一、部署ansible 1.1 安装 zabbix-s只是主机名&#xff0c;不用在意&#xff0c;更好该主机也安装了zabbix&#xff0c;不好更改。 下载阿里云epel源 #安装阿里云的epel源&#…

机器学习笔记 - 基于keras + 小型Xception网络进行图像分类

一、简述 Xception 是深度为 71 层的卷积神经网络,仅依赖于深度可分离的卷积层。 论文中将卷积神经网络中的 Inception 模块解释为常规卷积和深度可分离卷积运算(深度卷积后跟点卷积)之间的中间步骤。从这个角度来看,深度可分离卷积可以理解为具有最大数量塔的 Inception 模…

websocker无法注入依赖

在公司中准备用websocker统计在线人数&#xff0c;在WebSocketServer使用StringRedisTemplate保存数据到redis中去&#xff0c;但是在保存的时候显示 StringRedisTemplate变量为null 详细问题 2023-08-20 10:37:14.109 ERROR 28240 --- [nio-7125-exec-1] o.a.t.websocket.po…

Python爬虫的scrapy的学习(学习于b站尚硅谷)

目录 一、scrapy  1. scrapy的安装  &#xff08;1&#xff09;什么是scrapy  &#xff08;2&#xff09;scrapy的安装 2. scrapy的基本使用  &#xff08;1&#xff09;scrap的使用步骤  &#xff08;2&#xff09;代码的演示 3. scrapy之58同城项目结构和基本方法&…

网络安全---webshell实践

一、首先环境配置 1.上传文件并解压 2.进入目录下 为了方便解释&#xff0c;我们只用两个节点&#xff0c;启动之后&#xff0c;大家可以看到有 3 个容器&#xff08;可想像成有 3 台服务器就成&#xff09;。 二、使用蚁剑去连接 因为两台节点都在相同的位置存在 ant.jsp&…

CI/CD入门(二)

CI/CD入门(二) 目录 CI/CD入门(二) 1、代码上线方案 1.1 早期手动部署代码1.2 合理化上线方案1.3 大型企业上线制度和流程1.4 php程序代码上线的具体方案1.5 Java程序代码上线的具体方案1.6 代码上线解决方案注意事项2、理解持续集成、持续交付、持续部署 2.1 持续集成2.2 持续…

政务中心站至政务中心东站右线盾构本月始发

本报记者 赵鹏 实习记者 池阳 通讯员 董浩程 立秋已过&#xff0c;平谷线“瓜熟蒂落”的日子指日可待。在左线隧道刚刚顺利贯通后&#xff0c;平谷线政务中心站至政务中心东站区间右线隧道已展开盾构组装施工&#xff0c;右线盾构即将于本月内始发&#xff0c;被誉为“地下蛟龙…

若依项目的介绍(前后端分离版本)

目录 一、若依介绍 &#xff08;一&#xff09;简单介绍 &#xff08;二&#xff09;若依版本 &#xff08;三&#xff09;Git远程拉取步骤 二、项目的技术介绍 &#xff08;一&#xff09;后端技术 1.spring boot 2.Spring Security安全控制 3.MyBatis 4.MySQL和R…