Android media controller shows display for a short time

Android picture Android · Jun 30, 2011 · Viewed 9k times · Source

This below activity works fine but the mediaController display only if I click on the screen. And the second problem is the media controller display only for 3 sec. what should I do to remove this problem?

public class PlayingActivity extends Activity
{

    private VideoView mVideoView;
    private EditText mPath;
    MediaController mediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.playingactivity);
        mPath = (EditText) findViewById(R.id.path);
        mPath.setText(GlobalVariable.getstrEmail());
        mVideoView = (VideoView) findViewById(R.id.surface_view);
        Uri uri = Uri.parse("/sdcard/download/test.mp3");
        mediaController = new MediaController(this);
        mediaController.findFocus();
        mediaController.setEnabled(true);
        mediaController.show(0);
        mediaController.setAnchorView(mVideoView);
        mVideoView.setMediaController(mediaController);
        mVideoView.setVideoURI(uri);
        mVideoView.start();
    }
}

Answer

Neo picture Neo · Aug 1, 2012
mediaController.requestFocus();

will make it display as soon as the video starts ( without requiring the click)

and

mVideoView.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                mediaController.show(0);
            }
        });

Will keep it on the screen. Hope it helps