0

私の Android アプリケーションでは、URL をストリーミングして再生したいと考えています。再生ボタンがクリックされたときにプログレスバーを表示してから、一時停止ボタンを表示したい。Mediaplayer での再生中に遅延があるため、そこで何かが起こっていることをユーザーに示すため、Progressbar を使用しました。一時停止ボタンへ。ユーザーがペイリーボタンをクリックしたときにプログレスバーを表示するにはどうすればよいですか。コードを以下に示します

      holder.videoPlayVoiceBtn.setOnClickListener(new OnClickListener() {

                public void onClick(final View v) {
                    // videoInfo element = (videoInfo) videos.get(position);
                    // element.setPlayButton((Button) v);
                    // element.setPlaying(true);


                    LinearLayout relativeLayout = (LinearLayout) v.getParent();
                    RelativeLayout layout = (RelativeLayout) relativeLayout
                            .getParent();
                    final ProgressBar bar = (ProgressBar) layout
                            .findViewById(R.id.progressBarVoice);
                    bar.setVisibility(View.VISIBLE);
                     SeekBar mSeekBar = (SeekBar) relativeLayout
                            .findViewWithTag(position);
                     final SeekBar SeekBar = mSeekBar;


                    final Button playBtn = (Button) relativeLayout
                            .findViewWithTag(position + "b");



                        if (Utilities.message_player != null) {



                            if (Utilities.message_player.isPlaying()) {
                                bar.setVisibility(View.GONE);
                                Utilities.message_player.pause();
                                holder.username.setKeepScreenOn(false);
                                videos.get(position).setCurrentDuration(
                                        Utilities.message_player
                                                .getCurrentPosition());
                                playBtn.setBackgroundResource(R.drawable.play_button_style);
                                pause_check = true;


                            } else if (!Utilities.message_player.isPlaying()) {
                                bar.setVisibility(View.VISIBLE);
                                playBtn.setVisibility(View.GONE);

                                Utilities.message_player.seekTo(videos.get(
                                        position).getCurrentDuration());
                                playBtnPrev
                                        .setBackgroundResource(R.drawable.pause_btn_style);

//                              
                                        playVoice(videos.get(position)
                                                .getVoice_URL(),
                                                videos.get(position)
                                                        .getDuration(),
                                                        SeekBar, duration, playBtn,
                                                position, v, 0, bar);
//                              
                                Utilities.message_player.start();

                                pause_check = true;

                            } else {
                                bar.setVisibility(View.GONE);
                                playBtn.setVisibility(View.VISIBLE);
                                Utilities.message_player.stop();
                                holder.username.setKeepScreenOn(false);
                                // Utilities.message_player.reset();
                                Utilities.message_player = new MediaPlayer();
                                pause_check = false;
                            }

                            playBtnPrev
                                    .setBackgroundResource(R.drawable.play_button_style);

                            isPlayCheck = true;
                        } else {
                            // bar.setVisibility(View.VISIBLE);
                            // playBtn.setVisibility(View.GONE);
                            playBtnPrev
                                    .setBackgroundResource(R.drawable.pause_btn_style);
                            isPlayCheck = false;
                        }
                    }

                    if (pause_check == true) {

                    } else {
                        dummy_voice_button = playBtn;
                        bar.setVisibility(View.VISIBLE);
                        playBtn.setVisibility(View.GONE);
                        if (Utilities.message_player == null)
                            Utilities.message_player = new MediaPlayer();

                                playVoice(videos.get(position).getVoice_URL(),
                                        videos.get(position).getDuration(),
                                        SeekBar, duration, playBtn, position,
                                        v, 1, bar);

                        prevPosition = position;

                    }
                }
            });




   private void playVoice(String url, final int voiceduration,
            final SeekBar mSeekBar, final TextView durationtv,
            final Button playBtn, final int posToPlay, final View view,
            int valInt, final ProgressBar bar) {

        if (Utilities.message_player != null) {
            Utilities.message_player
                    .setOnCompletionListener(new OnCompletionListener() {

                        public void onCompletion(MediaPlayer mp) {
                            Log.e("Play voice", "setOnCompletionListener");

                            if (play_task != null) {
                                prevPosition = -1;
                                playBtn.setBackgroundResource(R.drawable.profile_play_button_style);
                                durationtv.setText(""
                                        + videos.get(posToPlay).getDuration());
                                LinearLayout relativeLayout = (LinearLayout) view
                                        .getParent();
                                if (((SeekBar) relativeLayout
                                        .findViewWithTag(posToPlay)) != null)
                                    ((SeekBar) relativeLayout
                                            .findViewWithTag(posToPlay))
                                            .setProgress(0);

                            }



                        }
                    });
            Utilities.message_player
                    .setOnPreparedListener(new OnPreparedListener() {

                        public void onPrepared(MediaPlayer mp) {
                            playBtn.setVisibility(View.VISIBLE);
                            playBtn.setBackgroundResource(R.drawable.pause_btn_style);
                            bar.setVisibility(View.GONE);

                        }
                    });


                try {
                    Log.e("Play voice", "message_player.isnotPlaying()");
                    Utilities.message_player.reset();
                    Utilities.message_player.setDataSource(url);
                    Utilities.message_player.prepare();

                    Utilities.message_player.start();
                    holder.username.setKeepScreenOn(true);
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            }
        }
    }
4

0 に答える 0