Skip to content

Commit

Permalink
change sample code in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaydeep committed Sep 23, 2014
1 parent b6804b7 commit 04b5649
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
4 changes: 2 additions & 2 deletions AudioWifeDemo/res/layout/awd_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
android:paddingTop="5dp" >

<TextView
android:id="@+id/play_view"
android:id="@+id/run_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
Expand All @@ -93,7 +93,7 @@
android:textSize="11sp" />

<TextView
android:id="@+id/pause_view"
android:id="@+id/total_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
Expand Down
27 changes: 9 additions & 18 deletions AudioWifeDemo/src/nl/changer/audiowifedemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -28,6 +27,8 @@ public class MainActivity extends BaseActivity {
private View mPlayMedia;
private View mPauseMedia;
private SeekBar mMediaSeekBar;
private TextView mRunTime;
private TextView mTotalTime;
private TextView mPlaybackTime;

@Override
Expand All @@ -50,7 +51,8 @@ public void onClick(View v) {
mPlayMedia = findViewById(R.id.play);
mPauseMedia = findViewById(R.id.pause);
mMediaSeekBar = (SeekBar) findViewById(R.id.media_seekbar);
mPlaybackTime = (TextView) findViewById(R.id.playback_time);
mRunTime = (TextView) findViewById(R.id.run_time);
mTotalTime = (TextView) findViewById(R.id.total_time);

mPlayMedia.setOnClickListener(new View.OnClickListener() {

Expand Down Expand Up @@ -80,26 +82,15 @@ protected void onActivityResult(int requestCode, int resuleCode, Intent intent)

mUri = uri;

TextView playTime = (TextView) findViewById(R.id.play_view);
TextView totalTime = (TextView) findViewById(R.id.pause_view);

/*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).setPlaytime(mPlaybackTime);*/

// AudioWife takes care of click handler for play/pause button
// AudioWife takes care of click
// handler for play/pause button
AudioWife.getInstance()
.init(mContext, uri)
.init(mContext, uri)
.setPlayView(mPlayMedia)
.setPauseView(mPauseMedia)
.setSeekBar(mMediaSeekBar)
.setRuntimeView(playTime)
.setTotalTimeView(totalTime);
.setRuntimeView(mRunTime)
.setTotalTimeView(mTotalTime);

AudioWife.getInstance().addOnCompletionListener(new MediaPlayer.OnCompletionListener() {

Expand Down
26 changes: 21 additions & 5 deletions LibAudioWife/src/nl/changer/audiowife/AudioWife.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ public class AudioWife {
private MediaPlayer mMediaPlayer;

private SeekBar mSeekBar;

@Deprecated
/***
* Set both current playack time and total runtime
* of the audio in the UI.
*/
private TextView mPlaybackTime;

private View mPlayButton;
private View mPauseButton;

Expand Down Expand Up @@ -635,8 +642,9 @@ public void onCompletion(MediaPlayer mp) {

private void initMediaSeekBar() {

if (mSeekBar == null)
if (mSeekBar == null) {
return;
}

// update seekbar
long finalTime = mMediaPlayer.getDuration();
Expand All @@ -649,6 +657,10 @@ private void initMediaSeekBar() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mMediaPlayer.seekTo(seekBar.getProgress());

// if the audio is paused and seekbar is moved,
// update the play time in the UI.
updateRuntime(seekBar.getProgress());
}

@Override
Expand Down Expand Up @@ -676,7 +688,9 @@ private void fireCustomCompletionListeners(MediaPlayer mp) {
* This is the simplest way to get AudioWife working for you. If you are using the default
* player provided by this method, calling method {@link AudioWife#setPlayView(View)},
* {@link AudioWife#setPauseView(View)}, {@link AudioWife#setSeekBar(SeekBar)},
* {@link AudioWife#setPlaytime(TextView)} will have no effect. <br/>
* {@link AudioWife#setPlaytime(TextView)} will have no effect.
*
* <br/>
* <br/>
* The default player UI consists of:
*
Expand All @@ -692,11 +706,13 @@ private void fireCustomCompletionListeners(MediaPlayer mp) {
* View to integrate default player UI into.
****/
public AudioWife useDefaultUi(ViewGroup playerContainer, LayoutInflater inflater) {
if (playerContainer == null)
if (playerContainer == null) {
throw new NullPointerException("Player container cannot be null");
}

if (inflater == null)
throw new NullPointerException("Inflater cannot be null");
if (inflater == null) {
throw new IllegalArgumentException("Inflater cannot be null");
}

View playerUi = inflater.inflate(R.layout.aw_player, playerContainer);

Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,20 @@ You can initialize the custom player controls of your UI using AudioWife
```java

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

// initialize AudioWife
AudioWife.getInstance()
.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)
.setPlaytime(mPlaybackTime);
mPlayMedia = findViewById(R.id.play);
mPauseMedia = findViewById(R.id.pause);
mMediaSeekBar = (SeekBar) findViewById(R.id.media_seekbar);
mRunTime = (TextView) findViewById(R.id.run_time);
mTotalTime = (TextView) findViewById(R.id.total_time);

// AudioWife takes care of click handler for play/pause button
AudioWife.getInstance()
.init(mContext, uri)
.setPlayView(mPlayMedia)
.setPauseView(mPauseMedia)
.setSeekBar(mMediaSeekBar)
.setRuntimeView(mRunTime)
.setTotalTimeView(mTotalTime);

// to explicitly pause
AudioWife.getInstance().pause();
Expand Down

0 comments on commit 04b5649

Please sign in to comment.