RTSP Android媒体播放器

时间:2013-02-18 19:12:50

标签: android android-layout android-intent android-emulator android-widget

我正在尝试为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;
}

}

1 个答案:

答案 0 :(得分:0)

你可以尝试在应用程序的清单文件中包含因特网-Permisison line(以下行)。在我的情况下它可以工作。

使用权限android:name =“android.permission.INTERNET”

希望这有帮助。