diff --git a/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java b/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java index b5669c9..f584234 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java @@ -5,13 +5,19 @@ import androidx.fragment.app.Fragment; import android.content.Intent; +import android.media.MediaPlayer; +import android.media.MediaRecorder; import android.os.Bundle; +import android.os.Environment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageView; +import android.widget.SeekBar; +import android.widget.TextView; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; @@ -23,9 +29,22 @@ import org.ntlab.amaryllis.client.R; import org.ntlab.amaryllis.client.VoiceActivity; +import java.io.File; + public class MapsFragment extends Fragment { - Button rokuButton; + + private MediaRecorder mr; + private MediaPlayer mp; + private int totalTime; + private SeekBar positionBar; + private TextView elapsedTimeLabel; + private TextView remainingTimeLabel; + private int StartChange = 1; + File file; + static final String filePath = Environment.getExternalStorageDirectory() + "/sample.mp4"; + Button RecordButton; + Button PlaybackButton; private OnMapReadyCallback callback = new OnMapReadyCallback() { @@ -55,17 +74,30 @@ } + //ここにボタンを押した時の処理を書いていきます。 @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + //file = new File(getFilesDir(),"Sample.3gp"); + mp = new MediaPlayer(); - rokuButton = (Button)view.findViewById(R.id.button); - rokuButton.setOnClickListener(new View.OnClickListener() { + RecordButton = (Button)view.findViewById(R.id.button); + RecordButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - Intent intent = new Intent(getActivity(), VoiceActivity.class); - startActivity(intent); + //Intent intent = new Intent(getActivity(), VoiceActivity.class); + //startActivity(intent); + startRecord(); } }); + + PlaybackButton = (Button)view.findViewById(R.id.button2); + PlaybackButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + startPlay(); + } + }); + + SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); if (mapFragment != null) { @@ -96,7 +128,135 @@ } + //録音開始&録音終了 + private void startRecord(){ + File wavFile = new File(filePath); + if(StartChange == 0) { + try { + TextView textView1 = (TextView)getView().findViewById(R.id.Notice); + textView1.setText("Record End!"); + mr.stop(); + mr.reset(); + mr.release(); + StartChange = 1; + } catch (Exception e) { + e.printStackTrace(); + } + }else { + try { + TextView textView1 = (TextView)getView().findViewById(R.id.Notice); + textView1.setText("Record Start!"); + mr = new MediaRecorder(); + mr.setAudioSource(MediaRecorder.AudioSource.MIC); + mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + //mr.setOutputFile(file.getAbsolutePath()); + mr.setOutputFile(filePath); + mr.prepare(); + mr.start(); + StartChange = 0; + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + + //再生開始&再生中止 + //次は再生が終わった時の処理を書いていく事。 + private void startPlay(){ + ImageView Stoping = getView().findViewById(R.id.Stoping); + ImageView Playing = getView().findViewById(R.id.Playing); + float Tmin = 0; + float Tmax = 255; + //mp = new MediaPlayer(); + //mp = MediaPlayer.create(this,R.raw.bgm); + + if(mp.isPlaying()){ + TextView textView1 = (TextView)getView().findViewById(R.id.Notice); + textView1.setText("Playback Stop!"); + mp.stop();//再生を中断 + //mp.pause();//途中から再生を再開したい時はこっちを使う必要があるかも + + + Stoping.setAlpha(1.0f);//画像が見えるようにする処理 + Playing.setAlpha(0.0f);//画像が見えないようにする処理 + + + //try{ + //mp.prepare(); + //}catch(IllegalStateException e){ + //e.printStackTrace(); + //}catch(IOException e){ + //e.printStackTrace(); + //} + }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(); + + //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){ + + //} + //} + //); + + //} + + //mp.start(); + + + } catch (Exception e) { + e.printStackTrace(); + } + TextView textView1 = (TextView)getView().findViewById(R.id.Notice); + textView1.setText("Playback Start!"); + mp.seekTo(0); + mp.start();//再生スタート + Playing.setAlpha(1.0f); + Stoping.setAlpha(0.0f); + } + totalTime = mp.getDuration(); + String S_totalTime = createTimeLabel(totalTime);//createTimeLabelにtotalTimeを渡す。 + TextView voiceTime = (TextView)getView().findViewById(R.id.VoiceTime); + voiceTime.setText(S_totalTime); + } + + //totalTimeを分、秒に変換 + public String createTimeLabel(int time){ + String timeLabel = ""; + int min = time/1000/60; + int sec = time/1000%60; + + timeLabel = min + ":"; + if(sec < 10) timeLabel += "0"; + timeLabel += sec; + return timeLabel; + } } \ No newline at end of file