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