Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android media controller shows display for a short time

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();
    }
}
like image 826
Android Avatar asked Jun 30 '11 05:06

Android


2 Answers

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

like image 136
Neo Avatar answered Oct 13 '22 00:10

Neo


Requesting focus or specifying 0 in show method never worked for me.

The problem is that MediaController class has default timeout of 3000ms or 3seconds. And its show() method replaces our given parameter to its default parameter. Its a stupid bug resulting from untested code at Google.

We need to implement a lousy workaround of replacing the default value by desired value.

Try the below code. It should work.

mediaControls = new MediaController(getActivity()){
        @Override
        public void show (int timeout){
            if(timeout == 3000) timeout = 20000; //Set to desired number
            super.show(timeout);
        }
    };
mVideoView.setMediaController(mediaControls);
like image 24
Harsh Patel Avatar answered Oct 13 '22 01:10

Harsh Patel