Android:使用VideoView和RtpStream

Android:使用VideoView和RtpStream,android,streaming,android-videoview,rtp,Android,Streaming,Android Videoview,Rtp,我正在使用VideoView使用rtsp传输视频。我想获得关于它的详细信息,所以我想使用android.net.rtp。当我调用任何RtpStream类的方法(如getLocalPort)时,应用程序都无法工作。代码如下: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_m

我正在使用VideoView使用rtsp传输视频。我想获得关于它的详细信息,所以我想使用android.net.rtp。当我调用任何RtpStream类的方法(如getLocalPort)时,应用程序都无法工作。代码如下:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mVideoView = (VideoView) findViewById(R.id.surface_view);

    mPath = (EditText) findViewById(R.id.edit_message);
    text= "rtsp://192.168.1.37/sample_300kbit.mp4";
    mPath.setText(text);

    mPlay = (ImageButton) findViewById(R.id.play);
    mPause = (ImageButton) findViewById(R.id.pause);
    mReset = (ImageButton) findViewById(R.id.reset);
    mStop = (ImageButton) findViewById(R.id.stop);


    mPlay.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            reproducirVideo();
        }
    });
    mPause.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                mVideoView.pause();
            }
        }
    });
    mReset.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                mVideoView.seekTo(0);
            }
        }
    });
    mStop.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                current = null;
                mVideoView.stopPlayback();
            }
        }
    });

    runOnUiThread(new Runnable(){
        public void run() {
            reproducirVideo();

        }

    });

}

public void reproducirVideo() {
    try {
        final String path = mPath.getText().toString();
        Log.v(TAG, "path: " + path);
        if (path == null || path.length() == 0) {
            Toast.makeText(MainActivity.this, "Campo URL vacío",
                    Toast.LENGTH_LONG).show();

        } else {
            if (path.equals(current) && mVideoView != null) {
                mVideoView.start();
                mVideoView.requestFocus();
                return;
            }
            current = path;
            mVideoView.setVideoPath(getDataSource(path));
            mVideoView.start();
            mVideoView.requestFocus();      

            TextView texto= (TextView) findViewById(R.id.mensaje);
            InetAddress address = null;
            mRtpStream.associate(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, (byte)1, (byte)37 }), 1220);
            address=mRtpStream.getRemoteAddress();
            String address_string = address.getHostAddress();
            texto.setText(" La dirección local es "+(address_string)+"   ");

        }
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
        if (mVideoView != null) {
            mVideoView.stopPlayback();
        }
    }
}
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;
    }
}

}

如果您能解释一下这里什么不起作用,那会很有帮助。当我调用mRtpStream的方法时,应用程序不起作用。它不显示文本。如果我退出该方法,文本将显示。应用程序可以工作,但文本不会显示。如果我把方法放在VideoView之前,它就不会出现了。