thử ví dụ này cho RTSP (url nên hỗ trợ RTSP) cho video thay đổi mã để hỗ trợ chỉ âm thanh
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();
}
}
EDIT:
Sống Âm thanh trực tuyến sử dụng MediaPlayer trong Android Sống Audio streaming trong Android, từ 1,6 sdk trở đi trở nên dễ dàng như vậy. Trong setDataSource() API trực tiếp vượt qua url và âm thanh sẽ phát mà không có bất kỳ vấn đề nào.
Đoạn mã hoàn chỉnh là,
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);
}
}
}
Nguồn
2012-08-27 11:55:57
trạng thái kết nối https (an toàn) để phát trực tuyến không được hỗ trợ dưới 3.0, bạn có thể phát video trực tiếp trong kết nối http bằng rtp như giao thức –
bạn có thể cho tôi ví dụ về luồng đó không? P.S. "Giao thức dự thảo luồng trực tiếp HTTP/HTTPS: Không được hỗ trợ trước Android 3.0" – midnight
thử RTP (hoặc thậm chí bạn có thể triển khai một tập lệnh java đã bật chế độ xem web để hoàn thành phát trực tiếp .. SHORTCUT!) –