gpt4 book ai didi

android - 带有预览的搜索栏,例如 youtube

转载 作者:行者123 更新时间:2023-12-03 05:27:39 26 4
gpt4 key购买 nike

我需要一些组件或github链接来显示视频的搜索栏(或进度条),并在设置的时间(由搜索栏设置)显示视频的缩略图(像 youtube)

非常感谢!

最佳答案

好吧,我想通了,我上传到:

https://github.com/CorradiSebastian/SeekBarPreview

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sebastiancorradi.seekbar.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coded By Sebastian Corradi SebastianCorradi@gmail.com"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:textColor="#AAAAAA"
android:textSize="10dp"
app:layout_constraintTop_toTopOf="parent" />

<com.sebastiancorradi.seekbar.components.SeekBarPreview
android:id="@+id/seekBarPreviewSDCard"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>


</android.support.constraint.ConstraintLayout>

.JAVA:

public class SeekBarPreview  extends LinearLayout {
private SeekBar mSeekBar;
private ImageView mPreview;
private View rootView;

private int totalDuration;
private int currentPosition;
private MediaMetadataRetriever retriever;

public SeekBarPreview(Context context) {
super(context);
init();
}

public SeekBarPreview(Context context, AttributeSet attrs)
{
super(context, attrs);
init();
}

public SeekBarPreview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

private void init(){
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rootView = inflater.inflate(R.layout.seekbarpreview_layout, this, true);

mPreview = rootView.findViewById(R.id.imageView);
mSeekBar = rootView.findViewById(R.id.seekBar);
retriever = new MediaMetadataRetriever();

mPreview.setScaleType(ImageView.ScaleType.CENTER_CROP);
}

public void setUrl(String url){
retriever.setDataSource(url, new HashMap<String, String>());
String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
if (duration != null) {
totalDuration = Integer.valueOf(duration);//milisecs
} else {
totalDuration = 0;
//or throw an exception
}
}
public void setUri(Uri uri){
retriever.setDataSource(getContext(),uri);
String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
if (duration != null) {
totalDuration = Integer.valueOf(duration);//milisecs
} else {
totalDuration = 0;
//or throw an exception
}
}

public void update(int i) {
Long newPosition = totalDuration * i * 10L;
Bitmap bitmap = retriever.getFrameAtTime(newPosition);
mPreview.setImageBitmap(bitmap);


int x = mSeekBar.getThumb().getBounds().centerX();
int newPos = x - (i * mPreview.getWidth() / 100);
mPreview.setX(newPos);


}

public void initialize(){

mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
update(i);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});
mSeekBar.setProgress(1);
}
}

在父级中,您只需添加 MXL:

<com.sebastiancorradi.seekbar.components.SeekBarPreview
android:id="@+id/seekBarPreviewSDCard"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>

Java:

SeekBarPreview seekBarPreviewSDCard = findViewById(R.id.seekBarPreviewSDCard);

String path = "android.resource://" + getPackageName() + "/" + R.raw.bunny;
seekBarPreviewSDCard.setUri(Uri.parse(path));

seekBarPreviewSDCard.initialize();

关于android - 带有预览的搜索栏,例如 youtube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48236910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com