@@ -23,7 +23,8 @@ public class AudioPreviewActivity extends AppCompatActivity {
2323
2424
2525 @ Override
26- protected void onCreate (@ Nullable Bundle savedInstanceState ) {
26+ protected void onCreate (@ Nullable Bundle savedInstanceState )
27+ {
2728 super .onCreate (savedInstanceState );
2829 setContentView (R .layout .activity_audio_preview );
2930 ActionBar actionBar = getSupportActionBar ();
@@ -39,31 +40,37 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3940 }
4041
4142 @ Override
42- protected void onResume () {
43+ protected void onResume ()
44+ {
4345 super .onResume ();
4446 initAudio ();
4547 }
4648
4749 @ Override
48- public boolean onOptionsItemSelected (MenuItem item ) {
50+ public boolean onOptionsItemSelected (MenuItem item )
51+ {
4952 // handle arrow click here
50- if (item .getItemId () == android .R .id .home ) {
53+ if (item .getItemId () == android .R .id .home )
54+ {
5155 finish (); // close this activity and return to preview activity (if there is any)
5256 }
5357
5458 return super .onOptionsItemSelected (item );
5559 }
5660 @ Override
57- protected void onPause () {
61+ protected void onPause ()
62+ {
5863 super .onPause ();
59- if (mMediaPlayer != null ) {
64+ if (mMediaPlayer != null )
65+ {
6066 mVisualizer .release ();
6167 mMediaPlayer .release ();
6268 mMediaPlayer = null ;
6369 }
6470 }
6571
66- private void initAudio () {
72+ private void initAudio ()
73+ {
6774 setVolumeControlStream (AudioManager .STREAM_MUSIC );
6875 String filePath = getIntent ().getStringExtra (FILEPATH );
6976 TextView tvInstruction =(TextView ) findViewById (R .id .tvInstruction );
@@ -81,29 +88,35 @@ private void initAudio() {
8188 // non-Visualizer related code
8289 // in this callback.
8390 mMediaPlayer
84- .setOnCompletionListener (new MediaPlayer .OnCompletionListener () {
85- public void onCompletion (MediaPlayer mediaPlayer ) {
91+ .setOnCompletionListener (new MediaPlayer .OnCompletionListener ()
92+ {
93+ public void onCompletion (MediaPlayer mediaPlayer )
94+ {
8695 mVisualizer .setEnabled (false );
8796 }
8897 });
8998 mMediaPlayer .start ();
9099 mMediaPlayer .setLooping (true );
91100
92101 }
93- private void setupVisualizerFxAndUI () {
102+ private void setupVisualizerFxAndUI ()
103+ {
94104
95105 // Create the Visualizer object and attach it to our media player.
96106 mVisualizer = new Visualizer (mMediaPlayer .getAudioSessionId ());
97107 mVisualizer .setCaptureSize (Visualizer .getCaptureSizeRange ()[1 ]);
98108 mVisualizer .setDataCaptureListener (
99- new Visualizer .OnDataCaptureListener () {
109+ new Visualizer .OnDataCaptureListener ()
110+ {
100111 public void onWaveFormDataCapture (Visualizer visualizer ,
101- byte [] bytes , int samplingRate ) {
112+ byte [] bytes , int samplingRate )
113+ {
102114 mVisualizerView .updateVisualizer (bytes );
103115 }
104116
105117 public void onFftDataCapture (Visualizer visualizer ,
106- byte [] bytes , int samplingRate ) {
118+ byte [] bytes , int samplingRate )
119+ {
107120 }
108121 }, Visualizer .getMaxCaptureRate () / 2 , true , false );
109122 }
0 commit comments