Android Audio Streaming Very Slow - android

I am developing an android audio streaming application. I am using androids mediaplayer prepareAsync() in my service class.
However the streaming is very slow in Android 2.3 gingerbread. It works fine on Android 2.2 and 4.0 (around 5-6 seconds), but takes around 80 seconds on 2.3.
Is there any alternative radio streaming client that i can use.
I am referring Android Random Music Player Code for this application development.
http://developer.android.com/resources/samples/RandomMusicPlayer/index.html

public class ListenAudio extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//specify the url of audio file
String path = ?;
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(path);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // might take long! (for buffering, etc)
mediaPlayer.start();
}}

Related

Android: Redirecting pls file so that mediaplayer can read it

I want to play a radio shoutcast but its a pls file format by looking at the link:
http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361 It doesn't play at the moment,
I have got:
Initializing:
player = new MediaPlayer();
try {
player.setDataSource("http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361");
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
When play button is pressed:
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
player.start();
}
});
I have the code tested with another shoutcast link that ends with a port like www.example.com:8080 or something like that, it was working pretty fine, but when the link changed to a pls?id= it doesn't read the link and hence I can't hear the radio... Someone please help me with this :-/
A .pls file is just a playlist. There is no media there. You will have the parse the file yourself to get the actual stream URLs. Open it up in a text editor to see what I mean.

Code working on emulator but not working on real device

public class MySmthng extends Activity {
/** Called when the activity is first created. */
MediaPlayer mediaPlayer = new MediaPlayer();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url = "http://108.166.161.206:8826/;stream.mp3";
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // might take long! (for buffering, etc)
mediaPlayer.start();
}
}
Hello everyone,
This is a small code to stream audio. This code runs very fine on Emulator but when I install the apk on my device nothing happens except just launch of the application. Can anyone help me how to fix this kind of problem. Thank you all in advance.
Do you have all the permissions required set up in the manifest file? Most importantly would be :
uses-permission android:name="android.permission.INTERNET" />
Have a look at this site to see what other permissions you would need : HERE
I hope this helps. However since it worked on the emulator, permissions are probably not the issue, it's good to check anyway.

Audio-Streaming IOException: Prepare failed.: status=0xFFFFFFF6

Android 2.3 Mediaplayer can't play none of those audiostreams resulting in W/System.err(19610): java.io.IOException: Prepare failed.: status=0xFFFFFFF6. However, the same stream works fine on Android 4.0.
Is there anything I can provide the app with to make it work on Android 2.3 platform ?
Thanks.
Some code that I use:
mPlayer = new MediaPlayer();
mPlayer.setOnErrorListener(mOnErrorListener);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setOnPreparedListener(mOnPreparedListener);
mPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
try {
mPlayer.setDataSource(
this,
Uri.parse("http://radio02-cn03.akadostream.ru:8114/detifm192.mp3"));
mPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UPD
I'm able to play "http://radio02-cn03.akadostream.ru:8114/detifm192.mp3" with MoboPlayer - any suggestions how they do it ? It plays after message "trying soft decoding mode"
Check there encoding. It seems that hardware decoding is failing.

Media Player called in state 0, error (-38,0) error

i'm trying to use this code which i called from a button but it doesn't work and when i see the LogCat window i found Media Player called in state 0, error (-38,0)
public void audioPlayer(String path, String fileName){
//set up MediaPlayer
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(HeyActivity.this, Uri.parse(path+"/"+fileName));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
System.out.print("hey");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
Try setting OnPreparedListener and call the start method within it. Like this:
MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener( new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.start();
}
};
);
I finally solved the problem by running on an emulator that supported audio!!
Can't believe it was that simple!
Window > AVD Manager > Edit your AVD (I created a new one to be on the safe side cause I was running from snapshot) > Hardware > New > Audio Playback Support

Using eclipse streaming audio from web url

I have tried to find the answer online and none are clear to me. I am starting of programming and dont know much so any assistance that makes sense would help. My brother developed a website I'm trying to stream audio from and found on the developer web page a code to use. eclipse gives me no errors but when I run the app it forces close here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
String url = "http://beatswith.us/uploads/Mac%20Miller%20- %20Paper%20Route%20feat.%20Kev%20Da%20Hustla.mp3"; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // might take long! (for buffering, etc)
mediaPlayer.start();
}
};
Its probably throwing an exception at mediaPlayer.start()
The url must be bad. looks to me like theres an actual space in your String, which is invalid. You should put setDataSource, prepare, and start in the same try/catch block
Edit:nevermind the url seems fine. Can you post the stacktrace of the exception?
Edit2: did you add your activity to the AndroidManifest.xml? Are you navigating here from another activity?
Found the Answer I had my button set up with the wrong package name

Categories

Resources