-
Notifications
You must be signed in to change notification settings - Fork 78
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
Jaydeep
committed
May 4, 2014
1 parent
e5f5167
commit cfb4be6
Showing
5 changed files
with
146 additions
and
67 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
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
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
108 changes: 87 additions & 21 deletions
108
AudioWifeDemo/src/nl/changer/audiowifedemo/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 | 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(); | ||
} | ||
} |
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