Skip to content

Commit

Permalink
demo completes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaydeep committed May 4, 2014
1 parent e5f5167 commit cfb4be6
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 67 deletions.
4 changes: 3 additions & 1 deletion AudioWifeDemo/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
android:minSdkVersion="11"
android:targetSdkVersion="14" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
Expand All @@ -24,4 +26,4 @@
</activity>
</application>

</manifest>
</manifest>
2 changes: 1 addition & 1 deletion AudioWifeDemo/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

# Project target.
target=android-14
android.library.reference.1=../appcompat_v7
android.library.reference.1=../LibAudioWife
92 changes: 48 additions & 44 deletions AudioWifeDemo/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,68 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
tools:context="nl.changer.audiowifedemo.MainActivity"
tools:ignore="MergeRootFrame" >

<LinearLayout
android:id="@+id/player_layout"
android:layout_width="match_parent"
android:layout_height="58dp"
android:orientation="horizontal" >
android:layout_height="50dp "
android:background="@drawable/gray_border_wo_padding"
android:gravity="center_vertical"
android:paddingLeft="4dp" >

<LinearLayout
<ImageView
android:id="@+id/play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:src="@android:drawable/ic_media_play" />

<ImageView
android:id="@+id/pause"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:src="@android:drawable/ic_media_pause"
android:visibility="gone" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="@drawable/gray_border_wo_padding"
android:gravity="center_vertical"
android:paddingLeft="4dp" >
android:layout_weight="0.8"
android:paddingBottom="5dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >

<ImageView
android:id="@+id/play"
<SeekBar
android:id="@+id/mediaSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:src="@android:drawable/ic_media_play" />
android:layout_gravity="center_vertical"
android:thumb="@drawable/black_ball" />

<ImageView
android:id="@+id/pause"
android:layout_width="match_parent"
<TextView
android:id="@+id/playback_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6"
android:src="@android:drawable/ic_media_pause"
android:visibility="gone" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:paddingBottom="5dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >

<SeekBar
android:id="@+id/mediaSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:thumb="@drawable/black_ball" />

<TextView
android:id="@+id/playback_time"
android:textColor="@android:color/darker_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:ellipsize="end"
android:inputType="text"
android:textSize="11sp" />
</FrameLayout>
</LinearLayout>
android:layout_gravity="right|top"
android:ellipsize="end"
android:inputType="text"
android:textColor="@android:color/darker_gray"
android:textSize="11sp" />
</FrameLayout>
</LinearLayout>

<Button
android:id="@+id/pickAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:text="Pick Audio" />

</LinearLayout>
108 changes: 87 additions & 21 deletions AudioWifeDemo/src/nl/changer/audiowifedemo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,109 @@
package nl.changer.audiowifedemo;

import nl.changer.audiowife.AudioWife;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {



private static final String TAG = MainActivity.class.getSimpleName();

private static final int INTENT_PICK_AUDIO = 1;

private View mPlayMedia;
private View mPauseMedia;
private SeekBar mMediaSeekBar;
private TextView mPlaybackTime;

private Uri mUri;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


View pickAudio = findViewById(R.id.pickAudio);

pickAudio.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
pickAudio();
}
});

// initialize the player contols
mPlayMedia = findViewById(R.id.play);
mPauseMedia = findViewById(R.id.pause);
mMediaSeekBar = (SeekBar) findViewById(R.id.mediaSeekBar);
mPlaybackTime = (TextView) findViewById(R.id.playback_time);

mPlayMedia.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

try {
AudioWife.getInstance().play();
} catch (IllegalStateException e) {
Toast.makeText(MainActivity.this,
"Pick an audio file before playing",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}

}
});

mPauseMedia.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
AudioWife.getInstance().pause();
}
});
}

private void pickAudio() {
Intent mediaChooser = new Intent(Intent.ACTION_GET_CONTENT);
// comma-separated MIME types
mediaChooser.setType("audio/*");
startActivityForResult(mediaChooser, INTENT_PICK_AUDIO);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
protected void onActivityResult(int requestCode, int resuleCode,
Intent intent) {
super.onActivityResult(requestCode, resuleCode, intent);

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
if (resuleCode == Activity.RESULT_OK) {
if (requestCode == INTENT_PICK_AUDIO) {
Uri uri = intent.getData();

AudioWife.getInstance().init(MainActivity.this, uri)
.setPlayView(mPlayMedia).setPauseView(mPauseMedia)
.setSeekBar(mMediaSeekBar).setPlaytime(mPlaybackTime)
.play();
}
} else {
Log.w(TAG, "Audio file not picked up");
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
protected void onPause() {
super.onPause();

// when done playing, release the resources
AudioWife.getInstance().release();
}
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ AudioWife.getInstance()
// to pause
AudioWife.getInstance().pause();


// when done playing, release the resources
AudioWife.getInstance().release();

```

Permission required to play audio

```xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
```

Why the name 'AudioWife'?
=========================
This relates with yet another Android AudioRecorder library project that is coming soon.
Expand Down

0 comments on commit cfb4be6

Please sign in to comment.