Android 中的流媒体音频
我使用此代码来传输音频。但它没有奏效。
public class MediaPlayerAudio extends Activity implements OnClickListener,
OnPreparedListener, OnErrorListener {
MediaPlayer mp;
public v
oid 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("radio", "prepare finished");
mp.start();
}
@Override
public void onClick(View v) {
try
{
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(this);
mp.setOnErrorListener(this);
mp.setDataSource("http://stream1.tanitweb.com/rtci");
mp.prepareAsync();
}
catch(Exception e)
{
Log.e("radio", e.getMessage());
}
}
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
return false;
}
}}
单击按钮时出现此错误
05-15 09:31:14.360: ERROR/PlayerDriver(30): Command PLAYER_INIT completed with an error or info PVMFErrCorrupt
05-15 09:31:14.371: ERROR/MediaPlayer(330): error (1, -10)
05-15 09:31:14.371: ERROR/MediaPlayer(330): Error (1,-10)
I use this code to stream an audio. But it didn't worked.
public class MediaPlayerAudio extends Activity implements OnClickListener,
OnPreparedListener, OnErrorListener {
MediaPlayer mp;
public v
oid 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("radio", "prepare finished");
mp.start();
}
@Override
public void onClick(View v) {
try
{
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(this);
mp.setOnErrorListener(this);
mp.setDataSource("http://stream1.tanitweb.com/rtci");
mp.prepareAsync();
}
catch(Exception e)
{
Log.e("radio", e.getMessage());
}
}
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
return false;
}
}}
On click in the button, I have this error
05-15 09:31:14.360: ERROR/PlayerDriver(30): Command PLAYER_INIT completed with an error or info PVMFErrCorrupt
05-15 09:31:14.371: ERROR/MediaPlayer(330): error (1, -10)
05-15 09:31:14.371: ERROR/MediaPlayer(330): Error (1,-10)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android 似乎不支持您尝试播放的媒体格式。 这里是包含所有支持格式的表格,看来 ASF 是不在其中。我已经尝试过你的网址,它指向 rtci.asf
It seems that media format you're trying to play is not supported from android. Here is table with all supported formats and it seems that ASF is not in it. I've tried your url and it's pointing to rtci.asf