-1

在我的活动中,我想播放在线视频,但此功能在我的代码中不起作用。视频流未启动?

这是代码:

     private String getDataSource(String path) throws IOException {
        if (!URLUtil.isNetworkUrl(path)) {
            return path;
        } else {
            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");
            temp.deleteOnExit();
            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);
            try {
                stream.close();
            } catch (IOException ex) {
                Log.e(TAG, "error: " + ex.getMessage(), ex);
            }
            return tempPath;
        }
    }
4

2 回答 2

3

试试这个http://www.pocketjourney.com/downloads/pj/video/着名.3gp

于 2012-05-15T06:51:55.043 回答
1
VideoView mVideoView = (VideoView) findViewById(R.id.vdoTest);
mVideoView.setMediaController(new MediaController(this));
String viewSource ="http://view.vzaar.com/923037/video";
mVideoView.setVideoURI(Uri.parse(viewSource));

如果视频编码正确,这应该可以工作:(AAC+H.264,基线)

于 2012-05-15T06:47:42.177 回答