Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e173e6f
commit 1a0411a
Showing
20 changed files
with
239 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,12 @@ | |||
apply plugin: 'com.android.application' | apply plugin: 'com.android.application' | ||
|
|
||
android { | android { | ||
compileSdkVersion 19 | compileSdkVersion 24 | ||
buildToolsVersion "21.1.2" | buildToolsVersion "24.0.1" | ||
|
|||
defaultConfig { | |||
minSdkVersion 15 | |||
targetSdkVersion 24 | |||
vectorDrawables.generatedDensities = ['hdpi','xxhdpi'] | |||
} | |||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 0 additions & 137 deletions
137
Media/Audio/app/src/main/java/com/commonsware/android/audio/AudioDemo.java
This file was deleted.
Oops, something went wrong.
138 changes: 138 additions & 0 deletions
138
Media/Audio/app/src/main/java/com/commonsware/android/audio/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,138 @@ | |||
/*** | |||
* Copyright (c) 2008-2016 CommonsWare, LLC | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you | |||
* may not | |||
* use this file except in compliance with the License. You may | |||
* obtain | |||
* a copy | |||
* of the License at http://www.apache.org/licenses/LICENSE-2.0. | |||
* Unless required | |||
* by applicable law or agreed to in writing, software distributed | |||
* under the | |||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
* CONDITIONS | |||
* OF ANY KIND, either express or implied. See the License for the | |||
* specific | |||
* language governing permissions and limitations under the License. | |||
* <p/> | |||
* From _The Busy Coder's Guide to Android Development_ | |||
* https://commonsware.com/Android | |||
*/ | |||
|
|||
package com.commonsware.android.audio; | |||
|
|||
import android.app.Activity; | |||
import android.media.MediaPlayer; | |||
import android.os.Bundle; | |||
import android.util.Log; | |||
import android.view.Menu; | |||
import android.view.MenuItem; | |||
import android.widget.Toast; | |||
|
|||
public class MainActivity extends Activity | |||
implements MediaPlayer.OnCompletionListener { | |||
private MenuItem play; | |||
private MenuItem pause; | |||
private MenuItem stop; | |||
private MediaPlayer mp; | |||
|
|||
@Override | |||
public void onCreate(Bundle icicle) { | |||
super.onCreate(icicle); | |||
|
|||
try { | |||
mp=MediaPlayer.create(this, R.raw.clip); | |||
mp.setOnCompletionListener(this); | |||
} | |||
catch (Exception e) { | |||
goBlooey(e); | |||
} | |||
} | |||
|
|||
@Override | |||
public void onDestroy() { | |||
super.onDestroy(); | |||
|
|||
if (mp.isPlaying()) { | |||
mp.stop(); | |||
} | |||
} | |||
|
|||
@Override | |||
public boolean onCreateOptionsMenu(Menu menu) { | |||
getMenuInflater().inflate(R.menu.actions, menu); | |||
play=menu.findItem(R.id.play); | |||
pause=menu.findItem(R.id.pause); | |||
stop=menu.findItem(R.id.stop); | |||
|
|||
return(super.onCreateOptionsMenu(menu)); | |||
} | |||
|
|||
@Override | |||
public boolean onOptionsItemSelected(MenuItem item) { | |||
switch (item.getItemId()) { | |||
case R.id.play: | |||
play(); | |||
return (true); | |||
|
|||
case R.id.pause: | |||
pause(); | |||
return (true); | |||
|
|||
case R.id.stop: | |||
stop(); | |||
return (true); | |||
} | |||
|
|||
return(super.onOptionsItemSelected(item)); | |||
} | |||
|
|||
public void onCompletion(MediaPlayer mp) { | |||
stop(); | |||
} | |||
|
|||
private void play() { | |||
mp.start(); | |||
|
|||
play.setVisible(false); | |||
pause.setVisible(true); | |||
stop.setVisible(true); | |||
} | |||
|
|||
private void stop() { | |||
mp.stop(); | |||
pause.setVisible(false); | |||
stop.setVisible(false); | |||
|
|||
findViewById(android.R.id.content).postDelayed(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
mp.prepare(); | |||
mp.seekTo(0); | |||
play.setVisible(true); | |||
} | |||
catch (Exception e) { | |||
goBlooey(e); | |||
} | |||
} | |||
}, 100); | |||
} | |||
|
|||
private void pause() { | |||
mp.pause(); | |||
|
|||
play.setVisible(true); | |||
pause.setVisible(false); | |||
stop.setVisible(true); | |||
} | |||
|
|||
private void goBlooey(Exception e) { | |||
Log.e(getClass().getSimpleName(), getString(R.string.msg_error), | |||
e); | |||
Toast | |||
.makeText(this, R.string.msg_error_toast, Toast.LENGTH_LONG) | |||
.show(); | |||
} | |||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:width="24dp" | |||
android:height="24dp" | |||
android:viewportWidth="24.0" | |||
android:viewportHeight="24.0"> | |||
<path | |||
android:fillColor="#FFFFFFFF" | |||
android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z"/> | |||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:width="24dp" | |||
android:height="24dp" | |||
android:viewportWidth="24.0" | |||
android:viewportHeight="24.0"> | |||
<path | |||
android:fillColor="#FFFFFFFF" | |||
android:pathData="M8,5v14l11,-7z"/> | |||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:width="24dp" | |||
android:height="24dp" | |||
android:viewportWidth="24.0" | |||
android:viewportHeight="24.0"> | |||
<path | |||
android:fillColor="#FFFFFFFF" | |||
android:pathData="M6,6h12v12H6z"/> | |||
</vector> |
Oops, something went wrong.