Skip to content

Commit

Permalink
refreshed sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsguy committed Aug 21, 2016
1 parent e173e6f commit 1a0411a
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 222 deletions.
10 changes: 8 additions & 2 deletions Media/Audio/app/build.gradle
@@ -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']
}
} }
25 changes: 17 additions & 8 deletions Media/Audio/app/src/main/AndroidManifest.xml
@@ -1,13 +1,22 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.commonsware.android.audio" android:versionCode="1" android:versionName="1.0"> <manifest package="com.commonsware.android.audio"

xmlns:android="http://schemas.android.com/apk/res/android"
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="6"/> android:versionCode="1"
<supports-screens android:largeScreens="false" android:normalScreens="true" android:smallScreens="false"/> android:versionName="1.0">
<application android:icon="@drawable/cw">
<activity android:label="AudioDemo" android:name=".AudioDemo"> <supports-screens
android:largeScreens="false"
android:normalScreens="true"
android:smallScreens="false" />
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Apptheme">
<activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
Expand Down

This file was deleted.

@@ -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 removed Media/Audio/app/src/main/res/drawable-mdpi/cw.png
Binary file not shown.
9 changes: 9 additions & 0 deletions Media/Audio/app/src/main/res/drawable/ic_pause.xml
@@ -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>
9 changes: 9 additions & 0 deletions Media/Audio/app/src/main/res/drawable/ic_play_arrow.xml
@@ -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>
9 changes: 9 additions & 0 deletions Media/Audio/app/src/main/res/drawable/ic_stop.xml
@@ -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>

0 comments on commit 1a0411a

Please sign in to comment.