我需要在具有2.x及更高版本的设备上播放实时流.
This声明在Android 2.x设备上播放实时流是不可能的.
我在这里有什么选择?特别是我对流式音频感兴趣 – 我应该选择哪种格式以及哪种协议?
附:我尝试过Vitamio – 不想让客户下载第三方库.
UPD
>为什么我可以播放这个流“http://188.138.112.71:9018/”?
解决方法
尝试此示例用于RTSP流(网址应支持RTSP),用于视频更改代码以支持音频
public class MultimediaActivity extends Activity { private static final String RTSP = "rtsp://url here"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.multimedia); //***VideoView to video element inside Multimedia.xml file VideoView videoView = (VideoView) findViewById(R.id.video); Log.v("Video","***Video to Play:: " + RTSP); MediaController mc = new MediaController(this); mc.setAnchorView(videoView); Uri video = Uri.parse(RTSP); videoView.setMediaController(mc); videoView.setVideoURI(video); videoView.start(); } }
编辑:
使用Android中的MediaPlayer实时音频流媒体
Android中的实时音频流,从1.6 sdk开始变得如此简单.在setDataSource()API中直接传递url,音频将播放没有任何问题.
完整的代码段是,
public class AudioStream extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String url = "http://www.songblasts.com/songs/hindi/t/three-idiots/01-Aal_Izz_Well-(SongsBlasts.Com).mp3"; MediaPlayer mp = new MediaPlayer(); try { mp.setDataSource(url); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.prepare(); mp.start(); } catch (Exception e) { Log.i("Exception","Exception in streaming mediaplayer e = " + e); } } }