我想开发一个 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。
这应该让你开始。
关于android - 使用 VideoView 和 MediaPlayer 进行 Rtsp 流式传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9696603/