我正在尝试为 Android 创建一个 RTSP 播放器,但我收到错误视频无法播放。我不知道我犯了什么错误,这根本行不通,我尝试了所有方法,我给出了下面的代码
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView myVideoView;
ProgressDialog progDailog;
AudioManager audio;
MediaController mediaController;
String unStringUrl="rtsp://his.dvrdns.org:8554/channel/2";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myVideoView = (VideoView)findViewById(R.id.videoplayer);
progDailog = ProgressDialog.show(MainActivity.this, null, "Video loading...", true);
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mediaController = new MediaController(this);
myVideoView.setMediaController(mediaController);
myVideoView.setVideoURI(Uri.parse(unStringUrl));
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
// called too soon with rtsp in 4.1
if(progDailog != null) {
progDailog.dismiss();
}
myVideoView.start();
}
});
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
/*Intent intent = new Intent(MyVideoView.this, lastActivity);
intent.putExtra("cleTitre", activityTitle);
intent.putExtra("cleSegment", activityCat);
startActivity(intent);*/
}
});
myVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
if(progDailog != null) {
progDailog.dismiss();
}
return false;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}