2017-02-10 4 views
0

を働いていないバーを求めます。シークバーをクリックすると前方に進みますが、1秒後に前の位置に戻ります。のAndroidメディアプレーヤー私はコールレコーダーアプリケーションを作成すると、オーディオファイルを再生しようと使用しています]ダイアログでバーメディアプレーヤーを求めるが、私はそれに</p> <p>をクリックしたときにバーが動作しません求めて使用しています

@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; 

} 

答えて

1

ここで、media.seekTo(position)を呼び出しましたか?私が見る限り、あなたはあなたの探検隊員にそのことを呼ばなかった。

そして、あなたは常にあなたの曲の進行にシークバーの相対位置を設定しているよう...それは常に戻って以前の状態に戻ります。..

ソリューション: あなたseekbarchangelistenerで...(メディアonSeekbarchangedを使用し、使用プレイヤー).seekTo(位置)

+1

はいを​​解決しますが、私はseekbarchangelistener NADを使用します。ここで、私は理解didnot使用する方法を私に説明弟 – Ahmad

+1

audioPlayDialogSeekBar.setOnSeekBarChangeListener(新SeekBar.OnSeekBarChangeListener(){onProgressChanged @Override 公共ボイド(シークバーシークバー、int型の進行状況、ブールFROMUSER){ Log.dは( "進行は変更さ"、)+進捗状況を "進行状況が変わっ"; audioPlayDialogSeekBar.setMax((int)finalTime); } 私はこのリスナーの声で...(mediaPlayer).seekTo(progress);を使用してこの – Ahmad

+1

を使用しています。 – Ahmad

1
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); 

        } 

私はこのコードを使用し、問題が

関連する問題

 関連する問題