我试图在Android手机上显示来自ACTI IP摄像头的直播。 ACTI摄像机设置为以32x240分辨率传输H.264 Baseline。调用prepareAsync()后,错误会不断弹出。
W/IMediaDeathNotifier: media server died
W/AudioSystem: AudioFlinger server died!
E/MediaPlayer: Error (100,0)
E/MediaPlayer: error (100, 0)
我检查了网址格式,尝试删除“?”。我也在VLC中尝试了流URL,但它确实有效。我在Android Jelly Bean上运行它。代码如下
final static String RTSP_URL = "rtsp://192.168.34.52:7070?/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vo_ipphone);
mySurfaceView = findViewById(R.id.surface);
Log.i(TAG, "prepare surface holder");
_surfaceHolder = mySurfaceView.getHolder();
_surfaceHolder.addCallback(this);
_surfaceHolder.setFixedSize(320, 240);
}
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
Log.i(TAG, "Prepared!");
_mediaPlayer.start();
}
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
Log.i(TAG, "Surface created");
_mediaPlayer = new MediaPlayer();
_mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
_mediaPlayer.release();
//create another mediaplayer preferrably in another thread
return false;
}
});
_mediaPlayer.setDisplay(_surfaceHolder);
Context context = getApplicationContext();
Map<String, String> headers = getRtspHeaders();
Uri source = Uri.parse(RTSP_URL);
try {
// Specify the IP camera's URL and auth headers.
Log.i(TAG, "Set data source");
_mediaPlayer.setDataSource(context, source, headers);
//_mediaPlayer.setDataSource(this, source);
// Begin the process of setting up a video stream.
Log.i(TAG, "set on prepared listener");
_mediaPlayer.setOnPreparedListener(this);
Log.i(TAG, "prepare async");
_mediaPlayer.prepareAsync();
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
_mediaPlayer.release();
}
答案 0 :(得分:0)
看起来所有行都是真的但是错误来自错误的网址,网址应该如下所示
try {
server.start();
} catch (IOException e) {
throw new RuntimeException(e);
}
// wait for a SIGINT (Ctrl+c) signal to shut down
try {
LOG.info("Press CTRL^C to exit..");
Thread.currentThread().join();
} catch(InterruptedException e) {
throw new RuntimeException(e);
}
在没有&#39;?&#39;
的情况下尝试此网址并检查您的设备互联网和权限
如果不存在则添加到AndroidManifest.xml中的权限
final static String RTSP_URL = "rtsp://192.168.34.52:7070/";
我希望它有用