how to stream audio files in android - android

I am trying to stream audio files in android but everytime I get this exception
java.io.IOException: Prepare failed.: status=0x1
for my songs url stored on the server. eg(http://Touchstoneesol.com/listen/ML1 (Section 2).mp3);
But same code stream this link properly (http://android.programmerguru.com/wp-content/uploads/2013/04/hosannatelugu.mp3);
Now I am stuck inbetween whether there is some problem in the code or my songs link is corrupt.
buttonPlay = (Button) findViewById(R.id.play);
buttonPlay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
});

public class StreamAudioDemo extends Activity implements OnClickListener,
OnPreparedListener, OnErrorListener, OnCompletionListener {
MediaPlayer mp;
ProgressDialog pd;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bt = (Button)findViewById(R.id.play);
bt.setOnClickListener(this);
}
#Override
public void onPrepared(MediaPlayer mp) {
Log.i("StreamAudioDemo", "prepare finished");
pd.setMessage("Playing.....");
mp.start();
}
#Override
public void onClick(View v) {
try
{
pd = new ProgressDialog(this);
pd.setMessage("Buffering.....");
pd.show();
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(this);
mp.setOnErrorListener(this);
mp.setDataSource("http://www.robtowns.com/music/blind_willie.mp3");
mp.prepareAsync();
mp.setOnCompletionListener(this);
}
catch(Exception e)
{
Log.e("StreamAudioDemo", e.getMessage());
}
}
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
pd.dismiss();
return false;
}
#Override
public void onCompletion(MediaPlayer mp) {
pd.dismiss();A
Toast.makeText(getApplicationContext(), "Completed", Toast.LENGTH_LONG).show();
}
}
This is the xml that contains the button.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Stream Audio and Play"
android:id="#+id/play"
/>
</LinearLayout

Related

How to play and pause audio in firebase recyclerview in android

I am developing an app in which I have to fetch audio from firebase. I am using firebase recycler view. I am getting a problem that when I click the first song it plays good, but when I click second item then the first song's play button does not change and seekbar of first and second song changes.
Here is the code.
holder.play_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String audioUrl3 = model.getMedia();
if (!isPlaying){
if (mPlayer!=null){
mPlayer.release();
}
Toast.makeText(mContext, "Loading....", Toast.LENGTH_SHORT).show();
isPlaying = true;
Uri uri = Uri.parse(audioUrl3);
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.reset();
try {
mPlayer.setDataSource(mContext,uri);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(mContext, "Error Occured", Toast.LENGTH_SHORT).show();
}
try{
mPlayer.prepareAsync();
}catch (Exception e){
Toast.makeText(mContext, "Error Occured", Toast.LENGTH_SHORT).show();
holder.play_btn.setImageDrawable(holder.play_btn.getContext().getResources().getDrawable(R.drawable.ic_play));
}
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
if(mPlayer.isPlaying()){
mPlayer.stop();
}
mPlayer.start();
holder.play_btn.setImageDrawable(holder.play_btn.getContext().getResources().getDrawable(R.drawable.ic_pause));
holder.seekBar.setMax(mPlayer.getDuration());
Toast.makeText(mContext, "Playing...", Toast.LENGTH_SHORT).show();
updateSeekBar(holder.seekBar);
}
});
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
holder.play_btn.setImageDrawable(holder.play_btn.getContext().getResources().getDrawable(R.drawable.ic_play));
isPlaying = false;
}
});
}
else {
isPlaying=false;
stopPlaying();
}
}
private void stopPlaying() {
mPlayer.release();
mPlayer=null;
holder.play_btn.setImageDrawable(holder.play_btn.getContext().getResources().getDrawable(R.drawable.ic_play));
}
});
}
private void updateSeekBar(final SeekBar seek) {
try{
int pos = mPlayer.getCurrentPosition();
seek.setProgress(pos);
}catch (Exception e){
}
runnable = new Runnable() {
#Override
public void run() {
updateSeekBar(seek);
}
};
handler.postDelayed(runnable, 1800);
}

Android Media Player does not stop. When I click on a play button, it plays multiple times

When I click on the play button again and again, it plays multiple times simultaneously. I want to stop multiple playing. Here's the code:
Objects for Media player and buttons
MediaPlayer mPlayer;
Button playbtn;
Button stopbtn;
Button click event listener to play audio
playbtn = (Button) findViewById(R.id.play);
playbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Uri myUri1 = Uri.parse("file:///sdcard/Birds/parrot.mp3");
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(getApplicationContext(), myUri1);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
Button click event listener to stop audio
stopbtn = (Button) findViewById(R.id.stop);
stopbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(mPlayer!=null && mPlayer.isPlaying()){
mPlayer.stop();
}
}
});
any help would be appreciated. Thanks!
It is creating a new player with every play click but only keeping the reference to the last player so the solution is to keep player in a list and stop all.
private List<MediaPlayer> players = new ArrayList<>()
stopbtn = (Button) findViewById(R.id.stop);
stopbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
for(player in players){
if(player!=null && player.isPlaying()){
mPlayer.stop();
}
}
players.clear();
}
});
Another solution is, only use one instance of player. move the player initialization outside click as:
playbtn = (Button) findViewById(R.id.play);
Uri myUri1 = Uri.parse("file:///sdcard/Birds/parrot.mp3");
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(getApplicationContext(), myUri1);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
playbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!mPlayer.isPlaying())
mPlayer.start();

How to play Base 64 encoded audio in Android

I'm trying to play some base 64 encoded audio in Android, and I've followed various examples to come up with the following code:
MediaPlayer soundPlayer = new MediaPlayer();
try {
soundPlayer.setDataSource(audioData);
soundPlayer.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
}
});
soundPlayer.prepare();
soundPlayer.setVolume(100f, 100f);
soundPlayer.setLooping(false);
soundPlayer.start();
}
catch (Exception e) {
.
.
.
}
When this code executes, I just get silence - and the following error:
08-24 11:38:58.555: W/System.err(18862): java.io.IOException: Prepare
failed.: status=0x1 08-24 11:38:58.555: W/System.err(18862): at
android.media.MediaPlayer.prepare(Native Method) 08-24 11:38:58.555:
W/System.err(18862): at
application.main.Application$27.run(Application.java:233)
Would appreciate if anyone can point out where I'm going wrong. The 'audioData' variable in question (which, if you manage to decode and play it, describes my frustration) is as follows:
data:application/octet-stream;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQRChYECGFOAZwH/////////FUmpZpkq17GDD0JATYCGQ2hyb21lV0GGQ2hyb21lFlSua7+uvdeBAXPFh+lZ/IvV7yqDgQKGhkFfT1BVU2Oik09wdXNIZWFkAQEAAIC7AAAAAADhjbWERzuAAJ+BAWJkgSAfQ7Z1Af/////////ngQCjQZSBAACA+4O1bX7U7Fau4djaow6/qEcFOx2D6vgdTWqanSWTXXa4MzJRsP2c4GEeQwl5/cRiYFl3QmBVeh8n5mGhkgidhLFrDoCIMEJBptK5vggcJl5zwHJSDWDOFwrI/RRvrygpr+L+fHCQ8vnKQfn6W+U1MYhPc4u/xVkm4pp1qsZTyEXM3SQLnlOPNR5Lrp0q7lSyiezMrJ9JpcC3GBB4PrxIhyN09K7iyACAS3gPH1J3dmCt1JDNkJ/hpZRRU2mEPBC/ooXsqZ24Znqkr4XqmHfybYX0tEu5iTz7gngLbxiyPPEfcKYKpwAljaLLjOINVSna8jmkulRVNOIJ1edk2pGnwP5+FhU/5mia2w3sniEBjvBS5W2WiXOU40qYCG+0LY7+WmFFAovpUddWz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p9P8IEz6QoqPo6WELX76WPY9IXyJNgZ9kO7pFBncr7LBrQr4o1DnUVQlnFp/Flm0GWLH7GYCFw2Bbm6uiQsCp7sY7cVloFkmmgtN+4jtv75bdgDafsTZI90drCFYAVTHBKKfRjxi01E7EM15Hy/irSvXFxeV4gbMQ/2u9kA2GI/29WIzqQW+TOLgaA7lENLrVVQtUxf5Vlmv08oCL86A3u/9E59JYe5dZ7sthg=
Example Code of Playing Base64 encoded audio in Android :
public class MainActivity extends AppCompatActivity {
Button button;
String base64FormattedString="GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQRChYECGFOAZwH/////////FUmpZpkq17GDD0JATYCGQ2hyb21lV0GGQ2hyb21lFlSua7+uvdeBAXPFh+lZ/IvV7yqDgQKGhkFfT1BVU2Oik09wdXNIZWFkAQEAAIC7AAAAAADhjbWERzuAAJ+BAWJkgSAfQ7Z1Af/////////ngQCjQZSBAACA+4O1bX7U7Fau4djaow6/qEcFOx2D6vgdTWqanSWTXXa4MzJRsP2c4GEeQwl5/cRiYFl3QmBVeh8n5mGhkgidhLFrDoCIMEJBptK5vggcJl5zwHJSDWDOFwrI/RRvrygpr+L+fHCQ8vnKQfn6W+U1MYhPc4u/xVkm4pp1qsZTyEXM3SQLnlOPNR5Lrp0q7lSyiezMrJ9JpcC3GBB4PrxIhyN09K7iyACAS3gPH1J3dmCt1JDNkJ/hpZRRU2mEPBC/ooXsqZ24Znqkr4XqmHfybYX0tEu5iTz7gngLbxiyPPEfcKYKpwAljaLLjOINVSna8jmkulRVNOIJ1edk2pGnwP5+FhU/5mia2w3sniEBjvBS5W2WiXOU40qYCG+0LY7+WmFFAovpUddWzC1Jv5T6HpmLELnSYojoC6QKC8ECn8m7y0L9EIoMGkDH04Fk6l359StgSGpqqp1BVhCiMHzebvOM4pRXDzLJdCsYi3WFQfWf+ojKKZixVh3iuDDaKJqhxio5xBmXH/SDTlwQedAL06NBeIEAPID7g3J/UCJbxeOHYWvJS3wNcvuxbIec2Fa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zqQW+TOLgaA7lENLrVVQtUxf5Vlmv08oCL86A3u/9E59JYe5dZ7sthg=";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=findViewById(R.id.btnId);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
playMedia();
}
});
}
public void playMedia() {
try{
String url = "data:audio/mp3;base64,"+base64FormattedString;
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepareAsync();
mediaPlayer.setVolume(100f, 100f);
mediaPlayer.setLooping(false);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the DataSource correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the DataSource correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the DataSource correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer player) {
player.start();
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
}
});
}
catch(Exception e){
e.printStackTrace();
}
}
}
Also : AudioTrack is recommend to play a single audio resource for Java applications.
your error occurred because of the length of the base64 url limitation. media cannot prepare datasource for the long string. what I found base64 url for around 128 characters maybe work well. For long string you have to split string into pieces and fetch base64 url for small strings.

Streaming audio from website to app

I'm in the process of building a prototype for a project. I want to be able to stream music from my website to the app.
Here is what I have so far. Trying it with an m3u because I honestly have no idea what else to use for this.
Button buttonPlay;
Button buttonStop;
MediaPlayer mPlayer;
String url = "http://www.*******.com/*****/files.m3u";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonPlay = (Button) findViewById(R.id.play);
buttonPlay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Illegal Argument", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Security ", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Illegal Statement", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Prepare Illegal State", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Prepare IO", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
});
buttonStop = (Button) findViewById(R.id.stop);
buttonStop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(mPlayer!=null && mPlayer.isPlaying()){
mPlayer.stop();
}
}
});
Them problem is it throws IOexception after prepare. Now I read somewhere you have to download m3u files and then read them line by line. If that is the case, is there a better way? I'm attempting to make sort of a radio app for testing purposes that will play songs at random, not in order, so I don't want to hard code them MP3 files,
you cant just prepare a stream because it needs to download asynchronously. you will need to do this
Button buttonPlay;
Button buttonStop;
MediaPlayer mPlayer;
String url = "http://www.*******.com/*****/files.m3u";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonPlay = (Button) findViewById(R.id.play);
buttonPlay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Illegal Argument", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Security ", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Illegal Statement", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mPlayer.start();
}
};);
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Prepare Illegal State", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly! Prepare IO", Toast.LENGTH_LONG).show();
}
}
});
buttonStop = (Button) findViewById(R.id.stop);
buttonStop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(mPlayer!=null && mPlayer.isPlaying()){
mPlayer.stop();
}
}
});

Stream mp3 from link

i am trying to build a app that can stream mp3 content from the web. when i run this code i dont get any errors but there is no audio being played. Any help ? thanks
private MediaPlayer mediaPlayer;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
try {
mediaPlayer.setDataSource("my link.mp3"); //
mediaPlayer.prepareAsync();
//mediaPlayer.prepare(); //
if(! mediaPlayer.isPlaying())
{
mediaPlayer.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void initView() {
mediaPlayer = new MediaPlayer();
}
}
private MediaPlayer mediaPlayer;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
try {
mediaPlayer.setDataSource("my link.mp3"); //
// mediaPlayer.prepareAsync();
mediaPlayer.prepare();
// this mehthod block the UI if you want async operation then use mediaPlayer.prepareAsync();
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
Try this:
ProgressDialog progressDialog = ProgressDialog
.show(this, "Loading ", "Please Wait...");
progressDialog.setCancelable(false);
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
player.setDataSource("http://my link.mp3");
player.setOnErrorListener(this);
player.setOnPreparedListener(this);
player.prepareAsync();
} catch (IllegalArgumentException e) {
Toast.makeText(YourActivity.this,
"Internet Access is not Provided", 0).show();
e.printStackTrace();
} catch (IllegalStateException e) {
Toast.makeText(YourActivity.this,
"Internet Access is not Provided", 0).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(YourActivity.this,
"Internet Access is not Provided", 0).show();
e.printStackTrace();
}
#Override
public void onPrepared(MediaPlayer play) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
play.start();
}
#Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (player != null) {
player.release();
player = null;
}
return false;
}

Categories

Resources