我在对话框中使用搜索栏媒体播放器,但是当我点击它时,搜索栏不起作用
我正在制作通话记录应用程序,并使用seek播放音频文件。当我点击搜索栏时,它会向前移动,但在1秒钟后,它会回到之前的位置。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final Holder holder = new Holder();
View rowView;
rowView = inflater.inflate(R.layout.audio_calls_list_row, null);
holder.playpauseView = (LinearLayout) rowView.findViewById(R.id.play_pause_view);
holder.playpausebtn = (ImageButton) rowView.findViewById(R.id.play_pause_btn);
holder.callfileName = (TextView) rowView.findViewById(R.id.audiofileName);
holder.totaltime = (TextView) rowView.findViewById(R.id.durationtiming);
holder.callstatus1 = (ImageView) rowView.findViewById(R.id.callstatusid);
holder.btnshare = (ImageView) rowView.findViewById(R.id.btn_share);
holder.number = (TextView) rowView.findViewById(R.id.txt_number);
holder.filetimecreated = (TextView) rowView.findViewById(R.id.myaudiofiletime);
holder.filedatecreated = (TextView) rowView.findViewById(R.id.myaudiofiledate);
if (audioFileList.size() > 0) {
try {
mmr = new MediaMetadataRetriever();
mmr.setDataSource(audioFileList.get(position).getMyfilepath());
String durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
int millSecond = Integer.parseInt(durationStr);
//setting listview totaltime
holder.totaltime.setText(String.format("%02d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours((long) millSecond),
TimeUnit.MILLISECONDS.toMinutes((long) millSecond),
TimeUnit.MILLISECONDS.toSeconds((long) millSecond) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) millSecond))));
String filename = audioFileList.get(position).filename;
final String call_type = filename.substring(25, 33);
int numlastpositionstr = filename.lastIndexOf("_");
String call_number = filename.substring(34, numlastpositionstr);
String call_time = filename.substring(16, 21);
String call_date = filename.substring(5, 15);
char[] call_timeArray = call_time.toCharArray();
for (int x = 0; x < call_timeArray.length; x++) {
if (call_timeArray[x] == '.') {
call_timeArray[x] = ':';
}
}
call_time = String.valueOf(call_timeArray);
holder.filetimecreated.setText(call_time);
holder.filedatecreated.setText(call_date);
String name = getContactDisplayNameByNumber(call_number, context);
holder.number.setText(call_number);
holder.callfileName.setText(name);
//status incomming or outgoing.
if (filename.contains(CallStatus.INCOMING) || filename.contains (CallStatus.incoming)) {
// if (call_type.equals(CallStatus.INCOMING) || call_type.equals(CallStatus.incoming)) {
holder.callstatus1.setBackgroundResource(R.drawable.ic_call_received_black_24dp);
} else {
holder.callstatus1.setBackgroundResource(R.drawable.ic_call_made_black_24dp);
}
// if (call_type.equals(CallStatus.OUTGOING) || call_type.equals(CallStatus.outgoing)) {
// holder.callstatus1.setBackgroundResource(android.R.drawable.sym_call_outgoing);
// }
} catch (Exception e) {
System.out.println("Exaption is here " + e);
}
} else {
Log.d("audiofilesize", "Audio file size is 0");
}
holder.playpausebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final AlertDialog.Builder audioPlayDialog = new AlertDialog.Builder(context, R.style.DialogTheme);
LayoutInflater inflater1 = LayoutInflater.from(context.getApplicationContext());
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View layout1 = inflater1.inflate(R.layout.dialoguelayout, null);
audioPlayDialog.setView(layout1)
.setNeutralButton("", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
mediaPlayer.pause();
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.release();
myHandler.removeCallbacks(UpdateSongTime);
filecompleted = false;
running = false;
}
});
audioPlayDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
try {
mediaPlayer.pause();
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.release();
myHandler.removeCallbacks(UpdateSongTime);
filecompleted = false;
running = false;
} catch (Exception e) {
}
}
});
audioPlayDialog.setCancelable(true);
final ImageButton audioPlayDialogButton = (ImageButton) layout1.findViewById(R.id.your_dialog_button);
audioPlayDialogSeekBar = (SeekBar) layout1.findViewById(R.id.your_dialog_seekbar);
dfilename = (TextView) layout1.findViewById(R.id.dcallnameid);
remaingtime = (TextView) layout1.findViewById(R.id.dremaingtime);
totaltime = (TextView) layout1.findViewById(R.id.dtotaltime);
callstatus = (TextView) layout1.findViewById(R.id.dcallstatus);
audioPlayDialog.create();
audioPlayDialog.show();
String[] call_type1 = getcallstatus(position);
callstatus.setText(call_type1[0]);
if (call_type1[1].equals("")) {
dfilename.setText(call_type1[2]);
} else {
dfilename.setText(call_type1[1]);
}
audioPlayDialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (filecompleted == true) {
updateTime();
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
audioPlayDialogButton.setBackgroundResource(R.drawable.ic_play_circle_outline_black_48dp);
}
} else {
mediaPlayer.start();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
audioPlayDialogButton.setBackgroundResource(R.drawable.ic_pause_circle_outline_black_48dp);
}
}
} else {
try {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
audioPlayDialogButton.setBackgroundResource(R.drawable.ic_play_circle_outline_black_48dp);
}
} else {
mediaPlayer.start();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
audioPlayDialogButton.setBackgroundResource(R.drawable.ic_pause_circle_outline_black_48dp);
}
}
} catch (Exception e) {
}
}
}
});
audioPlayDialogSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.d("Progress changed", "progress changed" + progress);
audioPlayDialogSeekBar.setMax((int) finalTime);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.d("starttracking", "progress starTT");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
final Uri data = Uri.parse(audioFileList.get(position).getMyfilepath());
System.out.println("file Path is here" + data.getPath());
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(context, data);
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
finalTime = mp.getDuration();
running = true;
mp.start();
// audioPlayDialogSeekBar = true;
audioPlayDialogSeekBar.setMax(mediaPlayer.getDuration());
if (finalTime != 0) {
totaltime.setText(String.format("%02d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours((long) finalTime),
TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) finalTime))));
}
}
});
} catch (Exception e) {
}
myHandler = new Handler();
totaltime.setText(String.format("%02d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours((long) finalTime),
TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) finalTime))));
updateTime();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
audioPlayDialogButton.setBackgroundResource (R.drawable.ic_pause_circle_outline_black_48dp);
}
firsttime = false;
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
audioPlayDialogSeekBar.setProgress(0);
audioPlayDialogButton.setBackgroundResource (R.drawable.ic_play_circle_outline_black_48dp);
filecompleted = true;
startTime = 0;
mediaPlayer.pause();
checkpoint = true;
mp.seekTo(10);
mp.pause();
}
});
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});
}
private void updateTime() {
UpdateSongTime = new Runnable() {
public void run() {
if (running == true) {
startTime = mediaPlayer.getCurrentPosition();
}
if (filecompleted == true) {
if (checkpoint) {
startTime = 0;
checkpoint = false;
}
}
if (startTime > (finalTime - 100)) {
remaingtime.setText("00:00:00");
} else {
remaingtime.setText(String.format("%02d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours((long) startTime),
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime))));
audioPlayDialogSeekBar.setProgress((int) startTime);
myHandler.postDelayed(this, 100);
}
}
};
myHandler1 = new Handler();
UpdateSongTime1 = new Runnable() {
public void run() {
myHandler.postDelayed(this, 100);
}
};
startTime = mediaPlayer.getCurrentPosition();
audioPlayDialogSeekBar.setProgress((int) startTime);
myHandler.postDelayed(UpdateSongTime, 100);
}
});
holder.btnshare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// final Uri data = Uri.parse(audioFileList.get(position).getMyfilepath());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("audio/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File (audioFileList.get(position).getMyfilepath())));
context.startActivity(intent);
}
});
return rowView;
}
try {
if (mediaPlayer.isPlaying() || mediaPlayer != null) {
if (fromUser)
mediaPlayer.seekTo(progress);
} else if (mediaPlayer == null) {
Toast.makeText(context.getApplicationContext(), "Media is not running",
Toast.LENGTH_SHORT).show();
seekBar.setProgress(0);
}
} catch (Exception e) {
Log.e("seek bar", "" + e);
seekBar.setEnabled(false);
}
我使用此代码和问题解决
你给媒体打电话了吗。希克托(职位)?据我所知,你还没有在你的Seekbarchenger聆听者身上打过这个电话。
因为你总是设置相对于你的歌曲进度的搜索栏位置...它总是会回到以前的状态...
解决方案:在你的seekbarchaneglistener中。。使用onSeekbarchanged并使用(媒体播放器)。希克托(职位)
我收到一个错误,上面写着“未能解析:com.github.mancj:MaterialSearchBar:0.8.5”。关于如何修复这个问题,有什么想法吗? 我的构建gradle项目 构建gradle应用程序:
苹果风格的搜索栏,带有一个自动隐藏的取消按钮。适合作为主搜索固定在页面顶部,搜索栏只是一个CSS组件,不提供任何JS功能,你也可以单独使用 .search-input。 <header class="bar bar-nav"> <h1 class='title'>搜索栏</h1> </header> <div class="bar bar-header-secondary"> <d
搜索栏允许用户在列表元素中搜索,或者它可以用来作为UI组件,放到你自己的搜索实现中。 搜索栏布局 搜索栏应该放到“.page”内,“.page-content”前: <div class="page"> <!-- Search bar --> <form class="searchbar"> <div class="searchbar-input"> <inpu
<div class="ui-searchbar-wrap ui-border-b"> <div class="ui-searchbar ui-border-radius"> <i class="ui-icon-search"></i> <div class="ui-searchbar-text">搜索号码(2-10位)</div>
search这部分是利用小程序input组件实现,在下面的示例中主要使用了focus和bindinput两个属性,由于mpvue从底层支持 Vue.js 语法和构建工具体系,因此可以用vue的v-model进行双向数据绑定,示例如下: <template> <div class="page"> <div class="page__hd"> <div class="page_
描述 (Description) 框架7允许使用searchbar类搜索元素。 搜索栏参数 S.No 参数和描述 类型 默认 1 searchList 它搜索列表的CSS选择器或HTML元素。 字符串或HTML元素 - 2 searchIn 您可以搜索CSS选择器的列表视图元素,也可以通过传递.item-title , .item-text类来搜索元素。 string '.item-title'