开发者

MediaController appears only after tapping in Android

I am writing an Android App where I am playing video using VideoView,but the me开发者_开发技巧diaController appears only after tapping the screen.Is this correct procedure ? If not how can we make it to appear without tapping on the screen.

Thanks in Advance,


You can display it with the show() method but not from the OnCreate method of your activity containing your VideoView because the VideoView is not yet attached to a SurfaceHolder (or something like that). You will have use a similar procedure:

public class ActivityPreHomeVideo extends Activity implements SurfaceHolder.Callback{

    private VideoView mVideoView;
    private MediaController mMediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.videolayout);
        mVideoView = (VideoView) findViewById(R.id.videolayout_video);

        mMediaController = new MediaController(this);
        mMediaController.setMediaPlayer(mVideoView);
        mMediaController.setAnchorView(mVideoView);
        mVideoView.setMediaController(mMediaController);

        //Set a callback when the VideoView is displayed
        mVideoView.getHolder().addCallback(this);

        mVideoView.setVideoPath("http://.../your_video.mp4");
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // Display the mediaController for 3 seconds
        mMediaController.show();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
    }
}

Hope it will help.


try this http://developer.android.com/reference/android/widget/MediaController.html#show()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜