I have a simple android app, thar stream online radio, everything is OK, but the client want the app has 2 options, 128 kbp/s and 38 kbp/s. how I can set bitrate to the MediaPlayer Class in asdroid?
this is my pla action:
public void actionPlay(View view) {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
If you refer to the documentation using prepareAsync() is better from streams. If you use prepare(), you will block it until enough data is buffered.
mediaPlayer.prepareAsync();
Refer here.
As for setting the bit rate there is no mention of it in the official documentation.
Perhaps you need to go NDK to realize it and that will require lots of work..
Related
I'm developing a SIP client app using Android 2.3+ API, I can make a outgoing call and receive a incoming call successfully by using SipDemo sample codes. but I can't hear any thing before peer answers the call.
What steps will reproduce the problem?
register to sip provider (mSipManager.open())
place a call (mSipManager.makeAudioCall)
silence (onRingBack method trigger in SipAudioCallListener)
other side answer (onCallEstablished method trigger in SipAudioCallListener)
both sides hear each other with good quality
I expect for ring-back tone, in step: 3 instead silence.
Can i do something in onRingBack for hear sip ring-back tone instead of silence.
Try this in your onReceive()
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IllegalStateException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
Thats supposed to start the ringtone. Don't for get to put mediaPlayer.stop(); somewhere in your code. onCallEstablished is where i put mine
I'm trying to play an rtsp stream using MediaPlayer in android and the application seems to always become stuck on MediaPlayer.prepare();
The url is valid as I tested it using VLC on my desktop.
Any ideas why the application is not preparing the stream.
class InitializeService extends Thread {
#Override
public void run() {
try {
player.prepare();
Log.d("Play", "Player prepared");
} catch (IOException e) {
e.printStackTrace();
fallback();
} catch (IllegalStateException e) {
e.printStackTrace();
fallback();
}
}
}
The log statement is never reached.
Update 1:
Sorry I forgot to mention that the stream will always be in 3gp format. Here is a url rtsp://r2---sn-p5qlsu76.c.youtube.com/CiILENy73wIaGQnTXOVs7Kwo8xMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
Your stream might not be of a format supported by Android.
Check http://developer.android.com/guide/appendix/media-formats.html to see if Android supports it.
Turns out it was android l that wasn't able to play the streams.
I had anapplication to stream video(without audio) from android device(Blaze board) to PC. For that, I'm using vlc player to view streamed video by using the following command in command line
vlc stream.sdp
This .sdp file would be generated from my application. By using the above command, I can stream from blaze board to PC with the delay of 1 sec.
Now, My problem is that, I have to stream from one blaze board to another blaze board. I have searched a lot. But, Nothing is worked.
I have an idea to write viewer application ( For client ). This application will use sdp file path as url. I refer this page. Here, he had used "setDataSource(http://localhost/file.sdp)" . I used like this in my application. But, it also, didn't work.
String videoSrc = "rtsp://192.168.13.77:8086/stream.sdp";
Here is my code
public void surfaceCreated(SurfaceHolder arg0) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setDataSource(videoSrc);
mediaPlayer.prepare();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} 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();
}
}
How to use .sdp file to play streamed video lively?
Whether I am going is correct path or not? If you are having any other way, please suggest me.
Any help will be appreciated.
I have a strange problem when playing music files with the mediaplayer.
The playback starts without any problems and everything works fine. The app doesn't crash. But everytime I select a song I get the following LogCatError:
11-18 16:26:19.800: E/MediaPlayer(11367): setDataSource JAVA path
11-18 16:26:19.800: E/MediaPlayer-JNI(11367): setDataSource: outside
path in JNI is ?x#
11-18 16:26:19.855: E/MediaPlayer(11367): In prepareAsync
11-18 16:26:20.005: W/MediaPlayer(11367): info/warning (1, 44)
I don't download the files from the internet, I just play the songs stored on the device.
If nobody could give me a solution, it would be nice if anybody could explain the error to me.
Use try catch around you mediaplayer datasource, like this:
try {
mp.setDataSource(getApplicationContext(), ringtoneUri);
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
You have to catch all Exceptions.
This worked for me.
try using ES File Explorer or something similar to check the properties/permissions of the file you want to play and try making it world readable
I had same problem, the file was in "*.wmv" format, then i converted file to mp3 and tried same code and it worked, please find code below
try {
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://Server.com/XXXX.mp3");
player.prepare();
player.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
I have online radio (shout cast ) in web. I want to develop android app for listen this stream. so I want to know how to play online stream in android. using URL. In Android Im not going to Stream the audio. I want listen the web stream from android app.
How to do that..?
thanks
Something like
private void init() throws IOException {
try {
mediaPlayer = new MediaPlayer();
String streamPath = "";//enter path
mediaPlayer.setDataSource(streamPath);
mediaPlayer.prepare();
} catch (MalformedURLException ex) {
throw new RuntimeException("Wrong url for mediaplayer! " + ex);
} catch (IllegalStateException ex) {
} catch (IllegalArgumentException ex) {
throw new RuntimeException("Wrong url for mediaplayer! " + ex);
}
}
private void play() {
mediaPlayer.start();
}
Please refer the link it may help you a while, http://developer.android.com/guide/topics/media/index.html