-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/famous.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 に答える