如何从VideoView类扩展我自己的类?请举个例子

时间:2011-08-08 15:49:24

标签: android

我正在创建自己的类并扩展活动以使用VideoView类。

如何从VideoView类扩展自己的类。这是我的代码。

public class VideoPlayer extends Activity {
    private ProgressDialog mProgressdialog = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videoview);
        StartVideoPlayer();
    }
    private void StartVideoPlayer(){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
        showProgressDialog();
        VideoView videoView = (VideoView) findViewById(R.id.surface_view);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri video=Uri.parse("rtsp://192.168.1.80/movie4.mp4"); 
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();
        videoView.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                mProgressdialog.dismiss();
            }
        });

        videoView.setOnErrorListener(new OnErrorListener() {
            public boolean onError(MediaPlayer mp, int what, int extra) {
                mProgressdialog.dismiss();
                return false;
            }
        });
    }
    private void showProgressDialog()
    {
        /** Progress dialog displayed while loading video*/
        mProgressdialog = ProgressDialog.show(VideoPlayer.this, 
                "", "Streaming...", true);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

现在我想从VideoView扩展VideoPlayer类,我该如何使用它。请帮忙。

谢谢,
斯利拉姆

1 个答案:

答案 0 :(得分:0)

您只需创建一个班级public class extends VideoView即可。但根据我的经验,VideoView并不是要扩展,它有自己的逻辑和状态,而且它的大多数字段都是私有的,并且扩展它并不是一个好的尝试。

(见a related question of mine regarding the same VideoView