7
我正在開發應用程序,我必須實現直播電視流。我的谷歌搜索引導我相信直播2.1 android之前,直播是不可能的。安卓直播電視
是不是?
至於我,我可以使用它的類型設置以下方法來獲取媒體播放器的音樂straming代碼:
mp.setAudioStreamType(2)
;
,但我想知道的是它足以流就這樣代碼並保存文件,如下面的方法:
private void setDataSource(String path) throws IOException {
if (!URLUtil.isNetworkUrl(path)) {
mp.setDataSource(path);
} else {
Log.i("enter the setdata","enter the setdata");
URL url = new URL(path);
URLConnection cn = url.openConnection();
cn.connect();
InputStream stream = cn.getInputStream();
if (stream == null)
throw new RuntimeException("stream is null");
File temp = File.createTempFile("mediaplayertmp", "dat");
String tempPath = temp.getAbsolutePath();
FileOutputStream out = new FileOutputStream(temp);
byte buf[] = new byte[128];
do {
int numread = stream.read(buf);
if (numread <= 0)
break;
out.write(buf, 0, numread);
} while (true);
mp.setDataSource(tempPath);
try {
stream.close();
Log.i("exit the setdata","exit the setdata");
}
catch (IOException ex) {
Log.e(TAG, "error: " + ex.getMessage(), ex);
}
}
}
有需要的直播電視流的任何額外的東西?請給我指導。
流媒體電視是什麼意思?你使用什麼協議。 – dongshengcn 2011-02-17 02:21:31