diff --git a/app/src/main/java/org/ntlab/amaryllis/client/VoiceTest.java b/app/src/main/java/org/ntlab/amaryllis/client/VoiceTest.java index d4acdfe..e253d89 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/VoiceTest.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/VoiceTest.java @@ -35,49 +35,59 @@ //再生 private void startPlay(){ - mp = new MediaPlayer(); + //mp = new MediaPlayer(); StartChange = 1; //mp = MediaPlayer.create(this,R.raw.bgm); - try { - //mp = new MediaPlayer(); - mp.setDataSource(file.getAbsolutePath()); - //OutputStream filePath = openFileOutput("a",MODE_PRIVATE); - //mp.setDataSource(filePath); - mp.prepare(); - mp.setLooping(false); + + if(mp.isPlaying()){ + mp.stop(); + }else { + try { + //mp = new MediaPlayer(); + mp.setDataSource(file.getAbsolutePath()); + //OutputStream filePath = openFileOutput("a",MODE_PRIVATE); + //mp.setDataSource(filePath); + mp.prepare(); + }catch(IllegalStateException e){ + e.printStackTrace(); + //mp.setLooping(false); + //mp.seekTo(0); + //if(StartChange == 1){ + //positionBar = findViewById(R.id.positionBar); + //positionBar.setMax(totalTime); + //positionBar.setOnSeekBarChangeListener( + //new SeekBar.OnSeekBarChangeListener(){ + //public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser){ + //if(fromUser){ + //mp.seekTo(progress); + //positionBar.setProgress(progress); + //} + //} + + //public void onStartTrackingTouch(SeekBar seekBar){ + + //} + + //public void onStopTrackingTouch(SeekBar seekBar){ + + //} + //} + //); + //totalTime = mp.getDuration(); + //String S_totalTime = createTimeLabel(totalTime);//createTimeLabelにtotalTimeを渡す。 + //TextView voiceTime = (TextView)findViewById(R.id.voiceTime); + //voiceTime.setText(S_totalTime); + + //} + + //mp.start(); + + + } catch (Exception e) { + e.printStackTrace(); + } mp.seekTo(0); - //if(StartChange == 1){ - positionBar = findViewById(R.id.positionBar); - positionBar.setMax(totalTime); - positionBar.setOnSeekBarChangeListener( - new SeekBar.OnSeekBarChangeListener(){ - public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser){ - if(fromUser){ - mp.seekTo(progress); - positionBar.setProgress(progress); - } - } - - public void onStartTrackingTouch(SeekBar seekBar){ - - } - - public void onStopTrackingTouch(SeekBar seekBar){ - - } - } - ); - totalTime = mp.getDuration(); - String S_totalTime = createTimeLabel(totalTime);//createTimeLabelにtotalTimeを渡す。 - TextView voiceTime = (TextView)findViewById(R.id.voiceTime); - voiceTime.setText(S_totalTime); - //voiceTime.setText("S_totalTime"); - - //} - mp.start(); - }catch(Exception e){ - e.printStackTrace(); } } @@ -141,6 +151,7 @@ super.onCreate(savedInstanceState); setContentView(R.layout.activity_voice_test); file = new File(getFilesDir(),"Sample.3gp"); + mp = new MediaPlayer();