How Can I stop mp3 player on menu - android

I create an items on menu to play mp3. But It couldnt stop. How could I stop mediaplayer when I click "stop" button. I want that clicking stop button must be stopp all playing mp3 on menu.
thanks...
public class DetailActivity extends AppCompatActivity {
Toolbar mToolbar;
ImageView mFlower;
TextView mDescription,mBaslik;
Button fab;
MediaPlayer mediaPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mToolbar = findViewById(R.id.toolbar);
mToolbar.setTitle(getResources().getString(R.string.app_name));
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("MP3 --->");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.fon2);
mediaPlayer.start();
}
if (id == R.id.stop) {
mediaPlayer.stop();
mediaPlayer.release();
// mediaPlayer.onDestroy();
}
if (id == R.id.fav) {
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.fon2);
mediaPlayer.start();
}
if (id == R.id.yor) {
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.fon3);
mediaPlayer.start();
}
if (id == R.id.asd) {
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.fon1);
mediaPlayer.start();
}
return super.onOptionsItemSelected(item);
}
}

MediaPlayer mp;
AssetFileDescriptor descriptor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout./////Your activity layout////);
if(mp != null){
if(mp.isPlaying()){
mp.stop();
}
}
try {
descriptor = getAssets().openFd("////the name of your song.mp3////"); // song should be in assets folder
} catch (IOException e) {
e.printStackTrace();
}
audioPlayer();
}
public void audioPlayer() {
//set up MediaPlayer
mp = new MediaPlayer();
try {
mp.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
descriptor.close();
mp.prepare();
} catch (Exception e) {
e.printStackTrace();
}
}
public void OnPlayPressed(View view){
if(mp.isPlaying()){
mp.pause();
}else{
mp.start();
}
}
public void OnStopPressed(View view){
mp.stop();
try {
descriptor = getAssets().openFd("////the name of your song.mp3////"); // song should be in assets folder
} catch (IOException e) {
e.printStackTrace();
}
audioPlayer();
}
Create 2 buttons, 1 for start/pause and one for stop. "OnPlayPressed" is the listener for the first button and "OnStopPressed" is the listener for the second button.
Feel free to mess with this code as long as you get the logic behind it.
Edit: In onStopPressed i reinitialise the descriptor so that you could once again press the "play" button and play your song again. This is not necessary though. You could just write "mp.stop();".

You have to declare the MediaPlayer object outside the method like this
MediaPlayer mediaplayer;
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.foni) {
//MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.fon2);
mediaPlayer = MediaPlayer.create(this, R.raw.fon2);
mediaPlayer.start();
}
if (id == R.id.stop) {
//MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.stop();
}
if (id == R.id.fonb) {
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.fon1);
mediaPlayer.start();
}
if (id == R.id.fonu) {
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.fon3);
mediaPlayer.start();
}
return super.onOptionsItemSelected(item);
}

Related

android set seekbar to initial and toggle play button to pause when music finish

i am designing a mediaplayer from scratch so what i am getting stuck in is that when the song finish to play i want to set seekbar to initial value
i know this can be done with
seekBar.setProgress(0)
but this don't work with me and i want the play button to switch back to pause button and if the user play song again than the song will be played normally
here is my code of media player and hope you tell me what is the logic and how to place it
public class MusicPlayerActivity extends AppCompatActivity implements Runnable,
SeekBar.OnSeekBarChangeListener {
ImageView playpause;
SeekBar seekBar;
MediaPlayer mp = null;
int len = 0;
boolean isPlaying = false;
public MusicPlayerActivity() throws IOException {
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music_player);
String url = getIntent().getExtras().getString("musicurl");
playpause = (ImageView)findViewById(R.id.imageView);
seekBar = (SeekBar)findViewById(R.id.seekBar);
playpause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(!isPlaying){
playpause.setImageResource(R.drawable.pause);
mp.pause();
len = mp.getCurrentPosition();
seekBar.setEnabled(false);
}else{
playpause.setImageResource(R.drawable.play);
mp.seekTo(len);
mp.start();
seekBar.setEnabled(true);
}
isPlaying = !isPlaying;
}
});
mp = new MediaPlayer();
try {
mp.setDataSource(url);
} catch (IOException e) {
e.printStackTrace();
}
try {
mp.prepare();
} catch (IOException e) {
e.printStackTrace();
}
//if(mp.isPlaying()) mp.stop(); mp.release();
mp.start();
seekBar.setMax(mp.getDuration());
new Thread(this).start();
// Toast.makeText(this, mp.getDuration(), Toast.LENGTH_SHORT).show();
}
//if(mp.isPlaying()){}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
try {
if (mp.isPlaying() || mp != null) {
if (fromUser)
mp.seekTo(progress);
} else if (mp == null) {
Toast.makeText(getApplicationContext(), "Media is not running",
Toast.LENGTH_SHORT).show();
seekBar.setProgress(0);
}
} catch (Exception e) {
Log.e("seek bar", "" + e);
seekBar.setEnabled(false);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void run() {
int currentPosition = mp.getCurrentPosition();
int total = mp.getDuration();
while (mp != null && currentPosition < total) {
try {
Thread.sleep(1000);
currentPosition = mp.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
seekBar.setProgress(currentPosition);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
mp.stop();
startActivity(new Intent(this,MainActivity.class));
break;
}
return true;
}
#Override
public void onBackPressed() {
Intent mainActivity = new Intent(Intent.ACTION_MAIN);
mainActivity.addCategory(Intent.CATEGORY_HOME);
mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mainActivity);
}
}
You are not setting the listener : seekbar.setOnSeekBarChangeListener(this)
Add seekbar.setOnSeekBarChangeListener(this); in your onCreate otherwise the onProgressChanged() does not get called.
To reset progress bar look into the following approach:
Set OnCompletionListener on your media player instance. When the media file completes playing, your can carry out the required actions in OnCompletion(MediaPlayer mp) callback function.
Adding following code snippet before mp.start() should work for you.
mp.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
seekBar.setProgress(0); // sets seekbar to initial position.
toggleViews();//implement this function to toggle your play/pause button
}
});

Media Player Shoutcast error

I am in the process of building an android app for a local community radio station and I am getting this error in the LogCat:
2862-2862/pmelia.bcrfm V/MediaPlayer﹕ callback application
2862-2862/pmelia.bcrfm V/MediaPlayer﹕ back from callback
2862-2862/pmelia.bcrfm V/MediaPlayer﹕ isPlaying: 0
2862-2862/pmelia.bcrfm E/MediaPlayer﹕ Error (-38,0)
Here is my activity code
public class MainActivity extends ActionBarActivity implements View.OnClickListener, View.OnTouchListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnBufferingUpdateListener {
private Toolbar toolbar;
private Button btnPlay;
private Button btnPause;
private Button btnStop;
private SeekBar seekBar;
private MediaPlayer mediaPlayer;
private int lengthOfAudio;
//official broadcasting URL
private final String URL = "http://37.187.193.36:8002/listen.pls";
private final Handler handler = new Handler();
private final Runnable r = new Runnable() {
#Override
public void run() {
updateSeekProgress();
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_appbar);
init();
}
private void init() {
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer,(DrawerLayout)findViewById(R.id.drawer_layout), toolbar);
btnPlay = (Button) findViewById(R.id.btnPlay);
btnPlay.setOnClickListener(this);
btnPause = (Button) findViewById(R.id.btnPause);
btnPause.setOnClickListener(this);
btnPause.setEnabled(false);
btnStop = (Button) findViewById(R.id.btnStop);
btnStop.setOnClickListener(this);
btnStop.setEnabled(false);
seekBar = (SeekBar)findViewById(R.id.seekBar);
seekBar.setOnTouchListener(this);
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Toast.makeText(this, "Hey you just hit " + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onBufferingUpdate(MediaPlayer mediaPlayer, int percent) {
seekBar.setSecondaryProgress(percent);
}
#Override
public void onCompletion(MediaPlayer mp) {
btnPlay.setEnabled(true);
btnPause.setEnabled(false);
btnStop.setEnabled(false);
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (mediaPlayer.isPlaying()) {
SeekBar tmpSeekBar = (SeekBar)v;
mediaPlayer.seekTo((lengthOfAudio / 100) * tmpSeekBar.getProgress() );
}
return false;
}
#Override
public void onClick(View view) {
try {
mediaPlayer.setDataSource(URL);
mediaPlayer.prepare();
lengthOfAudio = mediaPlayer.getDuration();
}
catch (Exception e) {
Log.e("Error", e.getMessage());
}
switch (view.getId()) {
case R.id.btnPlay:
playAudio();
break;
case R.id.btnPause:
pauseAudio();
break;
case R.id.btnStop:
stopAudio();
break;
default:
break;
}
updateSeekProgress();
}
private void updateSeekProgress() {
if (mediaPlayer.isPlaying()) {
seekBar.setProgress((int)(((float)mediaPlayer.getCurrentPosition() / lengthOfAudio) * 100));
handler.postDelayed(r, 1000);
}
}
private void stopAudio() {
mediaPlayer.stop();
btnPlay.setEnabled(true);
btnPause.setEnabled(false);
btnStop.setEnabled(false);
seekBar.setProgress(0);
}
private void pauseAudio() {
mediaPlayer.pause();
btnPlay.setEnabled(true);
btnPause.setEnabled(false);
}
private void playAudio() {
mediaPlayer.start();
btnPlay.setEnabled(false);
btnPause.setEnabled(true);
btnStop.setEnabled(true);
}
}
Any help would be appreciated, this is my first time doing this type of development.
I had the same problem... It has to be just the IP address with port number.
For this:
private final String URL = "http://37.187.193.36:8002/listen.pls";
Replace with:
private final String URL = "http://37.187.193.36:8002/";
So I got it to work finally in the end....First of all, thanks to #TennyTech.com for the little hint.
So to help ye people out, I will have an ans up on my github repo by tonight hopefully :) But do keep an eye out.
Hope this helps,
PatrickMelia

Unable to play next song in Music Player Application

I have seen a few tutorials that indicate that in order to play the next song from a raw folder all I need to do is write some code like:
case R.id.next : mp.next();break;"
However it is not working. What is the right way to implement the "play previous and play next song"?
Here is my code for reference:
public class MainActivity extends Activity implements OnClickListener, OnPreparedListener{
private static final String SAVE_POSITION = "MainActivity.SAVE_POSITION";
public static final int STANDARD_NOTIFICATION = 0x01001;
public static final int EXPANDED_NOTIFICATION = 0x01002;
private static final int REQUEST_NOTIFY_LAUNCH = 0;
//Audio Control buttons
Button media;
Button pause;
Button stop;
Button prev;
Button next;
//Media Player
MediaPlayer mp;
boolean mActivityResumed;
boolean mPrepared;
int mAudioPosition;
//array of songs
private int[] rawFiles = {R.raw.black_banquet,R.raw.door_of_holy_spirits,R.raw.castlevania_prologue};
//random playback
private Random random = new Random();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPrepared = mActivityResumed = false;
mAudioPosition = 0;
if(savedInstanceState != null && savedInstanceState.containsKey(SAVE_POSITION)) {
mAudioPosition = savedInstanceState.getInt(SAVE_POSITION, 0);
}
//button audio playback control
media = (Button) findViewById(R.id.btMedia);
media.setOnClickListener(this);
pause = (Button) findViewById(R.id.pause);
pause.setOnClickListener(this);
stop = (Button) findViewById(R.id.stop);
stop.setOnClickListener(this);
media = (Button) findViewById(R.id.prev);
media.setOnClickListener(this);
media = (Button) findViewById(R.id.next);
media.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#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);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.btMedia: if (mp == null){
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(this);
//random song
mp = MediaPlayer.create(this, rawFiles[random.nextInt(rawFiles.length)]);
}
//looping one song
mp.setLooping(true);
mp.start();
break;
case R.id.pause : mp.pause();break;
case R.id.next : mp.next();break;
case R.id.stop : mp.stop();mp = null;break;
}
// Notification Manager
NotificationManager mgr =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
// Setting the default action.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent =
PendingIntent.getActivity(this, REQUEST_NOTIFY_LAUNCH, intent, 0);
// Setting the default action.
builder.setContentIntent(pIntent);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setLargeIcon(BitmapFactory.decodeResource(
getResources(), R.drawable.ic_launcher));
builder.setContentTitle("Standard Title");
builder.setContentText("songTitle");
mgr.notify(STANDARD_NOTIFICATION, builder.build());
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if(mp != null) {
outState.putInt(SAVE_POSITION, mp.getCurrentPosition());
}
}
#Override
protected void onResume() {
super.onResume();
mActivityResumed = true;
if(mp != null && !mPrepared) {
mp.prepareAsync();
} else if(mp != null && mPrepared) {
mp.seekTo(mAudioPosition);
mp.start();
}
}
#Override
protected void onPause() {
super.onPause();
mActivityResumed = false;
if(mp != null && mp.isPlaying()) {
mp.pause();
}
}
#Override
protected void onStop() {
super.onStop();
if(mp != null && mp.isPlaying()) {
mp.stop();
mPrepared = false;
}
}
#Override
protected void onDestroy() {
super.onDestroy();
if(mp != null) {
mp.release();
}
}
#Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mPrepared = true;
if(mp != null && mActivityResumed) {
mp.seekTo(mAudioPosition);
mp.start();
}
}
For the Android MediaPlayer class there is no next method. What you need to do in order to implement the next functionality is to call mp.reset(), mp.setDataSource() with the next audio file, and mp.prepare().
E.x.
case R.id.next : {
mp.reset();
mp.setDataSource(**LOCATION OF YOUR AUDIO FILE**)
//See http://developer.android.com/reference/android/media/MediaPlayer.html#setDataSource(java.lang.String)
mp.prepare();
break;
}

android MediaPlayer setDataSource not grabbing a playable file

Hey I'm having trouble getting a stream to play from my localhost server (and also other websites with raw mp3 files). My code work for the site that is commented out so i assume it has something to
do with the server and not the java code.
public class MainActivity extends ActionBarActivity{
//static final String ANCHOR = "http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3";
static final String ANCHOR = "http://spintron.ddns.net/Random%20Access%20Memories/07%20-%20Touch.mp3";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MediaPlayer mp = new MediaPlayer();
mp.setVolume(1, 1);
try{
mp.setDataSource(ANCHOR);
mp.prepareAsync();
}catch(Exception e){
e.printStackTrace();
}
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
Toast.makeText(MainActivity.this,"Prepared",Toast.LENGTH_LONG).show();
mp.start();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#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);
}
}
To play music file refer below code.
my res/raw folder contains options_music.wav music file.
// Play Music
MediaPlayer mp = new MediaPlayer();
AssetFileDescriptor descriptor;
try {
descriptor = getAssets().openFd("options_music.wav");
mp.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
descriptor.close();
mp.prepare();
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
//Log.e("Music", "Music Completed........");
mp.start();
}
});
} catch (Exception e) {
Log.e("ErrorMusic", "Cant Play Music File"+e);
}
For your url , make sure your it is properly url encoded and accessible from your mobile.

Streaming MediaPlayer will not work with Samsung Galaxy S3

Streaming MediaPlayer not working on Samsung galaxy s3. Don't have device myself but getting reports of it not working. Also tried Remote Test Lab and does not work. I have tested on many other devices and all work excepted for s3. Any help would be awesome!
Code:
public class Radio extends Activity {
private MediaPlayer mp;
private ImageButton pauseicon;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_1);
Toast.makeText(this, "Just one moment please", Toast.LENGTH_LONG).show();
pauseicon = (ImageButton) findViewById(R.id.pauseicon);
getActionBar().setDisplayHomeAsUpEnabled(true);
/**
* Play button click event plays a song and changes button to pause
* image pauses a song and changes button to play image
* */
String res = "http://************";
mp = new MediaPlayer();
try {
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(res);
mp.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer player) {
mp.start();
}
});
mp.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
}
pauseicon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
// No need to check if it is pauseicon
if (mp.isPlaying()) {
mp.pause();
((ImageButton) v).setImageResource(R.drawable.playicon);
} else {
mp.start();
((ImageButton) v).setImageResource(R.drawable.pauseicon);
}
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
if (mp != null)
if (mp.isPlaying())
mp.stop();
mp.release();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onBackPressed() {
if (mp != null) {
if (mp.isPlaying())
mp.stop();
mp.release();
}
// there is no reason to call super.finish(); here
// call super.onBackPressed(); and it will finish that activity for you
super.onBackPressed();
}
}
This is what I do to get a streaming music to play, just tested this on a Samsung Galaxy SIII and it is working fine. The audio stream in this is a public university radio stream. But this should work with other online streams. Just make sure you enable the internet permissions in your manifest.
public class MainActivity extends Activity {
MediaPlayer mpMediaPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
mpMediaPlayer = new MediaPlayer();
mpMediaPlayer.setDataSource("http://streams.tsc.usu.edu:8888");
mpMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mpMediaPlayer.prepare();
mpMediaPlayer.start();
}catch(Exception e){
e.printStackTrace();
}
}
This might be a little late, but for those who are coming to this looking for this answer, one solution might be to implement the MediaPlayer.OnPreparedListener.
public class MyActivity extends Activity implements MediaPlayer.OnPreparedListener
MediaPlayer mpMediaPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
try{
mpMediaPlayer = new MediaPlayer();
mpMediaPlayer.setDataSource("audio url");
mpMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mpMediaPlayer.prepare();
mpMediaPlayer.setOnPreparedListener(this);
}catch(Exception e){
e.printStackTrace();
Log.e(TAG, "Error loading media");
}
}
#Override
public void onPrepared(MediaPlayer mp) {
mpMediaPlayer.start();
}

Categories

Resources