[Android 2.1之前的Android的电视实时直播

问题描述 投票:7回答:1

我正在开发必须实现直播电视流的应用程序。我的Google搜索使我相信,直到2.1 Android才能进行实时流式传输。

是吗?

当我获得媒体播放器的流音乐的代码,并且可以通过设置以下方法来使用其类型时:

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);
            }
        }
    }

直播电视流媒体是否需要其他内容?

android streaming live
1个回答
5
投票

地址“是否足够”:绝对不行。

© www.soinside.com 2019 - 2024. All rights reserved.