我想开发一个Android Java应用程序来播放Linux中vlc的rtp音频流。
我有MediaPlayer,但是即使没有异常或错误,我也听不到声音,我的代码如下:
public void initializeViews() throws IOException {
songName = (TextView) findViewById(R.id.songName);
try {
Uri myUri = Uri.parse("rtp://10.10.1.15:5000"); // initialize Uri here
i("TestAudio", "URI : " + myUri.getScheme());
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getApplicationContext(), myUri);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.prepareAsync();
} catch (Exception e) {
i("TestAudio", "Message: " + e.getMessage() + " Cause: " + e.getCause());
e.printStackTrace();
}
}
public void play(View view) {
mediaPlayer.start();
}