Skip to content

Commit

Permalink
update docs with sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaydeep committed May 30, 2014
1 parent 662cd12 commit dae08ef
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import nl.changer.audiowife.AudioWife;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
Expand All @@ -20,6 +21,7 @@ public class DefaultPlayerActivity extends FragmentActivity {

private static final int INTENT_PICK_AUDIO = 1;

private Context mContext;
private ViewGroup mPlayerContainer;

private Uri mUri;
Expand All @@ -28,7 +30,8 @@ public class DefaultPlayerActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.default_player);

mContext = DefaultPlayerActivity.this;

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

pickAudio.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -62,7 +65,7 @@ protected void onActivityResult(int requestCode, int resuleCode,

mUri = uri;

AudioWife.getInstance().init(DefaultPlayerActivity.this, uri)
AudioWife.getInstance().init(mContext, uri)
.useDefaultUi(mPlayerContainer, getLayoutInflater());

AudioWife.getInstance().addOnCompletionListener( new MediaPlayer.OnCompletionListener() {
Expand Down
10 changes: 7 additions & 3 deletions AudioWifeDemo/src/nl/changer/audiowifedemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import nl.changer.audiowife.AudioWife;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
Expand All @@ -18,6 +19,8 @@ public class MainActivity extends FragmentActivity {
private static final String TAG = MainActivity.class.getSimpleName();

private static final int INTENT_PICK_AUDIO = 1;

private Context mContext;

private View mPlayMedia;
private View mPauseMedia;
Expand All @@ -30,7 +33,8 @@ public class MainActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mContext = MainActivity.this;

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

pickAudio.setOnClickListener(new View.OnClickListener() {
Expand All @@ -53,7 +57,7 @@ public void onClick(View v) {
public void onClick(View v) {

if (mUri == null)
Toast.makeText(MainActivity.this,
Toast.makeText(mContext,
"Pick an audio file before playing",
Toast.LENGTH_LONG).show();
}
Expand All @@ -78,7 +82,7 @@ protected void onActivityResult(int requestCode, int resuleCode,

mUri = uri;

AudioWife.getInstance().init(MainActivity.this, uri)
AudioWife.getInstance().init(mContext, uri)
.setPlayView(mPlayMedia) // AudioWife takes care of click handler for play button
.setPauseView(mPauseMedia) // AudioWife takes care of click handler for pause button
.setSeekBar(mMediaSeekBar)
Expand Down
2 changes: 2 additions & 0 deletions LibAudioWife/src/nl/changer/audiowife/AudioWife.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ public AudioWife useDefaultUi(ViewGroup playerContainer, LayoutInflater inflater
TextView playbackTime = (TextView) playerUi.findViewById(R.id.playback_time);
setPlaytime(playbackTime);

// this has to be set after all the views
// have finished initializing.
mHasDefaultUi = true;
return this;
}
Expand Down
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Why this project?
Features
=========
1. Provides default UI truly making it an embeddable player.
2. Ability to set multiple custom click handlers to play and pause buttons.
2. Ability to set multiple custom click handlers to play and pause buttons.


Including in your project
Expand All @@ -62,6 +62,29 @@ This project has NO DEPENDENCIES.

Getting started
====================

Permission required to play audio

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


##Using default player UI

AudioWife comes with a simple default player UI that you can use right away.

```java

AudioWife.getInstance().init(mContext, uri)
.useDefaultUi(mPlayerContainer, getLayoutInflater());

```

##Using custom player UI

You can initialize the custom player controls of your UI using AudioWife

```java

// initialize the player controls
Expand All @@ -72,7 +95,7 @@ mPlaybackTime = (TextView) findViewById(R.id.playback_time);

// initialize AudioWife
AudioWife.getInstance()
.init(MainActivity.this, uri)
.init(mContext, uri)
.setPlayView(mPlayMedia) // AudioWife takes care of click handler for play view
.setPauseView(mPauseMedia) // AudioWife takes care of click handler for pause view
.setSeekBar(mMediaSeekBar)
Expand All @@ -87,12 +110,6 @@ AudioWife.getInstance().release();

```

Permission required to play audio

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

##Add custom listeners

To extend the capabilities of AudioWife, custom click listeners can be attached.
Expand Down

0 comments on commit dae08ef

Please sign in to comment.