使用VideoView和MediaPlayer进行Rtsp流式传输

时间:2012-03-14 05:49:20

标签: android video-streaming android-videoview rtsp

我想开发Android应用程序,它将从本地服务器播放rtsp链接,但平板电脑屏幕变为空白....     我曾尝试过两个VideoViewMediaPlayer类。 在youtube rtsp链接上运行良好,扩展名为.3gp,但不能处理上述URL     以下是我的代码

public class WifiManagerActivity extends Activity {

private WifiManager  customWifiManager;
private VideoView mu;
private String path;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        wifiSettings();
    }

    private void wifiSettings() {
        mu  = (VideoView) findViewById(R.id.ttl);
        TextView notify = (TextView) findViewById(R.id.wifi_state);
        customWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                if(customWifiManager.isWifiEnabled()){
            Toast.makeText(this, "Your wifi is On now enjoy " +
                    "live streaming", Toast.LENGTH_SHORT).show();
            notify.setTextColor(Color.GREEN);
            showVideo();
        }else{
        Toast.makeText(this, "Turn your Wifi On", Toast.LENGTH_SHORT).show();
        customWifiManager.setWifiEnabled(true);
        //two second wait here
        showVideo();
        }

    }

    private void showVideo() {


        Authenticator.setDefault(new MyAuthenticater());
        String path = "rtsp://192.168.1.155:554/3g";
        mu.setVideoURI(Uri.parse(path));
        mu.setMediaController(new MediaController(this));
        mu.requestFocus();
        mu.start();
    }
}

1 个答案:

答案 0 :(得分:0)

有多种因素会影响您的信息流是否正常播放:

  1. 检查您的信息流是否有效且可播放(例如使用单独的VLC实例)
  2. 如果可行则检查logcat是否存在与RTSP连接或视频流本身相关的任何错误/警告。查找以下标签: MediaPlayer ARTSPConnection MyHandler ASessionDescription ACodec
  3. 这应该让你开始。

相关问题