>我正在播放Uri它的工作的音频.
>从每个Listview项目单击一个按钮.
>从每个Listview项目单击一个按钮.
问题:音频正在播放列表视图,但仍然Seekbar没有移动(更新).
编辑:1
1.Audio正在播放每个Listview项目完全,但Seekbar不工作(不更新).
请帮我解决这个问题.
我的Listview数组适配器类:
Adapter.class
private static final int UPDATE_FREQUENCY = 500; int progress=0; public View getView(final int position,View view,ViewGroup parent) { LayoutInflater inflater = context.getLayoutInflater(); View rowView = inflater.inflate(R.layout.audio_listview,null,true); ListenAUdioButton = (Button) rowView.findViewById(R.id.ListenAudiobuttonxml); seek_bar_view = (SeekBar) rowView.findViewById(R.id.seek_bar); ListenAUdioButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // text_shown.setText("Playing..."); try { try { // get Internet status isInternetPresent = cd1.isConnectingToInternet(); // check for Internet status if (isInternetPresent) { if (!itemname3_AUdio_FILE[position].equals("") || !itemname3_AUdio_FILE[position].equals("null")) { System.out.println(" AUdio FILE :-)" + itemname3_AUdio_FILE[position]); player = new MediaPlayer(); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setDataSource(context,Uri.parse(itemname3_AUdio_FILE[position])); player.prepareAsync(); player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { try { mp.start(); seek_bar_view.setMax(player.getDuration()); updatePosition(); } catch (Exception e) { e.printStackTrace(); } } }); player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { stopPlay(); } }); MediaPlayer.OnErrorListener onError = new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp,int what,int extra) { // returning false will call the OnCompletionListener return false; } }; } else { Toast.makeText(getContext(),"Audio Not Found..!",Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getContext(),"Please Check Your Internet Connection..!",Toast.LENGTH_SHORT).show(); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(getContext(),Toast.LENGTH_SHORT).show(); } } catch (Exception e) { e.printStackTrace(); } } }); return rowView; } private void stopPlay() { player.stop(); player.reset(); // playButton.setImageResource(android.R.drawable.ic_media_play); handler.removeCallbacks(updatePositionRunnable); seek_bar_view.setProgress(0); // isStarted = false; } private final Handler handler = new Handler(); private final Runnable updatePositionRunnable = new Runnable() { public void run() { updatePosition(); } }; private void updatePosition() { handler.removeCallbacks(updatePositionRunnable); seek_bar_view.setProgress(progress); progress=getProgressPercentage(player.getCurrentPosition(),player.getDuration(); notifyDataSetChanged(); handler.postDelayed(updatePositionRunnable,UPDATE_FREQUENCY); }
解决方法
你需要在每一秒更新你的seekbar位置(值)..
设置seekbar最大值..
seek_bar_view.setMax((int) player.getDuration());
并每秒更新一次以显示进度
Handler mHandler = new Handler(); runOnUiThread(new Runnable() { @Override public void run() { seek_bar_view.setProgress((int) player.getCurrentPosition()); } mHandler.postDelayed(this,1000); } );