Now a days i m working on Audio Streaming through RTSP ...
First I have try through http url so i succeed. I can playing and streaming mp3 file though url but when i try to using RTSP its shows Errors::
My code is look like this:
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MusicPlayer extends Activity {
boolean musicFlag,m_bplayingsound;
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
tv = (TextView)this.findViewById(R.id.title1);
tv.setText("0%");
Button cmd_play = (Button)this.findViewById(R.id.cmd_play);
cmd_play.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("rtsp://localhost/sample.m3u");
System.out.println("1");
mp.prepareAsync();
System.out.println("2");
//mp.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//mp.start();
mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener(){
//@Override
public void onBufferingUpdate(MediaPlayer mp, int percent){
if(percent==50&&!musicFlag){
mp.start();
musicFlag=true;
}
tv.setText(percent+"%");
}
});
mp.setOnErrorListener(new
MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
return m_bplayingsound = false;
}
});
//mp.prepareAsync();
// i.e. react on the end of the music-file:
mp.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer arg0) {
// File has ended !!! Wink
//tv.setText(100+"%");
}
});
}
});
}
}
When i press the button it will shows error look like this:
12-08 17:33:08.847: ERROR/MediaPlayer(1462): Error (-1,0)
If u have any idea just help me..
Thanks in Advance.......
