我想开发一款android应用程序,它将从本地服务器播放rtsp链接,但平板电脑屏幕变为空白。。。。什么也没显示我试过VideoView
和MediaPlayer
两个类。适用于扩展名为.3gp的youtube rtsp链接,但不适用于上述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();
}
}
有多种因素会影响流是否正确播放:
- 检查您的流是否有效和可播放(例如使用VLC的单独实例)
- 如果有效,请检查logcat是否存在与RTSP连接或视频流本身相关的任何错误/警告。查找标签,如:MediaPlayer、ARTSPConnection,MyHandler和ASessionDescription以及ACodec
这应该会让你开始。